-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentDetails.sol
56 lines (40 loc) · 1.28 KB
/
StudentDetails.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
//a record of student in a university
//allows only principal to admit and exoell
contract StudentDetails{
address principal;
struct Student{
string name;
uint age;
string gender;
}
uint id;
mapping(uint => Student) public _student;
event Admitted(string indexed _name, string _gender, uint _age, uint _id);
constructor(address _prin) {
principal =_prin;
}
modifier onlyOwner(){
require(msg.sender == principal, "Not Principal");
_;
}
function admitStudent(string memory _name , string memory _gender, uint _age) external onlyOwner{
//increase the id by 1 since the default is 0
id = id +1;
uint _id = id;
//instance of the struct
Student storage newStudent = _student[id];
newStudent.name = _name;
newStudent.age = _age;
newStudent.gender = _gender;
emit Admitted(_name, _gender, _age, _id);
}
function expell(uint _id) external onlyOwner{
//Student storage newStudent = _student[id];
delete _student[_id];
}
function getStudentDetails(uint _id) external view returns(Student memory _s) {
_s = _student[_id];
}
}