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

PLEASE read the instructions: Modify the C++ program (listed below in the end of

ID: 3691840 • Letter: P

Question

PLEASE read the instructions:

Modify the C++ program (listed below in the end of the question) to accept all input from an external data file, the name of which is entered by the user, rather than from user input via the keyboard. The final summary displayed for each book sale should begin with the number of the sale so the individual summaries are visually separated on the screen. Otherwise, the project specifications remain the same.

The program should continually read data until the end of the file is reached. No sentinel value will be used to signal termination of the program, and you may not count the number of items in the file and use a count controlled loop to obtain the data. The data will be stored in the file such that the number of books in each sale and the single character code representing the shipping method used for that sale are on one line; the prices of all books in that sale are on the next line.

You may assume the data file has no errors. Specifically, the data file will contain information for at least one sale, the data for each sale will be stored in the order and manner described above, each sale will consist of at least one book, the price of each book will be a non-negative value, and the shipping method for each sale will consist of a single capital letter that represents one of the available options.

As a minimum, The program MUST include a single function for each of the following (additional functions, including subdivision of these into multiple functions, may be used if necessary or desired):

Obtain the name of the data file from the user and attempt to open it for reading. If the attempt to open the file fails, the program should report an appropriate error message and quit.

Obtain all input for each sale from the data file. The function should return the merchandise total and shipping method for the current sale being processed.

Calculate all discounts, fees, taxes, and any other related items for each sale.

Display a final summary for each sale.

No global variables may be used. All information must be shared between functions via parameters and return values. Your main function should be primarily variable declarations and function calls, but a control loop for reading each sale from the file may be there rather than in a separate function if desire.

Although there is some degree of flexibility with regard to the output style, a sample run of the program using a data shown below:

5 S

2.99 12.45 13.23 21.99 24.59

1 E

34.95

3 E

8.99 12.45 7.58

7 S

5.66 12.35 23.56 40 12.99 16.32 11.23

Sample Output (Using the data above)

Book Sale calculator

======================

The summary for order #1 is as follows:

Subtotal: $75.25

Tax: $3.76

Discount: $7.53

Shipping: $4.99

Total: $76.48

The summary for order #2 is as follows:

Subtotal: $34.95

Tax: $1.75

Discount: $0.00

Shipping: $12.99

Total: $49.69

The summary for order #3 is as follows:

Subtotal: $29.02

Tax: $1.45

Discount: $0.00

Shipping: $12.99

Total: $43.46

The summary for order #4 is as follows:

Subtotal: $122.11

Tax: $6.11

Discount: $18.32

Shipping: $4.99

Total: $114.89

Thanks for shopping with us. Come again!

Grading guides:

PLEASE NOTE:

The program is well documented.

The program reads from file and outputs the results (subtotal, tax, discount, etc) correctly

The program uses at least four functions and no global variables as specified in the handout.

------------------------------------------------------------------------------------------------------------------------------

The Program :


#include <iostream>
#include <string>
using namespace std;

int main()
{
while(1)
    {
      int num,i;
      cout<<"Enter the number of books in the sale: ";
      cin>>num;
      if(num==0){break;}
      double total=0,j,dis,sh;
      //We are reading the price of each book and adding it to the already existing total. The output requirement does not need us to store the individual prices of the books.
      for(i=0;i<num;i++)
        {
          cout<<"Enter price: ";
          cin>>j;
          total += j;
        }
      char ship;
      //Reading the shipping method
      cout<<"Enter shipping method [S]Standard shipping [E]Expedited shipping: ";
      cin>>ship;
      cout<<"Subtotal: $"<<total<<' ';
      cout<<"Tax: $"<<total/20<<' ';
      cout<<"Discount: $";
      if(total<50){dis=0;}
      else if(total>=50 && total<100){dis=total/10;}
      else{dis=total*15/100;}

     cout<<dis<<' ';

      if(ship=='S'){sh=4.99;}
      else{sh=12.99;}

      cout<<"Shipping: $"<<sh<<' ';
      //Calculating the total by adding tax and shipping cost and removing th
e discount.
      cout<<"Total: $"<<total+sh+total/20-dis<<' ';
    }
}

Explanation / Answer

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
int main(){
char filename[100];
cout<<"Enter the name of file to be processed ";
cin>>filename;
ifstream infile;
infile.open(filename);
string line;
while(getline(infile,line)){
istringstream iss(line);
int nbooks;
char shipment;
iss>>nbooks;
iss>>shipment;
getline(infile,line);
istringstream iss1(line);
int num,i;
double total=0,j,dis,sh;
/*We are reading the price of each book and adding it to the already existing total.
The output requirement does not need us to store the individual prices of the books.*/
for(i=0;i<nbooks;i++){
iss1>>j;
total += j;
}
cout<<"Subtotal: $"<<total<<' ';
cout<<"Tax: $"<<total/20<<' ';
cout<<"Discount: $";
if(total<50){dis=0;}
else if(total>=50 && total<100){dis=total/10;}
else{dis=total*15/100;}
cout<<dis<<' ';
if(shipment =='S'){sh=4.99;}
else{sh=12.99;}
cout<<"Shipping: $"<<sh<<' ';
/*Calculating the total by adding tax and shipping cost and removing the discount.*/
cout<<"Total: $"<<total+sh+total/20-dis<<' ';
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote