Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pragma solidity 0.5.1;
- contract Course {
- address admin;
- address ManagerContract;
- address instructor;
- int courseNo;
- mapping (int => Marks) student;
- mapping (int => bool) isEnrolled;
- struct Marks{
- int midsem;
- int endsem;
- int attendance;
- }
- constructor(int c, address inst, address adm) public {
- ManagerContract=msg.sender;
- admin=adm;
- instructor=inst;
- courseNo=c;
- }
- function kill() public{
- //The admin has the right to kill the contract at any time.
- //Take care that no one else is able to kill the contract
- assert(msg.sender == admin);
- selfdestruct(msg.sender);
- }
- function enroll(int rollNo) public {
- //This function can only be called by the ManagerContract
- //Enroll a student in the course if not already registered
- require(msg.sender==ManagerContract,"This function can only be called by the ManagerContract");
- student[rollNo].midsem=0;
- student[rollNo].endsem=0;
- student[rollNo].attendance=0;
- isEnrolled[rollNo]=true;
- }
- function markAttendance(int rollNo) public{
- //Only the instructor can mark the attendance
- //Increment the attendance variable by one
- //Make sure the student is enrolled in the course
- require(instructor==msg.sender,"Not the instructor");
- require(isEnrolled[rollNo],"Student not enrolled");
- student[rollNo].attendance++;
- }
- function addMidSemMarks(int rollNo, int marks) public{
- //Only the instructor can add midsem marks
- //Make sure that the student is enrolled in the course
- require(instructor==msg.sender,"Not the instructor");
- require(isEnrolled[rollNo],"Student not enrolled");
- require(marks>=0 && marks<=100,"Marks should be between 0-100");
- student[rollNo].midsem=marks;
- }
- function addEndSemMarks(int rollNo, int marks) public{
- //Only the instructor can add endsem marks
- //Make sure that the student is enrolled in the course
- require(instructor==msg.sender,"Not the instructor");
- require(isEnrolled[rollNo],"Student not enrolled");
- require(marks>=0 && marks<=100,"Marks should be between 0-100");
- student[rollNo].endsem=marks;
- }
- function getMidsemMarks(int rollNo) public view returns(int) {
- //Can only be called by the ManagerContract
- //return the midSem, endSem and attendance of the student
- //Make sure to check the student is enrolled
- require(ManagerContract==msg.sender,"Not sufficient rights");
- require(isEnrolled[rollNo],"Student not enrolled");
- int p=student[rollNo].midsem;
- return(p);
- }
- function getEndsemMarks(int rollNo) public view returns(int) {
- //Can only be called by the ManagerContract
- //return the midSem, endSem and attendance of the student
- //Make sure to check the student is enrolled
- require(ManagerContract==msg.sender,"Not sufficient rights");
- require(isEnrolled[rollNo],"Student not enrolled");
- int p=student[rollNo].endsem;
- return(p);
- }
- function getAttendance(int rollNo) public view returns(int) {
- //Can only be called by the ManagerContract
- //return the midSem, endSem and attendance of the student
- //Make sure to check the student is enrolled
- require(ManagerContract==msg.sender,"Not sufficient rights");
- require(isEnrolled[rollNo],"Student not enrolled");
- int p=student[rollNo].attendance;
- return(p);
- }
- function isEnroll(int rollNo) public view returns(bool){
- //Returns if a roll no. is enrolled in a particular course or not
- //Can be accessed by anyone
- return(isEnrolled[rollNo]);
- }
- function getinstructor() public view returns(address) {
- require(ManagerContract==msg.sender,"Not sufficient rights");
- address p=instructor;
- return(p);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement