Created
February 24, 2018 06:20
-
-
Save capsulecorplab/8696bc841bcf10056778c914e8da17d0 to your computer and use it in GitHub Desktop.
Smart contract for using struct and mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.19; | |
contract Instructors { | |
struct Instructor { | |
uint age; | |
string fName; | |
string lName; | |
} | |
mapping(address => Instructor) instructors; | |
address[] public instructorAccts; | |
function setInstructor(address _address, uint _age, string _fName, string _lName) public { | |
var instructor = instructors[_address]; | |
instructor.age = _age; | |
instructor.fName = _fName; | |
instructor.lName = _lName; | |
instructorAccts.push(_address) -1; | |
} | |
function getInstructors() view public returns(address[]) { | |
return instructorAccts; | |
} | |
function getInstructor(address _address) view public returns(uint, string, string) { | |
return (instructors[_address].age, instructors[_address].fName, instructors[_address].lName); | |
} | |
function countInstructors() view public returns(uint) { | |
return instructorAccts.length; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment