#include <iostream> #include <iomanip> using namespace std; double calculate(int
ID: 3541689 • Letter: #
Question
#include <iostream>
#include <iomanip>
using namespace std;
double calculate(int, double);
int main()
{
int product, quantity,error;
double total = 0.0,price;
cout << "Enter pairs of item numbers and quantities."
<< " Enter -1 for the item number to end input: ";
cin >> product;
while ( product != -1 ) {
error=0;
cin >> quantity;
switch ( product ) {
case 1:
price= 2.98;
break;
case 2:
price= 4.50;
break;
case 3:
price= 9.98;
break;
case 4:
price= 4.49;
break;
case 5:
price= 6.87;
break;
default:
cout << "Invalid product code: " << product
<< " Quantity: " << quantity << ' ';
error=1;
break;
}
if(error==0)
{price=calculate(quantity,price);
cout<<"price = $"<<setprecision(2)<<fixed<<price<<endl;
total+=price;
}
cout << "Enter pairs of item numbers and quantities. "
<< "Enter -1 for the item number to end input: ";
cin >> product;
}
cout << setiosflags( ios::fixed | ios::showpoint )
<< "The total retail value was: $" << setprecision( 2 )
<< total << endl;
return 0;
}
double calculate(int q,double p)
{return p*q;
}
this is what i have so far.
but i need three seperate files for it now.
1) company.h
2) company.cpp
3)lab3.cpp
Explanation / Answer
company.h : https://www.dropbox.com/s/h3weyiyltfp76ew/company.h
company.cpp: https://www.dropbox.com/s/o73mglh3aq8paat/company.cpp
lab3.cpp: https://www.dropbox.com/s/0y2d4g6tufdye6v/lab3.cpp
To compile use : g++ lab3.cpp company.cpp -o lab3
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.