write a 2 program Write a program that formats product infor
write a 2 program
Write a program that formats product information entered by the user and calculate the total amount of purchase.
Enter item number:583
Enter unit price:13.5
Enter quantity:2
Enter purchase date (mm/dd/yyyy):09/15/2016
Item Unit Price QTY Purchase Date Total Amount
583 $ 13.50 2 9/15/2016 $ 27.00
The item number, quantity and date should be left justified; the unit price and total amount should be right justified. Hint: Use tabs to line up the columns.
Solution
Calc.cpp
#include <iostream>
using namespace std;
int main()
 {
 int itemNo, quantity;
 double price;
 string date;
 cout<<\"Enter item number: \";
 cin >> itemNo;
 cout<<\"Enter unit price: \";
 cin >> price;
 cout<<\"Enter quantity: \";
 cin >> quantity;
 cout<<\"Enter purchase date (mm/dd/yyyy): \";
 cin >> date ;
 double total = price * quantity;
 cout<<\"Item\\tUnit Price\\tQTY\\tPurchas Date\\tTotal Amount\"<<endl;
 cout<<std::left<<itemNo<<\"\\t\"<<\"$\"<<std::right <<price<<\"\\t\"<<std::left<<quantity<<\"\\t\"<<std::left<<date<<\"\\t\"<<\"$\"<<std::right<<total<<endl;
 
 return 0;
 }
Output:
sh-4.3$ g++ -std=c++11 -o main *.cpp
sh-4.3$ main
Enter item number: 583
Enter unit price: 13.5
Enter quantity: 2
Enter purchase date (mm/dd/yyyy): 09/15/2016
Item Unit Price QTY Purchas Date Total Amount
583 $13.5 2 09/15/2016 $27


