Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

using the source codes at the bottom of the page Serendipity Booksellers Softwar

ID: 3906339 • Letter: U

Question

using the source codes at the bottom of the page

Serendipity Booksellers Software Development Project— Part 5: A Problem-Solving Exercise

1.Data Validation Modification

In Part 4 of this project you used if statements in each module to validate the input. Modify the code to use while loops instead.

2.The Main Menu

Item four on the Main Menu is “Exit,” which allows the user to end the program. Add a loop to the mainmenu.cpp program that causes it to repeatedly display the menu until the user selects item four.

3.The Inventory Database Menu

Item five on the Inventory Database Menu is “Return to the Main Menu.” When the project is complete, this item will cause the program to branch back to the main menu. For now, add a loop to the invmenu.cpp program that causes it to repeatedly display the menu until the user selects item five.

4.The Reports Menu

Item seven on the Reports Menu is “Return to the Main Menu.” When the project is complete, this item will cause the program to branch back to the main menu. For now, add a loop to the reports.cpp program that causes it to repeatedly display the menu until the user selects item seven.

5.The Cashier Module

After the user has entered the data for a sale and the simulated sales slip is displayed, add code that asks the cashier if another transaction is to be processed. If so, the program should repeat.

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;

}

#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;
}

Modified cahier.cpp Program

#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

1) Data Validation Modification

In Part 4 of this project you used if statements in each module to validate the input. Modify the code to use while loops instead.

for mainmenu.cpp

while(choice<1 || choice>4)
              {
                            cout<<" Enter Your Choice(1 to 7): ";
                             cin>>choice;
              }

for reports.cpp

while(choice<1 || choice>7)
              {
                            cout<<" Enter Your Choice(1 to 7): ";
                             cin>>choice;
              }

for invmenu.cpp

while(choice<1 || choice>5)
              {
                            cout<<" Enter Your Choice(1 to 5): ";
                             cin>>choice;
              }

2)The Main Menu

Item four on the Main Menu is “Exit,” which allows the user to end the program. Add a loop to the mainmenu.cpp program that causes it to repeatedly display the menu until the user selects item four.

#include <iostream>
#include <string>
using namespace std;
int main()
{
            int choice = 0;
            while(choice!=4)
            {
              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: ";
            
             
              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;
}

3.The Inventory Database Menu

Item five on the Inventory Database Menu is “Return to the Main Menu.” When the project is complete, this item will cause the program to branch back to the main menu. For now, add a loop to the invmenu.cpp program that causes it to repeatedly display the menu until the user selects item five.

#include <iostream>
#include <string>
using namespace std;
int main()
{
    int choice = 0;
        while(choice!=5)
        {
              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: ";
            
             
              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;
}

4.The Reports Menu

Item seven on the Reports Menu is “Return to the Main Menu.” When the project is complete, this item will cause the program to branch back to the main menu. For now, add a loop to the reports.cpp program that causes it to repeatedly display the menu until the user selects item seven.

#include <iostream>
#include <string>
using namespace std;
int main()
{
    int choice = 0;
        while(choice!=7)
        {
              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: ";
            
             
              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;
}

5) The Cashier Module

After the user has entered the data for a sale and the simulated sales slip is displayed, add code that asks the cashier if another transaction is to be processed. If so, the program should repeat.

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
string date, ISBN, Title;
int numOfBook;
double price, subtotal, tax, total;
int flag=1;
while(flag==1)
{
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<<" ------------------------------------------";
     cout<<" Do you want to continue..??(1 for Yes):";

     cin>>flag;
    cout<<" ------------------------------------------";
}
cout<<"Thank you for shopping at Serendipity!" <<endl;
   
}