Code must be in C++ language. Problem: The invoice-printing program has an unfor
ID: 3720920 • Letter: C
Question
Code must be in C++ language.
Problem: The invoice-printing program has an unfortunate flaw-- it mixes "application logic", the computation of total charges, and "presentation", the visual appearance of the invoice. HYPOTHETICAL: To appreciate this flaw, imagine the changes that would be necessary to draw the invoice in HTML, for presentation on the Web. Reimplement the program, using a separate 'InvoiceFormatter' class to format the invoice. That is, the 'Invoice', 'Address', Lineltem' and 'Product classes are no longer responsible for formatting. However, they will acquire other responsibilities, because the InvoiceFormatter class needs to query them for the values that it required. It is strongly recommended that your draw a small UML for each class, and plan how it will work.Explanation / Answer
A)
#include<iostream>
using namespace std;
double getUnitprice(int itemCode);
int main()
{
double invoice[6][4];
int i=0; char more; char date[100]; char address[100]; int name;
cout<< " Widget II 100 InvalidCode 0 ";
cout<< "Please enter the date: "<<endl;
cin>> date;
cout<<"Please enter your address: "<<endl;
cin>> address;
do {
cout << " Item code: ";
cin >> invoice[i][0];
cout << "Quantity : ";
cin >> invoice[i][1];
invoice[i][2] = getUnitprice(invoice[i][0]);
invoice[i][3] = invoice[i][1] * invoice[i][2];
cout << "Do you have any other items to be entered next (y/n) ? ";
cin >> more;
i++;
} while(more == 'y');
cout << " ----------------------------- ";
cout << "Date : " << date << " ";
cout << "Address : " <<address<< " ";
cout << "ItemCode|Quantity|UnitPrice|TotalPrice ";
int tot=0;
for(int k=0; k<i; k++)
{
for(int l=0; l<6; l++)
{
cout << invoice[k][l] << " ";
}
cout << endl;
tot = tot + invoice[k][6];
}
cout << " Your Total Amount : " << tot;
cout << " ----------------------------- ";
return 0;
}
double getUnitprice(int itemCode){
double price;
switch (itemCode)
{
case 1: price = 150;
break;
case 2: price = 75;
break;
case 3: price = 100;
break;
default: price = 0;
break;
}
return price;
}