3 FORMATTING OUTPUT Look at the following table: PRICE QUANTITY 1.95 10.89 Assum
ID: 3873790 • Letter: 3
Question
3 FORMATTING OUTPUT Look at the following table: PRICE QUANTITY 1.95 10.89 Assume that from the left margin, the price takes up fifteen spaces. We could say that the numbers are right justified in a 15-width space. Starting where the price ends, the next field (quantity) takes up twelve spaces. We can use the formatted output from the previous section and the statement setw(n) where n is some integer to indicate the width to produce such tables. Download the program tabledata.cpp from the Lab 3 folder Exercise 1 Finish the code above by filling in the blanks and the instructions necessary to execute the following sample run Note that rwo or more data iens can be input at oneme baing at leas them before hitting the enter key Please input the price and quantity of the first ite 1.95 8 Please input the price and quantity of the second item 10.899 PRICE OUANTITY 1.95 10.89 1 RITHMETIC QPERATIONS AND MATH FUNCTIONSExplanation / Answer
#include <bits/stdc++.h>
using namespace std;
int main()
{
/* array to store price and quantity */
double price[2];
int quantity[2];
cout<<"Please Input the quantity of the first item-";
cin>>price[0]>>quantity[0];
cout<<"Please Input the quantity of the second item-";
cin>>price[1]>>quantity[1];
/* price and quantity left margin is set */
cout << setfill(' ') << setw(15) << "PRICE";
cout << setfill(' ') << setw(17) << "QUANTITY"<<endl;
/* right justified printing with 15 width space */
cout << right << setw(15) << price[0] ;
cout << right << setw(15) << quantity[0]<<endl ;
cout << right << setw(15) << price[1] ;
cout << right << setw(15) << quantity[1] << endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.