Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Student.h"
- // Q1 : CLASS METHODS Part 1 : Constructor and Accessor Methods for Student (5 points)
- // Constructor
- // Create a constructor for the class Student which takes 2 string parameters (see helper function for use of constructor).
- // Use the 2 string parameters to initialize the 2 private local variables name and standard.
- // HINT: Don't forget to initialize your linked list of absents to NULL.
- Student::Student(string student_name, string student_standard)
- {
- name = student_name;
- standard = student_standard;
- absents = NULL;
- }
- // Accessor Methods
- // Create accessor methods for both private local strings name and standard (see print_all function for use of these methods).
- string Student::getName()
- {
- return name;
- }
- string Student::getStandard()
- {
- return standard;
- }
- // Q2 : CLASS METHODS Part 2 : Class Methods for Students (10 points)
- // Create a method named "addAbsent" which has one string parameter and no return type (see helper function for use).
- // 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.
- // You should add the date to the tail of the linked list "absents". Absents will be added in chronological order.
- void Student::addAbsent(string date)
- {
- //absents is the head of the list
- Absent *newAb = new Absent(date);
- newAb->next = NULL;
- if (absents == NULL)
- {
- absents = newAb;
- //first ever entry intoi list
- //add the ab
- //return
- }
- else
- {
- Absent *traverse = absents;
- while (traverse->next != NULL)
- {
- traverse = traverse->next;
- }
- traverse->next = newAb;
- //else add at the right place
- }
- }
- // Create a method named "lastAbsent" which has no parameters and returns a string (see print_all function for use).
- // This method will be used to return a string for the date of the last checkup for this student.
- // If the student has not yet had an absent, return an empty string.
- //ENTER CODE HERE
- string Student::lastAbsent()
- {
- //absents is the head of the list
- if (absents == NULL)
- {
- return "";
- }
- else
- {
- //traversing through the absents
- Absent *traverse = absents;
- while (traverse->next != NULL)
- {
- //iterating through
- traverse = traverse->next;
- }
- //getting the date for Absent
- string lastDate = traverse->getDate();
- return lastDate;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement