-
Notifications
You must be signed in to change notification settings - Fork 0
/
StudentManagmentSystem.sol
64 lines (44 loc) · 1.81 KB
/
StudentManagmentSystem.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
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
contract StudentManagmenetSystem{
enum Departments { CS, EC, BCOM }
address public staffadvisor;
struct Student{
string name;
uint16 sem;
Departments dept;
uint16 CGPA;
uint32 rollno;
bool exist;
}
mapping(uint32 => Student) private studentDetails;
constructor() {
staffadvisor = msg.sender;
}
modifier Onlyadmin(){
require(msg.sender == staffadvisor,"You cannot access this Function");
_;
}
modifier verifyStudent(uint32 rollno){
require(studentDetails[rollno].exist,"Roll Number does not exist");
_;
}
function addStudent(string memory _name,uint16 _sem,Departments _dept,uint16 _CGPA,uint32 _rollno) public Onlyadmin {
require(!studentDetails[_rollno].exist, "Roll number is already exists");
studentDetails[_rollno] = Student(_name,_sem,_dept,_CGPA,_rollno,true);
}
function getStudent(uint32 _rollno) public view Onlyadmin returns (string memory name, uint16 sem, Departments dept, uint16 CGPA, uint32 rollno) {
Student memory student = studentDetails[_rollno];
return (student.name, student.sem, student.dept, student.CGPA, student.rollno);
}
function editData(uint16 _sem,Departments _dept,uint16 _CGPA,uint32 _rollno) public Onlyadmin verifyStudent(_rollno){
Student storage student = studentDetails[_rollno];
student.sem= _sem;
student.dept = _dept;
student.CGPA = _CGPA;
}
function editName(string memory _name,uint32 _rollno) public verifyStudent(_rollno){
Student storage student = studentDetails[_rollno];
student.name= _name;
}
}