need the output to have the decimal points lined up for any test data I decide to use. How could I do that in this code?. (The computer language that I am using is c++) #include #include //Define constant for tax rate #define taxRate 0.0788 using namespace std; int main() { //Set the precision to two decimal places cout << setprecision(2) << fixed; const double EXT_MONITOR=159.99; const double DELL_KEYB=18.30; const double DELL_MOUSE=16.45; const double WIND_OS=199.99; const double PRINTER=599.89; int extMonitor,d_keyboards,d_mouse,wind_OS,printer; double costEMonitor,costDell_key,cost_d_mouse,costWindOs,costPrinter; double total=0,subtotal,tax; //Get the required inputs from the user cout<<"How many External Monitor s were ordered? "; cin>>extMonitor; cout<<"How many Dell keyboards players were ordered? "; cin>>d_keyboards; cout<<"How many Dell Mouse units were ordered? "; cin>>d_mouse; cout<<"How many Windows 10 OS were ordered? "; cin>>wind_OS; cout<<"How many Network Printers were ordered? "; cin>>printer; //Compute cost for external monitor costEMonitor=EXT_MONITOR*extMonitor; //Compute cost for dell mouse cost_d_mouse=DELL_MOUSE*d_mouse; //Compute cost for dell keyboard costDell_key=DELL_KEYB*d_keyboards; //Compute cost for windows OS costWindOs=WIND_OS*wind_OS; //Compute cost for printer costPrinter=PRINTER*printer; //Compute cost for sub total subtotal=costEMonitor+costDell_key+cost_d_mouse+costPrinter+costWindOs; //Print the output cout<<"\nQTY Description Unit Price Total Price"<

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

I need the output to have the decimal points lined up for any test data I decide to use. How could I do that in this code?. (The computer language that I am using is c++)

#include <iostream>
#include <iomanip>
//Define constant for tax rate
#define taxRate 0.0788
using namespace std;
int main()
{
//Set the precision to two decimal places
cout << setprecision(2) << fixed;
const double EXT_MONITOR=159.99;
const double DELL_KEYB=18.30;
const double DELL_MOUSE=16.45;
const double WIND_OS=199.99;
const double PRINTER=599.89;
int extMonitor,d_keyboards,d_mouse,wind_OS,printer;
double costEMonitor,costDell_key,cost_d_mouse,costWindOs,costPrinter;
double total=0,subtotal,tax;
//Get the required inputs from the user
cout<<"How many External Monitor s were ordered? ";
cin>>extMonitor;
cout<<"How many Dell keyboards players were ordered? ";
cin>>d_keyboards;
cout<<"How many Dell Mouse units were ordered? ";
cin>>d_mouse;
cout<<"How many Windows 10 OS were ordered? ";
cin>>wind_OS;
cout<<"How many Network Printers were ordered? ";
cin>>printer;
//Compute cost for external monitor
costEMonitor=EXT_MONITOR*extMonitor;
//Compute cost for dell mouse
cost_d_mouse=DELL_MOUSE*d_mouse;
//Compute cost for dell keyboard
costDell_key=DELL_KEYB*d_keyboards;
//Compute cost for windows OS
costWindOs=WIND_OS*wind_OS;
//Compute cost for printer
costPrinter=PRINTER*printer;
//Compute cost for sub total
subtotal=costEMonitor+costDell_key+cost_d_mouse+costPrinter+costWindOs;
//Print the output
cout<<"\nQTY Description Unit Price Total Price"<<endl;
cout<<extMonitor<<setw(15)<<" EXTERNAL MONITOR "<<setw(6)<<EXT_MONITOR<<" "<<setw(6)<<costEMonitor<<endl;
cout<<d_keyboards<<setw(15)<<" DELL KEYBOARD "<<setw(6)<<DELL_KEYB<< " "<<setw(6)<<costDell_key<<endl;
cout<<d_mouse<<setw(15)<<" DELL MOUSE "<<setw(6)<<DELL_MOUSE<< " "<<setw(6)<<cost_d_mouse<<endl;
cout<<wind_OS<<setw(15)<<" WINDOWS OS "<<setw(6)<<WIND_OS<< " "<<setw(6)<<costWindOs<<endl;
cout<<printer<<setw(15)<<" NETWORK PRINTER "<<setw(6)<<PRINTER<< " "<<setw(6)<<costPrinter<<endl;
cout<<"\nSUBTOTAL "<<subtotal<<endl;
//Compute tax
tax=subtotal*taxRate;
//Compute total
total=subtotal+tax;
cout<<"TAX "<<tax<<endl;
cout<<"TOTAL "<<total<<endl;

return 0;
}

Expert Solution
Step 1

You should first use the alignment type and then use the setw command to format the output.

PROGRAM:

//Header file

#include <iostream>

#include <iomanip>

 

//Define constant for tax rate

#define taxRate 0.0788

using namespace std;

 

//Defining main

int main()

{

 

  //Set the precision to two decimal places

  cout << setprecision(2) << fixed;

  const double EXT_MONITOR=159.99;

  const double DELL_KEYB=18.30;

  const double DELL_MOUSE=16.45;

  const double WIND_OS=199.99;

  const double PRINTER=599.89;

  int extMonitor,d_keyboards,d_mouse,wind_OS,printer;

  double costEMonitor,costDell_key,cost_d_mouse,costWindOs,costPrinter;

  double total=0,subtotal,tax;

 

  //Get the required inputs from the user

  cout<<"How many External Monitor s were ordered? ";

  cin>>extMonitor;

  cout<<"How many Dell keyboards players were ordered? ";

  cin>>d_keyboards;

  cout<<"How many Dell Mouse units were ordered? ";

  cin>>d_mouse;

  cout<<"How many Windows 10 OS were ordered? ";

  cin>>wind_OS;

  cout<<"How many Network Printers were ordered? ";

  cin>>printer;

 

  //Compute cost for external monitor

  costEMonitor=EXT_MONITOR*extMonitor;

 

  //Compute cost for dell mouse

  cost_d_mouse=DELL_MOUSE*d_mouse;

 

  //Compute cost for dell keyboard

  costDell_key=DELL_KEYB*d_keyboards;

 

  //Compute cost for windows OS

  costWindOs=WIND_OS*wind_OS;

 

  //Compute cost for printer

  costPrinter=PRINTER*printer;

 

  //Compute cost for sub total

  subtotal=costEMonitor+costDell_key+cost_d_mouse+costPrinter+costWindOs;

 

  //Print the output

  cout<<endl;

  cout<<left<<fixed<<"QTY"<<"\t\tDescription"<<"\t\t\tUnit Price"<<"\t\tTotal Price"<<endl;

 

  cout<<left<<fixed<<setw(7)<<extMonitor<<setw(21)<<" EXTERNAL MONITOR "<<setw(15)<<EXT_MONITOR<<" "<<setw(10)<<costEMonitor<<endl;

 

  cout<<left<<fixed<<setw(7)<<d_keyboards<<setw(21)<<" DELL KEYBOARD "<<setw(15)<<DELL_KEYB<< " "<<setw(10)<<costDell_key<<endl;

 

  cout<<left<<fixed<<setw(7)<<d_mouse<<setw(21)<<" DELL MOUSE "<<setw(15)<<DELL_MOUSE<< " "<<setw(10)<<cost_d_mouse<<endl;

 

  cout<<left<<fixed<<setw(7)<<wind_OS<<setw(21)<<" WINDOWS OS "<<setw(15)<<WIND_OS<< " "<<setw(10)<<costWindOs<<endl;

 

  cout<<left<<fixed<<setw(7)<<printer<<setw(21)<<" NETWORK PRINTER "<<setw(15)<<PRINTER<< " "<<setw(10)<<costPrinter<<endl;

 

  cout<<left<<fixed<<setw(7)<<"\nSUBTOTAL "<<setw(21)<<subtotal<<endl;

 

  //Compute tax

  tax=subtotal*taxRate;

 

  //Compute total

  total=subtotal+tax;

  cout<<left<<fixed<<setw(9)<<"TAX "<<setw(25)<<tax<<endl;

  cout<<left<<fixed<<setw(9)<<"TOTAL "<<setw(25)<<total<<endl;

 

return 0;

}

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education