2
pragma solidity ^0.4.23;

contract Owned {

    address owner;

    function owned() public {
        owner = msg.sender;
    }

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

}

contract Edureka is Owned {

    struct Instructor {

        uint age;
        bytes name;
        bytes subject;

    }

    mapping (address => Instructor) instructors;
    address[] public instructorAccts;

    event instructorInfo (

        bytes name,
        bytes subject,
        uint age

        );

    function setInstructor(address _address, uint _age, bytes _subject, bytes _name) {

        **var instructor =instructors[_address];**

        instructor.subject = _subject;
        instructor.name = _name;
        instructor.age = _age;
    }

    function getInstructor()view public returns(address[]){

        return instructorAccts;
    }

    function getInstructor(address _address)view public returns(uint, bytes, bytes) {

        **return(instructors[_address].subject, instructors[_address].name, instructors[_address].age)**

    ;
    }


    function countInstructurs() view public returns(uint){

        **return instructors.length;**
    }


}
Rob Hitchens
  • 55,151
  • 11
  • 89
  • 145

1 Answers1

0

This will get you part-way there.

pragma solidity ^0.4.23;

contract Owned {

    address owner;

    function owned() public {
        owner = msg.sender;
    }

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

}

contract Edureka is Owned {

    struct Instructor {

        uint age;
        bytes32 name;
        bytes32 subject;

    }

    mapping (address => Instructor) instructors;
    address[] public instructorAccts;

    event instructorInfo (

        bytes name,
        bytes subject,
        uint age

        );

    function setInstructor(address _address, uint _age, bytes32 _subject, bytes32 _name) public onlyOwner {

        instructors[_address].subject = _subject;
        instructors[_address].name = _name;
        instructors[_address].age = _age;
    }

    function getInstructor(address _address)view public returns(bytes32, bytes32, uint) {
        return(instructors[_address].subject, instructors[_address].name, instructors[_address].age);
    }
}

It's not possible to enumerate the instructors but you can set them an retrieve them. Only the owner (admin) is allowed to set.

For some ideas about extending the capabilities, have a look over here: Are there well-solved and simple storage patterns for Solidity?

Hope it helps.

Rob Hitchens
  • 55,151
  • 11
  • 89
  • 145
  • Great, it worked excellent, just when I put my vales in "Subject" Edureka contract, it appears : invalid bytes value, Im using words like read, blockchain but won't let me, I'll give it a try with other words, thanks a lot Rob – Pato Salinas Sep 10 '18 at 01:25
  • Simplify the interface with bytes32. bytes is an array of bytes of any length. bytes32 is exactly what it sounds like. Values go in and come out in hex. I left it the way it was to avoid straying too far from the question. I have updated the answer. – Rob Hitchens Sep 10 '18 at 01:48