using the source codes at the bottom of the page Serendipity Booksellers Softwar
ID: 3906192 • Letter: U
Question
using the source codes at the bottom of the page
Serendipity Booksellers Software Development
Project— Part 4: A Problem-Solving Exercise
1.The Main Menu
Modify the mainmenu.cpp program so it validates the user’s input. If a value outside the range of 1 through 4 is entered, the program should display an error message. Here is an example screen:
Serendipity Booksellers
Main Menu
1. Cashier Module
2. Inventory Database Module
3. Report Module
4. Exit
Enter Your Choice: 5
Please enter a number in the range 1 – 4.
Later, in Chapter 6, you will begin merging you will begin merging all the programs you have written into the mainmenu.cpp file. You will now start making preparations for that. After the user input has been validated, add a switch statement that branches to a section of code, depending on which menu choice the user made. For now, the program should simply display a message like “You selected item 1” when the user enters a number. Here is an example of the screen:
Serendipity Booksellers
Main Menu
1. Cashier Module
2. Inventory Database Module
3. Report Module
4 .Exit
Enter Your Choice: 3
You selected item 3.
2.The Inventory Database Menu
You will make the same modifications to invmenu.cpp that you made to mainmenu.cpp.
Modify the invmenu.cpp program so it validates the user’s input. If a value outside the range of 1 through 5 is entered, the program should display an error message. Here is an example screen:
Serendipity Booksellers
Inventory Database
1. Look Up a Book
2. Add a Book
3. Edit a Book’s Record
4. Delete a Book
5. Return to the Main Menu
Enter Your Choice: 9
Please enter a number in the range 1 – 5.
After the user input has been validated, add a switch statement that branches to a section of code, depending on which menu choice the user made. For now, the program should simply display a message like “You selected item 1” when the user enters a number. Here is an example of the screen:
Serendipity Booksellers
Inventory Database
1. Look Up a Book
2. Add a Book
3. Edit a Book’s Record
4. Delete a Book
5. Return to the Main Menu
Enter Your Choice: 2
You selected item 2.
3.The Reports Menu
You will make the same modifications to reports.cpp that you made to mainmenu.cpp and invmenu.cpp.
Modify the reports.cpp program so it validates the user’s input. If a value outside the range of 1 through 7 is entered, the program should display an error message. Here is an example screen:
Serendipity Booksellers
Reports
1. Inventory Listing
2. Inventory Wholesale Value
3. Inventory Retail Value
4. Listing by Quantity
5. Listing by Cost
6. Listing by Age
7. Return to Main Menu
Enter Your Choice: 8
Please enter a number in the range 1 – 7.
After the user input has been validated, add a switch statement that branches to a section of code, depending on which menu choice the user made. For now, the program should simply display a message like “You selected item 1” when the user enters a number. Here is an example of the screen:
Serendipity Booksellers
Reports
1. Inventory Listing
2. Inventory Wholesale Value
3. Inventory Retail Value
4. Listing by Quantity
5. Listing by Cost
6. Listing by Age
7. Return to Main Menu
Enter Your Choice: 5
You selected item 5.
source code for mainmenu.cpp and cashier.cpp
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string date, ISBN, Title;
int numOfBook;
double price, subtotal, tax, total;
cout<<" Serendipity Booksellers"<<endl;
cout<<"Cashier Module"<<endl <<endl;
cout<< "Date (MM/DD/YY): ";
getline (cin >> ws, date);
cout<<"Quantity of Book: ";
cin >> numOfBook;
cout<< "ISBN: ";
getline (cin >> ws, ISBN);
cout<< "Title: ";
getline (cin >> ws, Title);
cout<< "Price: ";
cin >> price;
subtotal = numOfBook * price;
tax = 6 * subtotal / 100;
total = subtotal + tax;
// setting to 2 decimal places in fixed point notation
cout << fixed << setprecision(2);
cout <<endl << "Serendipity Book Sellers" <<endl;
cout<< "Date: " << date << endl << endl;
// printing the nice header
cout<< "Qty" <<setw(10) << "ISBN" << setw(17) << "Title" << setw(24)
<< "Price" << setw(11)<< "Total" << endl;
cout<< "--------------------------------------------------------------------" <<endl;
// printing the book data
cout << numOfBook << setw(21) << ISBN << setw(22) << Title << setw(18) << setfill(' ')
<< setw(6)<< "$" << price << setfill(' ') << setw(6) << "$"<< subtotal<<endl;
cout<<" Subtotal" <<setfill(' ') << setw(6) << "$"<< subtotal << endl;
cout<<" Tax" << setfill(' ') << setw(6) << "$" << tax <<endl;
cout<<"Total" << " $" << total <<endl << endl;
cout<<"Thank you for shopping at Serendipity!" <<endl;
}
#include <iostream>
#include <string>
using namespace std;
int main()
{
int choice = 0;
while(choice < 1 || choice > 4)
{
cout<<" Serendipity Booksellers"<<endl <<endl;
cout<<" MAIN MENU "<<endl<<endl;
cout<<" 1.Cashier Module"<<endl;
cout<<" 2.Inventory Database Module"<<endl;
cout<<" 3.Report Module"<<endl;
cout<<" 4.Exit"<<endl <<endl;
cout<<" Enter your Choice: ";
cin >> choice;
if(choice < 1 || choice > 4)
cout << " Error! Invalid Choice. Choice must be in range 0 to 4." << endl << endl;
}
}
source codes for report.cpp and invmenu.cpp
invmenu.cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<" Serendipity Booksellers" <<endl;
cout<<" Inventory Database"<<endl <<endl;
cout<<" 1. Look Up a Book" <<endl;
cout<<" 2. Add a Book" <<endl;
cout<<" 3. Edit a Book's Record" <<endl;
cout<<" 4. Delete a Book" << endl;
cout<<" 5. Return to the Main Menu"<<endl <<endl;
cout<<" Enter Your Choice: ";
int choice = 0;
while(1)
{
cin>>choice;
if(choice<1 || choice>5)
{
cout<<" Invalid choice"<<endl;
cout<<" Enter Your Choice Again: ";
}
else
break;
}
return 0;
}
current OUTPUT:
reports.cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<" Serendipity Booksellers" <<endl;
cout<<" Reports"<<endl <<endl;
cout<<" 1. Inventory Listing" <<endl;
cout<<" 2. Inventory Wholesale Value" <<endl;
cout<<" 3. Inventory Retail Value" <<endl;
cout<<" 4. Listing by Quantity " << endl;
cout<<" 5. Listing by Cost " << endl;
cout<<" 6. Listing by Age " <<endl;
cout<<" 7. Return To Main Menu:"<<endl <<endl;
cout<<" Enter Your Choice: ";
int choice = 0;
while(1)
{
cin>>choice;
if(choice<1 || choice>7)
{
cout<<" Invalid choice"<<endl;
cout<<" Enter Your Choice Again: ";
}
else
break;
}
return 0;
}
Curren OUTPUT so far:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string date, ISBN, Title;
int numOfBook;
double price, subtotal, tax, total;
cout<<" Serendipity Booksellers"<<endl;
cout<<"Cashier Module"<<endl <<endl;
cout<< "Date (MM/DD/YY): ";
getline (cin >> ws, date);
cout<<"Quantity of Book: ";
cin >> numOfBook;
cout<< "ISBN: ";
getline (cin >> ws, ISBN);
cout<< "Title: ";
getline (cin >> ws, Title);
cout<< "Price: ";
cin >> price;
subtotal = numOfBook * price;
tax = 6 * subtotal / 100;
total = subtotal + tax;
// setting to 2 decimal places in fixed point notation
cout << fixed << setprecision(2);
cout <<endl << "Serendipity Book Sellers" <<endl;
cout<< "Date: " << date << endl << endl;
// printing the nice header
cout<< "Qty" <<setw(10) << "ISBN" << setw(17) << "Title" << setw(24)
<< "Price" << setw(11)<< "Total" << endl;
cout<< "--------------------------------------------------------------------" <<endl;
// printing the book data
cout << numOfBook << setw(21) << ISBN << setw(22) << Title << setw(18) << setfill(' ')
<< setw(6)<< "$" << price << setfill(' ') << setw(6) << "$"<< subtotal<<endl;
cout<<" Subtotal" <<setfill(' ') << setw(6) << "$"<< subtotal << endl;
cout<<" Tax" << setfill(' ') << setw(6) << "$" << tax <<endl;
cout<<"Total" << " $" << total <<endl << endl;
cout<<"Thank you for shopping at Serendipity!" <<endl;
}
Explanation / Answer
mainmenu.cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<" Serendipity Booksellers" <<endl;
cout<<" Main Menu"<<endl <<endl;
cout<<" 1. Cashier Module" <<endl;
cout<<" 2. Inventory Database Module" <<endl;
cout<<" 3. Report Module" <<endl;
cout<<" 4. Exit" << endl;
cout<<" Enter Your Choice: ";
int choice = 0;
while(1)
{
cin>>choice;
if(choice<1 || choice>4)
{
cout<<" Please enter a number in the range 1 - 4."<<endl;
cout<<" Enter Your Choice: ";
}
else
break;
}
switch(choice)
{
case 1:
cout<<" You selected item 1";
break;
case 2:
cout<<" You selected item 2";
break;
case 3:
cout<<" You selected item 3";
break;
case 4:
cout<<" You selected item 4";
break;
}
return 0;
}
reports.cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<" Serendipity Booksellers" <<endl;
cout<<" Reports"<<endl <<endl;
cout<<" 1. Inventory Listing" <<endl;
cout<<" 2. Inventory Wholesale Value" <<endl;
cout<<" 3. Inventory Retail Value" <<endl;
cout<<" 4. Listing by Quantity " << endl;
cout<<" 5. Listing by Cost " << endl;
cout<<" 6. Listing by Age " <<endl;
cout<<" 7. Return To Main Menu:"<<endl <<endl;
cout<<" Enter Your Choice: ";
int choice = 0;
while(1)
{
cin>>choice;
if(choice<1 || choice>7)
{
cout<<" Please enter a number in the range 1 - 7."<<endl;
cout<<" Enter Your Choice: ";
}
else
break;
}
switch(choice)
{
case 1:
cout<<" You selected item 1";
break;
case 2:
cout<<" You selected item 2";
break;
case 3:
cout<<" You selected item 3";
break;
case 4:
cout<<" You selected item 4";
break;
case 5:
cout<<" You selected item 5";
break;
case 6:
cout<<" You selected item 6";
break;
case 7:
cout<<" You selected item 7";
break;
}
return 0;
}
invmenu.cpp
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout<<" Serendipity Booksellers" <<endl;
cout<<" Inventory Database"<<endl <<endl;
cout<<" 1. Look Up a Book" <<endl;
cout<<" 2. Add a Book" <<endl;
cout<<" 3. Edit a Book's Record" <<endl;
cout<<" 4. Delete a Book" << endl;
cout<<" 5. Return to the Main Menu"<<endl <<endl;
cout<<" Enter Your Choice: ";
int choice = 0;
while(1)
{
cin>>choice;
if(choice<1 || choice>5)
{
cout<<" Please enter a number in the range 1 - 5."<<endl;
cout<<" Enter Your Choice: ";
}
else
break;
}
switch(choice)
{
case 1:
cout<<" You selected item 1";
break;
case 2:
cout<<" You selected item 2";
break;
case 3:
cout<<" You selected item 3";
break;
case 4:
cout<<" You selected item 4";
break;
case 5:
cout<<" You selected item 5";
break;
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.