Question
In this project you will write a C++ program that simulates the purchase of a single item in an online store. What to do Write
In this project you will write a C++ program that simulates the purchase
of a single item in an online store.
What to do
Write a C++ program that:
1. Prints out a welcome message.
2. Prompts the user for the following information: (a) Their first name (example: Roger)
(b) Their last name (example: Waters)
(c) The name of the product (example: Brick)
(d) The unit price of the product (example: 1.99)
(e) The quantity to buy (example: 200)
(f) Their sales tax rate, as a percentage (example: 7.75)
3. Calculates a subtotal, according to the formula
subtotal = (unit price) * (number to buy)
4. Calculates sales tax, according to the formula
sales tax = (subtotal) * (tax rate) / 100
5. Calculates shipping, according to the formula
shipping = .09 * (subtotal)
6. Calculates the grand total, according to the formula
grand total = subtotal + sales tax + shipping
7. Prints out a sales invoice. All of the input data, and calculated dollar amounts, should be printed out (first name, last name, product name, unit price, quantity, sales rate, subtotal, shipping charge, grand total). This information must be printed neatly, with aligned columns, appropriate whitespace, and dollar signs.
For full credit, your program must do the following:
_ declare variables for each of the data items (first name, last name, etc.)
_ use cin to input all the variables
_ store the first name, last name, and product name fields as strings and print them with cout
_ declare double variables for the subtotal, sales tax, shipping, and grand total, assign them values according to the formulas above, and print out the variables to cout
_ use the fixed and setprecision output manipulators to output all dollar figures with only two digits after the decimal point
_ print out all dollar figures in a vertically-aligned column using setw
Sample Input and Output
Hints
Reading strings with spaces
When the << operator reads a string from standard input, it stops at the first whitespace character it encounters. So far youve probably used the enter key to designate the end of each data item; but a space will have the same effect. So, if you use cin to read in the string variables, make sure to type in data with only one word (i.e., avoid Laser printer, which has a space). Otherwise your program will get confused.
Rounding to two decimal places
The fixed output manipulator causes the next floating point number printed to cout to use fixed precision mode, meaning that the number of digits after the decimal point is limited according to setprecision. So the following line of code
cout << fixed << setprecision( 3 ) << 3.1415926 << endl;
generates the following output:
3.142
You must #include
Controlling field width
The setw(k) output manipulator causes the next item to be output to use exactly k characters. If the item would normally use fewer characters, then extra padding spaces are inserted to use up all k characters. Thus
cout << Name: << setw ( 8 ) << David << endl ;
generates the following output:
Name: David
Note that there are exactly 3 characters between the : and the D.
You must #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started