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

Flowchart and code a C++ program that takes as input data a purchase price betwe

ID: 3543881 • Letter: F

Question

Flowchart and code a C++ program that takes as input data a purchase

price between 1.0 and 10000.0 dollars, and a tax code of either R (for

regular goods) or L ( for luxury goods ).

For each purchase made the program will print the purchase price, the

amount of sales tax on that purchase to the nearest cent, (sales tax

is 4% for regular goods or 7% for luxury goods) and the full amount

paid ( this is equal to purchase price plus sales tax).

Purchases should be read into the program until end-of-file (EOF) is

reached.

After all purchases have been processed, the program will print a

summary showing the total purchase, the total tax paid and the total

amount of the bill (total purchase price plus total tax paid).

Error checks should be performed on all input data. Check purchase

price and code to make sure they are within the proper range and values.

Draw a storage layout for all variables used in your program. The

starting value of any initialized variable should be shown in the

storage layout. (Put in the correct value inside the box.) Variables

with no initial values should be filled with a '?'.

Note that there are three major sections of the program. One is the

initialization and declaration (or beginning of the program).One is

the main loop and the other is the ending of the program where you print

out the totals.

Use the sample input as your input data. Make sure that there is at

least ONE blank between purchase price and tax code .

Please check your answers with the sample output shown below.

Sample Input:

35.4 R

10000.0 L

10001.3 L

355.4 R

25.5 R


Sample Output:

purchase price sales tax full amount

35.40 1.42 36.82

10000.00 *price not within range *

10001.30 * price not within range *

355.40 14.22 369.62

25.50 1.02 26.52

SUMMARY TABLE:

total purchase price = $ 416.30

total sales tax = $ 16.65

total amount = $ 432.95

Explanation / Answer

#include<iostream> #include<queue> #include<fstream> #include<iomanip> using namespace std; struct inputPrice{ float price; char taxType; }; int main() { queue<inputPrice> inputPriceQueue; fstream inputFile; inputFile.open("input",ios::in); if (!inputFile.is_open()) { cout<<"Error In File opening.Please Try again"; getchar(); return 0; } //read all data from file to queue and close file while(inputFile.good()) { inputPrice temp; inputFile>>temp.price; if(inputFile.good()) { inputFile>>temp.taxType; inputPriceQueue.push(temp); } } inputFile.close(); //process data one by one and outpur result cout<<"purchase price "<<"sales tax "<<"full amount"<<endl; float totalAmount=0,totalTax=0,totalSum=0; while(!inputPriceQueue.empty()) { inputPrice temp; temp=inputPriceQueue.front(); //price range check if(temp.price>1.0&&temp.price<10000.0) { float tax; cout<<temp.price<<" "; totalAmount+=temp.price; if(temp.taxType=='R') tax=(temp.price*4)/100; else tax=(temp.price*7)/100;    totalTax+=tax; cout<<tax<<" "<<totalAmount+totalTax<<endl; } else { cout<<temp.price<<" *price not within range *"<<endl; } inputPriceQueue.pop(); } //summary Table cout<<"SUMMARY TABLE:"<<endl; cout<<"total purchase price = $ "<<totalAmount<<endl; cout<<"total sales tax = $ "<<totalTax<<endl; cout<<"total amount = $ "<<totalAmount+totalTax<<endl; getchar(); return 0;
}