Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Objectives: This assignment will give you an opportunity to explore the process of dividing a C++ program into modules and using the project support components

Objectives: This assignment will give you an opportunity to explore the process of dividing a C++ program into modules and using the project support components of a C++ IDE to manage your modules.

General Instructions: Read the problem description below and reorganize this program in C++. The files for this assignment are provided under the folder for this assignment. You will be submitting two separate projects. See Part A and Part B for details.

o All of the functions making up this program are complete and in working order except for functions marked with /// FILL THIS FUNCTION. You will need to implement these functions.

o The major challenge in this assignment is to divide the program into separately compiled modules.

? A reservation module with files reserved.h and reserved.cpp, containing code dealing specifically with updating the reservations array.

? A guest module, consisting of files guest.h and guest.cpp containing code dealing specifically with the guest records in the guest array.

? A table module with the files table.h and table.cpp containing code dealing with the array of tables and their availability based on time.

? There are some functions that are not specifically related to any of these modules, but are called by or contain code needed by certain modules. You should apportion these functions to the modules in a way consistent with the goals of high cohesion and low coupling.

? Consult the comments in the provided code for additional details.

Problem description: A local restaurant has decided to upgrade their reservation system from a spiral notebook. They want a program that will store customer information including phone numbers and credit card information, so regular customers dont have to give the same information over and over. There are 3 options: New Reservation, View Reservations, and Cancel Reservations.

Input: Input to the program is taken from several text files containing Reservation data, Guest data, and Table data. These are included, but your program should function even if the information in the data files were to change with the format being the same. The first line in every file is the number of data points (lines) in the file.

Output: The output should be regular updates to the 3 files, as well as interactive menus and the reservation reports.

Part A: Create a project containing the file main.cpp. Implement the empty functions marked with ///Fill This Function comments. You will need understand the purpose of these function in order to implement them. Do this by looking for where the functions are being called and how the function is being used in the program. Also, there may be other function that do similar, though not the same task. These functions may give you a clue how to implement the empty functions. The program should compile and have expected Input and Output as outlined above. You will not need to split the functions into Modules for this portion. You DO need to create function declarations for each function and move main() to the top of the list of functions.

Part B: Create a project containing the files main.cpp, reserved.cpp, reserved.h, guest.cpp, guest.h, table.cpp, table.h. Split the functions from Part A into the appropriate modules as outlined in the general instructions. The program should compile and have the same input and output as Part A. In order to determine where a function belongs, look to see what functions it calls, and which functions it is called by. Functions which rely heavily on each other are good candidates for a module. Functions which are associated in purpose may also be candidates for a particular module.

Submission notes:

? Submit all files from your project folder, including the .cpp, .cbp, .h, and input files.

? Be sure that your project compiles on CS Department computers before submission.

? Zip each folder and name it as Assg2A_cslogin.zip and Assg2B_cslogin.zip, where the cslogin is your login ID for the computers at the Department of Computer Science at ODU. Bin and Debug folders do not need to be included.

? Submit the zipped file in the respective Blackboard link.

Code Provided:

main.cpp

