Last active
February 3, 2023 17:35
-
-
Save faytey/cafcdb766dbc2f7167fe4b0064003fc0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| //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