Skip to content

Instantly share code, notes, and snippets.

@capsulecorplab
Created February 24, 2018 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save capsulecorplab/8696bc841bcf10056778c914e8da17d0 to your computer and use it in GitHub Desktop.
Save capsulecorplab/8696bc841bcf10056778c914e8da17d0 to your computer and use it in GitHub Desktop.
Smart contract for using struct and mapping
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