Skip to content

Instantly share code, notes, and snippets.

@faytey
Last active February 3, 2023 17:35
Show Gist options
  • Select an option

  • Save faytey/cafcdb766dbc2f7167fe4b0064003fc0 to your computer and use it in GitHub Desktop.

Select an option

Save faytey/cafcdb766dbc2f7167fe4b0064003fc0 to your computer and use it in GitHub Desktop.
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
///@author Faith M. Roberts
///@title Student Records
contract Records{
address public admin_address;
struct StudentsInfo{
string name;
uint8 age;
string gender;
}
mapping(string => StudentsInfo) info;
uint public studentCount;
constructor(address admin){
admin_address = admin;
studentCount = 0;
}
function store_details (string memory name, uint8 age, string memory gender) external{
StudentsInfo memory _newStudent = StudentsInfo(name,age,gender);
info[name] = _newStudent;
studentCount++;
}
function getName(uint _studentId) public view returns(StudentsInfo memory){
return info[_studentId];
}
function getNames() public view returns(StudentsInfo[] memory){
StudentsInfo[] memory id = new StudentsInfo[](studentCount);
for (uint i = 0; i < studentCount; i++) {
StudentsInfo storage student = info[i];
id[i] = student;
}
return id;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment