Question: I need help with this code. this is part of a code that makes a list of books. I had the question parts of the

I need help with this code. this is part of a code that makes a list of books. I had the question parts of the code because im confused on how to do this. // Q3b: Define Friend Function changeLibraryType()(3 points)
// Define the function changeLibraryType()that is declared in room.h file.
// This function sets the new library type for the room. The room object and new library type (as integer) are to be passed as function arguments.
// Use 'd' display option after using 'c' option to verify.
// You will need to implement add() and displayList() before you test this function.
void changeLibraryType(Room* room,int no_input)
{
room->Type = no_input;
}
// Q4: addRoom (7 points)
// This function is used to add a new room to the global linked list 'list'. You may add the new room to head or tail of the list. (Sample solution adds to tail)
// libraryType 'type' can be hayden or noble. You will need to use the function argument type to determine which constructor to use to create new room node.
// For example, if the user enters type as 'noble', then you need to use Noble class and constructor to create new room node and add it to the list.
// NOTE: In executeAction(), searchroom() is called before this function. Therefore no need to check here if the room exists in the list.
// See how this fucntion is called in case 'a' of executeAction()
void addRoom(string name_input, int no_input, libraryType type)
{
Container* tempList = list; // work on a copy of 'list'
Container* newContainer = new Container();
Room* newroom;
if(type ==0){
newroom = new Hayden(name_input, no_input, type);
}else{
newroom = new Noble(name_input, no_input, type);
}
newContainer->room = newroom;
newContainer->next = NULL;
if (list == NULL)
list = newContainer;
else{ while(tempList->next != NULL){
tempList = tempList->next;
}
tempList->next = newContainer;
}
}
// Q5: displayList (4 points)
// This function displays the list of room and their details (name, no, library name)
// Parse the list and use the class member function to display the room info.
// See expected output in the question file.
void displayList()
{
Container *tempList = list; // work on a copy of 'list'
//this should check if the list is null or display list if not null
if(list == NULL)
cout << "list is empty" << endl;
while(tempList != NULL){
tempList->room->displayRoom();
tempList = tempList->next;
}
}
// Q6: save (7 points)
// Save the linked list of rooms to a file list.txt using ofstream.
// You will need to save the number of rooms in linked list. That will help in load() when reading the file.
// One format to store is:
//
//
//
//
//
//
//
// and so on..
// You may store the list in another format if you wish. You need to read the file in load () the same way that it is saved in save().
// This function is called when exiting the program (end of main()).
// Hint: You may want to cast the enum libraryType to an int before writing it to the file.
void save(string fileName)
{
}
// Q7: load (7 points)
// Load the linked list of rooms 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 rooms saved in the file.
// Then, for every room you will need to create a new Room node depending on room type. You may add the room to head or tail of the list.
// Hint: If you casted the enum 'libraryType' to an int, you will need to cast it back to 'libraryType' when making the room node.
// This function is called at the beginning of main().
void load(string fileName)
{
}

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 Accounting Questions!