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. Qb: Define Friend Function changeLibraryType points
Define the function changeLibraryTypethat 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 changeLibraryTypeRoom room,int noinput
roomType noinput;
Q: addRoom 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 addRoomstring nameinput, int noinput, libraryType type
Container tempList list; work on a copy of 'list'
Container newContainer new Container;
Room newroom;
iftype
newroom new Haydennameinput, noinput, type;
else
newroom new Noblenameinput, noinput, type;
newContainerroom newroom;
newContainernext NULL;
if list NULL
list newContainer;
else whiletempListnext NULL
tempList tempListnext;
tempListnext newContainer;
Q: displayList 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
iflist NULL
cout "list is empty" endl;
whiletempList NULL
tempListroomdisplayRoom;
tempList tempListnext;
Q: save 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 savestring fileName
Q: load 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 loadstring fileName
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