#include  #include  #include  #include  #include  #include  #include  using namespace std; void swapReserveItems(int reservations[][5], int indexA, int indexB) { ///swaps 2 items in reservation by row index for(int j = 0; j<5; j++) { int temp = reservations[indexA][j]; reservations[indexA][j]=reservations[indexB][j]; reservations[indexB][j]=temp; } } void readTable(std::istream& in, int row[], int numCols) { ///reads a single table row from a line in a stream /// /// FILL THIS FUNCTION /// } void sortReservations(int reservations[][5], int numItems) { ///sorts the reservations by reservation number(the first element in each row of the array) /// /// FILL THIS FUNCTION /// } void writeTable(std::ostream& out, int row[], int numCols) { /// writes a single table to a stream for(int i = 0; i< numCols; i++) { out<>guest[i]; } } void loadGuests(std::istream& in, std::string guests[][5], int numGuests) { /// loads guests from a stream for(int i=0; i>phone; if(!std::cin || phone.length()!=10 || !(phone.find_first_not_of( "0123456789" ) == string::npos)) /// checks phone number is a series of digits of the right length { std::cout<<" :::Invalid Entry!!!:::"; std::cin.clear(); std::cin.ignore(256,' '); } else { std::cin.clear(); std::cin.ignore(256,' '); return phone; } } return ""; } void sortGuests(std::string guests[][5], int numItems) { ///sorts the guests by guest number for(int i=1; iatoi(guests[j+1][0].c_str())) { swapGuestItems(guests,j,j+1); } } } } void saveGuests(std::string guests[][5], int numGuests) { /// saves guest array to a file std::fstream outFile; outFile.open("guests.txt", std::ios::out); outFile<>reservation[i]; } } std::string genNewGuestID(std::string guests[][5], int numGuests) { ///finds either an empty ID to return or returns a new one bool found = false; int largest=0; int ID=0; sortGuests(guests,numGuests); ///looks for a gap in the sorted IDs for(int i=0; ilargest) { largest = atoi(guests[i][0].c_str()); } } ///if a gap was not found, set ID to largest + 1 if(!found) { std::stringstream ss; ss<2&&party<=4) { if(table[i][4]==0) { out<<"\t"<<4< 4 && party <= 8) { if(table[i][8]==0) { out<<"\t"<<8<2 && party <= 4) { if(table[i][4]==0) { table[i][4]=RID; std::cout<<" ::::Reservation Completed::::"<4 && party <=8) { if(table[i][8]==0) { table[i][8]=RID; std::cout<<" ::::Reservation Completed::::"<largest) { largest = reservation[i][0]; } } ///if a gap was not found, set ID to largest + 2 (plus one would set it equal to the last item in the list. The last item is never evaluated for largest because of the nature of the for loop used) if(!found) { return largest+2; } return ID; } void loadReservations(std::istream& in, int reservations[][5], int numRIDs) { /// loads reservations to an array from a stream for(int i=0; i>MM; std::cin>>YYYY; ///validates the expiration data against the current date if(!std::cin || ((MM<1||MM>12)||(YYYY < (timePtr->tm_year+1900) || YYYY > 9999 ))||(YYYY==(timePtr->tm_year + 1900) && MM < (timePtr->tm_mon + 1))) { std::cout<<" :::Invalid Date!!!:::"; std::cin.clear(); std::cin.ignore(256,' '); } else { std::cin.clear(); std::cin.ignore(256,' '); ///converts the year to 2 digits YYYY= YYYY%100; std::stringstream ss; ss<>CC; if(!std::cin || CC.length()!=16 || !(CC.find_first_not_of( "0123456789" ) == string::npos)) { std::cout<<" :::Invalid Entry!!!:::"; std::cin.clear(); std::cin.ignore(256,' '); } else { std::cin.clear(); std::cin.ignore(256,' '); return CC; } } return ""; } void printAllRID(std::ostream& out, int reservations[][5], int numRIDs, std::string guests[][5], int numGuests) { /// Prints all of the reservations to a stream out<<" :::::::::::::::::::::Reservations:::::::::::::::::::::::::: "<>selection; if(!cin || (selection > (numRIDs) || selection< 1)) { std::cout<<":::::Invalid Selection:::::"; std::cin.clear(); std::cin.ignore(256,' '); } else { break; } } int RID = reservations[selection-1][0]; deleteRes(reservations, numRIDs, selection-1); releaseTable(tables, numRows, RID); } int getTime(int numRows) { /// prompts user for time of a reservation int time=0; while(true) { std::cout<<"Select a time (0-"<>time; if(!std::cin || (time<0 || time> (numRows-1))) { std::cout<<" :::::Invalid Selection:::::"; } else { std::cin.clear(); std::cin.ignore(256,' '); time = (time * 100)+1700; return time; } } return time; } int getNumParty() { /// prompts the user for the number in a guests party while(true) { int party=0; std::cout<<"Enter size of party: "; std::cin>>party; if(!std::cin || party > 8 || party < 1) { std::cout<<" :::Invalid Entry!!!:::"; std::cin.clear(); std::cin.ignore(256,' '); } else { std::cin.clear(); std::cin.ignore(256,' '); return party; } } return 0; } int menu() { ///displays the menu and returns a users selection int selection=0; while(true) { std::cout<<" :::::::::::::::::::Main Menu:::::::::::::::::::: "<>selection; if(!std::cin || (selection < 1 || selection > 4)) { std::cout<<" :::::Invalid Selection:::::"; std::cin.clear(); std::cin.ignore(256,' '); continue; } else { std::cin.clear(); std::cin.ignore(256,' '); return selection; } } } void NewReservation(int reservation[][5], int numRIDs, std::string guests[][5], int numGuests, int tables[][9], int numRows) { ///allows a user to enter a new reservation std::string Gname=""; int GID=0; std::cout<<"Enter the guests last name: "; std::cin>>Gname; std::cin.clear(); std::cin.ignore(256,' '); if(!guestExists(guests,numGuests,Gname)) { std::string Grow[5]; Grow[0]=genNewGuestID(guests,numGuests); Grow[1]=Gname; Grow[2]=getGuestPhone(); Grow[3]=getGuestCC(); Grow[4]=getGuestExpiry(); addGuest(guests,numGuests,Grow, 5); GID=atoi(Grow[0].c_str()); } else { std::cout<<":::Guest already Exists :):::"<>numRIDs; if(!inFile) { std::cout<<":::File \"reserved.txt\" missing or corrupted:::"<>numGuests; if(!inFile) { std::cout<<":::File \"guests.txt\" missing or corrupted:::"<>numRows; if(!inFile) { std::cout<<" "< 

guest.txt

4 1 whitlock 7577577575 5555555555555555 10/99 2 morris 4564564564 4444444444444444 12/99 3 carrington 2342342342 2222222222222222 01/99 4 clark 1231231231 1111111111111111 03/99

reserved.txt

4 1 4 4 1700 0 2 3 8 2100 0 3 2 2 1800 0 4 1 2 1800 0 

tables.txt

6 1700 0 4 0 1 0 0 0 0 1800 3 0 0 0 0 0 0 0 1900 0 0 0 0 0 0 0 0 2000 0 0 0 0 0 0 0 0 2100 0 0 0 0 0 0 0 2 2200 0 0 0 0 0 0 0 0

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

Students also viewed these Databases questions

Question

Can organizations execute an unlimited number of projects? Why?

Answered: 1 week ago