Created
July 20, 2022 10:44
-
-
Save dastagirkhan/865d73d5696ed5fea75baeb1aa8b00cf to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.7+commit.e28d00a7.js&optimize=false&runs=200&gist=
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; | |
| import "@openzeppelin/contracts/utils/Strings.sol"; | |
| contract School { | |
| address owner; | |
| constructor() public{ | |
| owner = msg.sender; | |
| } | |
| modifier onlyOwner{ | |
| require(msg.sender == owner); | |
| _; | |
| } | |
| modifier fees(uint price){ | |
| if(msg.value >= price){ | |
| _; | |
| } | |
| } | |
| modifier onlyStudent{ | |
| require(msg.sender != owner); | |
| _; | |
| } | |
| } | |
| contract SchoolStudent is School{ | |
| struct Student { | |
| string name; | |
| uint8 age; | |
| bool isStudent; | |
| } | |
| mapping(address => Student) public students; | |
| address[] public studentAddressCluster; | |
| uint public studentCount; | |
| uint enrollTermFees; | |
| mapping(address => bool) studentEnrolledTermFeesCluster; | |
| function setEnrollTermFees(uint fees) public onlyOwner { | |
| enrollTermFees = fees; | |
| } | |
| function getEnrollTermFees() public view returns(uint) { | |
| return enrollTermFees; | |
| } | |
| function setStudent(string memory name, uint8 age) payable onlyStudent fees(enrollTermFees) public returns(address){ | |
| require(students[msg.sender].isStudent == false); | |
| students[msg.sender] = Student({ | |
| name:name, | |
| age:age, | |
| isStudent:true | |
| }); | |
| studentAddressCluster.push(msg.sender); | |
| studentCount = studentAddressCluster.length; | |
| studentEnrolledTermFeesCluster[msg.sender] = true; | |
| return msg.sender; | |
| } | |
| function getStudents() public view returns(uint[] memory, string[] memory, address[] memory){ | |
| uint[] memory age = new uint[](studentCount); | |
| string[] memory name = new string[](studentCount); | |
| address[] memory addresses = new address[](studentCount); | |
| for(uint i = 0; i < studentCount; i++){ | |
| Student storage student = students[studentAddressCluster[i]]; | |
| age[i] = student.age; | |
| name[i] = student.name; | |
| addresses[i] = studentAddressCluster[i]; | |
| } | |
| return (age, name, addresses); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment