Question: hw10.cpp #include #include #include #include Container.h #include student.h #include grad.h #include undergrad.h using namespace std; // forward declarations of functions already implemented: void executeAction(char c);

 hw10.cpp #include #include #include #include "Container.h" #include "student.h" #include "grad.h" #include"undergrad.h" using namespace std; // forward declarations of functions already implemented: voidexecuteAction(char c); Student* searchStudent(string name_input); // forward declarations of functions that need

hw10.cpp

#include #include #include #include "Container.h" #include "student.h" #include "grad.h" #include "undergrad.h"

using namespace std;

// forward declarations of functions already implemented: void executeAction(char c); Student* searchStudent(string name_input);

// forward declarations of functions that need implementation: void addStudent(string name_input, int rollNo_input, studentType type); // 7 points void displayList(); // 4 points void save(string fileName); // 7 points void load(string fileName); // 7 points

Container* list = NULL; // global list

int main() { char c = 'i'; // initialized to a dummy value

load("list.txt"); // During first execution, there will be no list.txt in source directory. list.txt is generated by save() while exiting the program.

do { cout > c; cin.ignore(); executeAction(c); } while (c != 'q');

save("list.txt");

list = NULL;

return 0; }

// Ask for details from user for the given selection and perform that action // Read the function case by case void executeAction(char c) { string name_input; int rollNo_input; int type_input = 2; studentType type; Student* studentFound = NULL;

switch (c) { case 'a': // add student // input student details from user cout > rollNo_input; cin.ignore();

while (!(type_input == 0 || type_input == 1)) { cout > type_input; cin.ignore(); } type = (studentType)type_input;

// searchStudent() will return the student node if found, else returns NULL studentFound = searchStudent(name_input); if (studentFound == NULL) { addStudent(name_input, rollNo_input, type); cout

break;

case 'd': // display the list displayList(); break;

case 'c': // change roll number cout > rollNo_input; cin.ignore();

// Q3c Call changeRollNo() here (1 point) // 'studentFound' contains the student whose roll number is to be changed. // 'rollNo_input' contains the new roll number of the student. // Call the function with appropriate function arguments.

cout

case 'q': // quit break;

default: cout

}

// No implementation needed here, however it may be helpful to review this function Student* searchStudent(string name_input) {

Container* tempList = list; // work on a copy of 'list'

while (tempList != NULL) // parse till end of list { if (tempList->student->getName() == name_input) { return tempList->student; // return the student if found }

tempList = tempList->next; // parse the list }

return NULL; // return NULL if student not found in list }

// Q3b: Define Friend Function changeRollNo() (3 points) // Define the function changeRollNo()that is declared in student.h file. // This function sets the new roll number of the student. The student and new roll number is to be passed as function arguments. // Call this function in case 'c' of executeAction(). While testing, use 'd' display option after using 'c' option to verify whether the new roll number is set. // You will need to implement add() and displayList() before you test this function.

// Q4: addStudent (7 points) // This function is used to add a new student to the global linked list 'list'. You may add the new student to head or tail of the list. (Sample solution adds to tail) // New student can be either undergrad or grad. You will need to use the function argument type?to determine which constructor to use to create new student node. // For example, if the user enters undergrad student, then you need to use Undergrad class and constructor to create new student node and add it to the list. // NOTE: In executeAction(), searchStudent() is called before this function. Therefore no need to check here if the student exists in the list. // See how this fucntion is called in case 'a' of executeAction()

void addStudent(string name_input, int rollNo_input, studentType type) { Container* tempList = list; // work on a copy of 'list'

}

// Q5: displayList (4 points) // This function displays the list of student and their details (roll number, student type) // Parse the list and use the class member function to display the student info. // See expected output in the question file. // No implementation needed here, however it may be helpful to review this function

void displayList() { Container *tempList = list; // work on a copy of 'list'

}

// Q6: save (7 points) // Save the linked list of students to a file list.txt using ofstream. // You will need to save the number of students in linked list. That will help in load() when reading the file. // One format to store is: // // // // // // // // ... // You may store the list in another format if you wish. You need to read the file in same way in load(). // Hint: You may want to cast the enum StudentType?to an int before writing it to the file. See example in question file. // This function is called when exiting the program (end of main() ).

void save(string fileName) { }

// Q7: load (7 points) // Load the linked list of students from the file using ifstream. // You will need to create the linked list in the same order that is was saved to the file in save(). // First, read the number of students saved in the file. // Then, for every student you will need to create a new Student node depending on student type. You may add the student to head or tail of the list. // Hint: If you casted the enum StudentType?to an int, you will need to cast it back to StudentType?when making the student node. // This function is called at the beginning of main().

void load(string fileName) {

}

undergrad.cpp

// Q2a: Define displayInfo() for Undergrad class (5 points) // Define the fucntion displayInfo() that you declared within the Undergrad class in the header file // See expected output in question file.

// (displayList() function in hw10.cpp calls this function.) // Include necessary header files

grad.cpp

// Q2b: Define displayInfo() for Grad class (5 points) // Define the function displayInfo() that you declared within the Grad class in the header file // See expected output in question file.

// (displayList() function in hw10.cpp calls this function.) // Include necessary header files

grad.h

#ifndef _GRAD_H_ #define _GRAD_H_ // Q1b: Create Grad class (5 points) // Part 1: Create a child class of the Student class named 'Grad'

// Part2: Declare constructor which accepts the same 3 parameters as the parent class Student's constructor. // Pass the 3 parameters to the super constructor of the Student class.

// Part 3: Re-declare the method displayInfo (virtual method found inside of parent class Student)

#endif // _GRAD_H_

undergrad.h

#ifndef _UNDERGRAD_H #define _UNDERGRAD_H // Q1a: Create Undergrad class (5 points) // Part 1: Create a child class of the Student class named 'Undergrad'

// Part2: Declare constructor which accepts the same 3 parameters as the parent class Student's constructor. // Pass the 3 parameters to the super constructor of the Student class.

// Part 3: Re-declare the method displayInfo (virtual method found inside of parent class Student)

#endif // _UNDERGRAD_H

ps You are given a partially completed project containing Container.h student.h undergrad.h grad.h Container.cpp student.cpp grad.cpp undergrad.cpp hw10.cpp The diagram shows the inheritance and relationships between the classes and the linked list formed list next next next null Student inheritence rollNo rollNo level level level Undergracd Grad Student() getnamel) getRollNol Student() getname() getname() getRollNo() Undergrad Grad) displayinfo() Your job is to follow the instructions given in comments in these files to complete the missing parts of the project so that the program executes properly. Tasks are included below ps You are given a partially completed project containing Container.h student.h undergrad.h grad.h Container.cpp student.cpp grad.cpp undergrad.cpp hw10.cpp The diagram shows the inheritance and relationships between the classes and the linked list formed list next next next null Student inheritence rollNo rollNo level level level Undergracd Grad Student() getnamel) getRollNol Student() getname() getname() getRollNo() Undergrad Grad) displayinfo() Your job is to follow the instructions given in comments in these files to complete the missing parts of the project so that the program executes properly. Tasks are included below

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!