Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// READ BEFORE YOU START: // You are given a partially completed program that creates a list of pets with their list of absents. //

image text in transcribed

image text in transcribed

// READ BEFORE YOU START: // You are given a partially completed program that creates a list of pets with their list of absents. // Each student has the corresponding information: name, standard, and a linked list of absents. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you risk failing the automated test cases. // // You are to assume that all input is valid: // Valid name: String containing alphabetical letters beginning with a capital letter // Valid standard: String containing alphabetical letters beginning with a number // Valid date: String in the following format: "MM/DD/YYYY" ex: "01/01/2010" // All input will be a valid length and no more than the allowed amount of memory will be used // // Q1 : CLASS METHODS Part 1 : Constructor and Accessor Methods for Student class in Student.cpp file ( 5 points) // Q2 : CLASS METHODS Part 2 : Class methods for Student class in Student.cpp file (10 points) // Q3 : Add Function in hw09.cpp file ( 5 points) // Q4 : Search Function in hw09.cpp file (10 points) // Q5 : Remove One Function in hw09.cpp file (15 points) // Q6 : Implement cin / cout for the lines in main without modifying the functionality ( 5 points)

#include #include #include

#include "Container.h" #include "Student.h" #include "Absent.h"

using namespace std;

// forward declarations void flush(); void branching(char); void registration(char); void add_student(string, string); Student* search_student(string, string); void remove_student(string, string);

void print_all(); void remove_all();

Container* list = NULL; // global list

int main() { // _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); // Use to check for memory leaks in VS

char ch = 'i';

do {

// Q6: Implement cin / cout for the lines below without modifying the functionality (5 points) // (change all printf statements to cout and read the next char using cin) cout > ch; // End Q6

flush(); branching(ch); } while (ch != 'q');

remove_all(); list = NULL; return 0; }

void flush() { int c; do c = getchar(); while (c != ' ' && c != EOF); }

void branching(char c) { switch (c) { case 'a': case 'c': case 'r': case 'p': registration(c); break; case 'q': break; default: printf(" Invalid input! "); } }

// The registration function is used to determine how much data is needed and which function to send that data to. // It uses pointers and values that are returned from some functions to produce the correct ouput. // There is no implementation needed here, but you should study this function and know how it works. // It is always helpful to understand how the code works before implementing new features. // Do not change anything in this function or you risk failing the automated test cases. void registration(char c) { string name, standard;

if (c == 'p') print_all(); else { cout > name; cout > standard; flush();

Student* student_result = search_student(name, standard);

if (c == 'a') // add student { if (student_result == NULL) { add_student(name, standard); cout

string date; cout > date; flush();

student_result->addAbsent(date); cout

remove_student(name, standard); cout

// Q3: Add Student (5 points) // This function will be used to add a new student to the head of you linked list of containers, no need for sorting. // The search function is called before this function, therefore you can assume the student is not already on the list. // If the student is added to the list, return 1. If the student already exists on the list (not added), return 0. void add_student(string name, string standard) { }

// Q4: Search (10 points) // This function will be used to search for a student on the list. // Students on the list may have the same name OR the same standard, but should not have the same name AND standard. // Therefore, you must traverse the list and return a pointer to a 'Student' with the desired name AND standard. // If the student does not exist on the list, return NULL. (See registration function for use of this function). Student* search_student(string name, string standard) { }

// Q5: Remove Pet (15 points) // This function will be used to remove a student from the list. // Traverse the list and use the parameters to remove the student. // Use proper memory management to ensure no memory leaks. void remove_student(string name, string standard) { }

// This function is already implemented for you. It traverses the list and removes all pets to ensure no memory leaks. void remove_all() { while (list != NULL) { Container* container_to_be_removed = list; list = list->next;

while (container_to_be_removed->student->absents != NULL) { Absent *absent_to_be_removed = container_to_be_removed->student->absents; container_to_be_removed->student->absents = container_to_be_removed->student->absents->next; delete absent_to_be_removed; }

delete container_to_be_removed->student; delete container_to_be_removed; } }

// This function is already implemented for you. It prints all of the pets in the list in an organized format. void print_all() { if (list == NULL) cout

Container *container_traverser = list;

while (container_traverser != NULL) { cout student->getName() student->getStandard()

string last_absent = container_traverser->student->lastAbsent();

if (last_absent.empty()) cout

container_traverser = container_traverser->next; } }

#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.

//ENTER CODE HERE

// Accessor Methods // Create accessor methods for both private local strings name and standard (see print_all function for use of these methods).

//ENTER CODE HERE

// 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.

//ENTER CODE HERE

// 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

You are given a partially completed project containing: 3 header files: Container. h Student h Absent. 4 C++ files: Container cpp Student cpp Absent cpp hy09.cpp Your job is to follow the instructions given in the comments of the hy09.cpp and Student.cpp files to complete the missing parts of the project so that the program executes properly. Q1: Constructor and Accessor Methods for Student class (5 points) You will need to write the constructor and accessor methods for the Student class in the Student cpp file. The program will not compile until this part is completed. The constructor and accessor methods are already declared in the Student.h file. (See Student cpp file for details). Q2: Add Absent and Last Absent Methods for Student class (10 points) You will need to write these methods for the Student class in the Student.cpp file. The program will not compile until this part is completed. These methods are already declared in the Student.h file. (See Student.cpp file for further instructions). Please enter your selection a: add a new student to the list add a new absent for a student C r remove a student from the list p: print all students on the list q quit Please enter the student s name: Prajakta Please enter the student s standard Please enter the date of the absent 1/23/2217 Absent added You are given a partially completed project containing: 3 header files: Container. h Student h Absent. 4 C++ files: Container cpp Student cpp Absent cpp hy09.cpp Your job is to follow the instructions given in the comments of the hy09.cpp and Student.cpp files to complete the missing parts of the project so that the program executes properly. Q1: Constructor and Accessor Methods for Student class (5 points) You will need to write the constructor and accessor methods for the Student class in the Student cpp file. The program will not compile until this part is completed. The constructor and accessor methods are already declared in the Student.h file. (See Student cpp file for details). Q2: Add Absent and Last Absent Methods for Student class (10 points) You will need to write these methods for the Student class in the Student.cpp file. The program will not compile until this part is completed. These methods are already declared in the Student.h file. (See Student.cpp file for further instructions). Please enter your selection a: add a new student to the list add a new absent for a student C r remove a student from the list p: print all students on the list q quit Please enter the student s name: Prajakta Please enter the student s standard Please enter the date of the absent 1/23/2217 Absent added

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions