Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. pragma solidity 0.5.1;
  2.  
  3. contract Course {
  4.  
  5. address admin;
  6. address ManagerContract;
  7. address instructor;
  8. int courseNo;
  9. mapping (int => Marks) student;
  10. mapping (int => bool) isEnrolled;
  11.  
  12. struct Marks{
  13. int midsem;
  14. int endsem;
  15. int attendance;
  16. }
  17.  
  18. constructor(int c, address inst, address adm) public {
  19. ManagerContract=msg.sender;
  20. admin=adm;
  21. instructor=inst;
  22. courseNo=c;
  23. }
  24.  
  25. function kill() public{
  26. //The admin has the right to kill the contract at any time.
  27. //Take care that no one else is able to kill the contract
  28. assert(msg.sender == admin);
  29. selfdestruct(msg.sender);
  30. }
  31.  
  32. function enroll(int rollNo) public {
  33. //This function can only be called by the ManagerContract
  34. //Enroll a student in the course if not already registered
  35. require(msg.sender==ManagerContract,"This function can only be called by the ManagerContract");
  36. student[rollNo].midsem=0;
  37. student[rollNo].endsem=0;
  38. student[rollNo].attendance=0;
  39. isEnrolled[rollNo]=true;
  40. }
  41.  
  42. function markAttendance(int rollNo) public{
  43. //Only the instructor can mark the attendance
  44. //Increment the attendance variable by one
  45. //Make sure the student is enrolled in the course
  46. require(instructor==msg.sender,"Not the instructor");
  47. require(isEnrolled[rollNo],"Student not enrolled");
  48. student[rollNo].attendance++;
  49. }
  50.  
  51. function addMidSemMarks(int rollNo, int marks) public{
  52. //Only the instructor can add midsem marks
  53. //Make sure that the student is enrolled in the course
  54. require(instructor==msg.sender,"Not the instructor");
  55. require(isEnrolled[rollNo],"Student not enrolled");
  56. require(marks>=0 && marks<=100,"Marks should be between 0-100");
  57. student[rollNo].midsem=marks;
  58.  
  59. }
  60.  
  61. function addEndSemMarks(int rollNo, int marks) public{
  62. //Only the instructor can add endsem marks
  63. //Make sure that the student is enrolled in the course
  64. require(instructor==msg.sender,"Not the instructor");
  65. require(isEnrolled[rollNo],"Student not enrolled");
  66. require(marks>=0 && marks<=100,"Marks should be between 0-100");
  67. student[rollNo].endsem=marks;
  68.  
  69. }
  70.  
  71. function getMidsemMarks(int rollNo) public view returns(int) {
  72. //Can only be called by the ManagerContract
  73. //return the midSem, endSem and attendance of the student
  74. //Make sure to check the student is enrolled
  75. require(ManagerContract==msg.sender,"Not sufficient rights");
  76. require(isEnrolled[rollNo],"Student not enrolled");
  77. int p=student[rollNo].midsem;
  78. return(p);
  79. }
  80.  
  81. function getEndsemMarks(int rollNo) public view returns(int) {
  82. //Can only be called by the ManagerContract
  83. //return the midSem, endSem and attendance of the student
  84. //Make sure to check the student is enrolled
  85. require(ManagerContract==msg.sender,"Not sufficient rights");
  86. require(isEnrolled[rollNo],"Student not enrolled");
  87. int p=student[rollNo].endsem;
  88. return(p);
  89. }
  90.  
  91. function getAttendance(int rollNo) public view returns(int) {
  92. //Can only be called by the ManagerContract
  93. //return the midSem, endSem and attendance of the student
  94. //Make sure to check the student is enrolled
  95. require(ManagerContract==msg.sender,"Not sufficient rights");
  96. require(isEnrolled[rollNo],"Student not enrolled");
  97. int p=student[rollNo].attendance;
  98. return(p);
  99. }
  100.  
  101. function isEnroll(int rollNo) public view returns(bool){
  102. //Returns if a roll no. is enrolled in a particular course or not
  103. //Can be accessed by anyone
  104. return(isEnrolled[rollNo]);
  105. }
  106.  
  107. function getinstructor() public view returns(address) {
  108. require(ManagerContract==msg.sender,"Not sufficient rights");
  109. address p=instructor;
  110. return(p);
  111. }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement