-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScorecard.sol
52 lines (44 loc) · 1.83 KB
/
Scorecard.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
//SPDX-License-Identifier: GPL- 3.0
pragma solidity >=0.7.0 <0.9.0;
contract Scorecard {
uint256 studentCount = 0;
address public classTeacher;
constructor() {
classTeacher=msg.sender;
}
modifier onlyClassTeacher(address _classTeacher){
require(classTeacher == _classTeacher,"Only Class Teacher has access to these actions");
_;
}
struct StudentDetails{
string studentFirstName;
string studentLastName;
uint256 id;
}
struct Score{
uint256 studentId;
uint256 englishMarks;
uint256 mathsMarks;
uint256 scienceMarks;
}
mapping(uint => StudentDetails) students;
mapping(uint => Score) scores;
event studentAdded(string _studentFirstName,string _studentLastName,uint256 _studentId);
event studentScoresRecorded(uint256 _studentId,uint256 _englishMarks,uint256 _mathsMarks,uint256 _scienceMarks);
function addStudentDetails(string memory _studentFirstName,string memory _studentLastName) public onlyClassTeacher(msg.sender){
StudentDetails storage studentObj = students[studentCount];
studentObj.studentFirstName = _studentFirstName;
studentObj.studentLastName = _studentLastName;
studentObj.id=studentCount;
emit studentAdded(_studentFirstName,_studentLastName,studentCount);
studentCount++;
}
function addStudentScores(uint256 _studentId,uint256 _englishMarks,uint256 _mathsMarks,uint256 _scienceMarks) public onlyClassTeacher(msg.sender){
Score storage scoreObject = scores[_studentId];
scoreObject.englishMarks=_englishMarks;
scoreObject.mathsMarks=_mathsMarks;
scoreObject.scienceMarks=_scienceMarks;
scoreObject.studentId=_studentId;
emit studentScoresRecorded(_studentId,_englishMarks,_mathsMarks,_scienceMarks);
}
}