Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. #include "Student.h"
  2.  
  3. // Q1 : CLASS METHODS Part 1 : Constructor and Accessor Methods for Student (5 points)
  4.  
  5. // Constructor
  6. // Create a constructor for the class Student which takes 2 string parameters (see helper function for use of constructor).
  7. // Use the 2 string parameters to initialize the 2 private local variables name and standard.
  8. // HINT: Don't forget to initialize your linked list of absents to NULL.
  9.  
  10. Student::Student(string student_name, string student_standard)
  11. {
  12. name = student_name;
  13. standard = student_standard;
  14. absents = NULL;
  15. }
  16.  
  17. // Accessor Methods
  18. // Create accessor methods for both private local strings name and standard (see print_all function for use of these methods).
  19.  
  20. string Student::getName()
  21. {
  22. return name;
  23. }
  24. string Student::getStandard()
  25. {
  26. return standard;
  27. }
  28.  
  29.  
  30. // Q2 : CLASS METHODS Part 2 : Class Methods for Students (10 points)
  31.  
  32. // Create a method named "addAbsent" which has one string parameter and no return type (see helper function for use).
  33. // This method is used to add a new date to the student's linked list of absents. The string parameter is the date of absents.
  34. // You should add the date to the tail of the linked list "absents". Absents will be added in chronological order.
  35.  
  36. void Student::addAbsent(string date)
  37. {
  38. //absents is the head of the list
  39. Absent *newAb = new Absent(date);
  40. newAb->next = NULL;
  41.  
  42. if (absents == NULL)
  43. {
  44. absents = newAb;
  45. //first ever entry intoi list
  46.  
  47. //add the ab
  48. //return
  49. }
  50. else
  51. {
  52. Absent *traverse = absents;
  53. while (traverse->next != NULL)
  54. {
  55. traverse = traverse->next;
  56. }
  57. traverse->next = newAb;
  58.  
  59. //else add at the right place
  60.  
  61. }
  62.  
  63. }
  64.  
  65.  
  66. // Create a method named "lastAbsent" which has no parameters and returns a string (see print_all function for use).
  67. // This method will be used to return a string for the date of the last checkup for this student.
  68. // If the student has not yet had an absent, return an empty string.
  69.  
  70. //ENTER CODE HERE
  71. string Student::lastAbsent()
  72. {
  73. //absents is the head of the list
  74.  
  75. if (absents == NULL)
  76. {
  77. return "";
  78.  
  79. }
  80. else
  81. {
  82. //traversing through the absents
  83. Absent *traverse = absents;
  84. while (traverse->next != NULL)
  85. {
  86. //iterating through
  87. traverse = traverse->next;
  88. }
  89. //getting the date for Absent
  90. string lastDate = traverse->getDate();
  91. return lastDate;
  92.  
  93. }
  94.  
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement