Created
February 9, 2023 11:40
-
-
Save marvelous-007/f5d5409bc88751bf349153159be85e70 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: GPL-3.0 | |
pragma solidity 0.8.17; | |
struct Data{ | |
string name; | |
uint Id; | |
uint age; | |
string gender; | |
bool status; | |
} | |
interface IStudent{ | |
function registerStudent(string calldata _name, address student, uint _age, string calldata _gender) external; | |
function getStudent(address student) external view returns(Data memory _data); | |
function studentsDetails() external view returns(Data[] memory list); | |
function changeAdmin(address _newAdmin) external; | |
function DeleteStudent(address student) external; | |
} |
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: GPL-3.0 | |
pragma solidity 0.8.17; | |
import {IStudent, Data} from "./IStudent.sol"; | |
contract Chairman{ | |
address[] staffs; | |
address Admin; | |
IStudent studentDetail; | |
constructor(address _studentDetails){ | |
Admin = msg.sender; | |
studentDetail =IStudent( _studentDetails); | |
} | |
modifier onlyOwner(){ | |
require(msg.sender == Admin, "Not Admin"); | |
_; | |
} | |
function addStaff(address _staff) external onlyOwner{ | |
staffs.push(_staff); | |
} | |
function Register(string memory _name, address student, uint _age, string memory _gender) external { | |
studentDetail.registerStudent(_name, student, _age, _gender); | |
} | |
function getStudent(address student) external view returns(Data memory _data) { | |
studentDetail.getStudent(student); | |
return _data; | |
} | |
function studentsDetails() external view returns(Data[] memory list) { | |
studentDetail.studentsDetails(); | |
return list; | |
} | |
function changeAdmin(address _newAdmin) external { | |
studentDetail.changeAdmin(_newAdmin); | |
} | |
function DeleteStudent(address student) external { | |
studentDetail.DeleteStudent(student); | |
} | |
fallback() external payable{} | |
receive() external payable {} | |
} |
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: GPL-3.0 | |
pragma solidity 0.8.17; | |
contract StudentDetails{ | |
struct Data{ | |
string name; | |
uint Id; | |
uint age; | |
string gender; | |
bool status; | |
} | |
mapping (address => Data) public data; | |
Data[] public lists; | |
address[] _studentState; | |
address Admin; | |
uint ID; | |
constructor(){ | |
Admin = msg.sender; | |
} | |
modifier onlyOwner(){ | |
require(msg.sender == Admin, "Not Admin"); | |
_; | |
} | |
function registerStudent(string calldata _name, address student, uint _age, string calldata _gender) external onlyOwner{ | |
ID++; | |
Data storage _data = data[student]; | |
require(_data.status == false, "Student already exist"); | |
_data.name = _name; | |
_data.age = _age; | |
_data.gender = _gender; | |
_data.Id = ID; | |
_data.status = true; | |
_studentState.push(student); | |
} | |
function getStudent(address student) public view returns(Data memory _data){ | |
_data = data[student]; | |
} | |
function studentsDetails() external view returns(Data[] memory list){ | |
uint size = _studentState.length; | |
address[] memory studentMemory = new address[](size); | |
list = new Data[](size); | |
studentMemory = _studentState; | |
for(uint i =0; i < size; i++){ | |
Data storage _data = data[studentMemory[i]]; | |
list[i] = _data; | |
list[i] = data[studentMemory[i]]; | |
} | |
} | |
function DeleteStudent(address student) external onlyOwner{ | |
Data storage _data = data[student]; | |
require(_data.status == true, "Not student"); | |
_data.name = ""; | |
_data.age = 0; | |
_data.Id = 0; | |
_data.gender = ""; | |
_data.status = false; | |
uint size = _studentState.length; | |
address[] memory studentMemory = new address[](size); | |
studentMemory = _studentState; | |
for (uint i = 0; i < size; i++){ | |
if(student == studentMemory[i]){ | |
studentMemory[i] = studentMemory[size - 1]; | |
_studentState = studentMemory; | |
break; | |
} | |
} | |
_studentState.pop(); | |
} | |
function changeAdmin(address _newAdmin) external onlyOwner{ | |
Admin = _newAdmin; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment