Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- struct Items{
- string name;
- float unit_price, total;
- int quantity;
- };
- void setZero(Items *X, int ni);
- void readData(Items *X, int ni);
- void Calculate_Bill(Items *X, int ni, float &total);
- void Show_Bill(Items *X, int ni, float &total);
- int main(){
- int i, ni;
- float total = 0.00;
- cout << "Number of Items: ";
- cin >> ni;
- Items It[ni];
- setZero(&It[0], ni);
- readData(&It[0], ni);
- Calculate_Bill(&It[0], ni, total);
- Show_Bill(&It[0], ni, total);
- return 0;
- }
- void setZero(Items *X, int ni){
- for(int i = 0; i < ni; i++){
- X[i].name = "N/A";
- X[i].unit_price = 0.00;
- X[i].total = 0.00;
- X[i].quantity = 0;
- }
- }
- void readData(Items *X, int ni){
- for(int i = 0; i < ni; i++){
- cout << "Enter NAME, UNIT PRICE and QUANTITY for Item " << i + 1 << ": ";
- cin >> X[i].name >> X[i].unit_price >> X[i].quantity;
- X[i].total += X[i].unit_price * X[i].quantity;
- if(X[i].name == "N/A" && X[i].unit_price == 0 && X[i].quantity == 0) return;
- }
- return;
- }
- void Calculate_Bill(Items *X, int ni, float &total){
- for(int i = 0; i < ni && X[i].name != "N/A"; i++)
- total += X[i].total;
- }
- void Show_Bill(Items *X, int ni, float &total){
- cout.setf (ios :: fixed);
- cout << left << setw(4) << "No." << left << setw(17) << "ITEM NAME" << right << setw(10) << "UNIT PRICE" << right << setw(10) << "QUANTITY" << right << setw(12) << "TOTAL" << endl;
- for(int i = 0; i < ni && X[i].name != "N/A"; i++){
- cout << left << setw(4) << i + 1 << left << setw(17) << X[i].name << right << setw(10) << setprecision(2) << X[i].unit_price << right << setw(10) << X[i].quantity << right << setw(12) << setprecision(2) << X[i].total << endl;
- total += X[i].total;
- }
- if(total > 1000){
- for(int i = 0; i < 53; i++)
- cout << "-";
- cout << endl;
- cout << left << setw(25) << "TOTAL" << right << setw(28) << total << endl;
- cout << left << setw(25) << "+10% Service Charge: " << right << setw(28) << total / 10 << endl;
- total += total / 10;
- }
- for(int i = 0; i < 53; i++)
- cout << "-";
- cout << endl;
- for(int i = 0; i < 53; i++)
- cout << "-";
- cout << endl;
- cout << left << setw(25) << "GRAND TOTAL" << right << setw(28) << total << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement