Advertisement
skb50bd

Mid I-2: Iftaar Items

Jun 24th, 2015
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. struct Items{
  8.     string name;
  9.     float unit_price, total;
  10.     int quantity;
  11. };
  12.  
  13. void setZero(Items *X, int ni);
  14. void readData(Items *X, int ni);
  15. void Calculate_Bill(Items *X, int ni, float &total);
  16. void Show_Bill(Items *X, int ni, float &total);
  17.  
  18. int main(){
  19.  
  20.     int i, ni;
  21.  
  22.     float total = 0.00;
  23.  
  24.     cout << "Number of Items: ";
  25.     cin >> ni;
  26.  
  27.     Items It[ni];
  28.  
  29.     setZero(&It[0], ni);
  30.     readData(&It[0], ni);
  31.     Calculate_Bill(&It[0], ni, total);
  32.     Show_Bill(&It[0], ni, total);
  33.  
  34.     return 0;
  35. }
  36.  
  37.  
  38.  
  39. void setZero(Items *X, int ni){
  40.     for(int i = 0; i < ni; i++){
  41.         X[i].name = "N/A";
  42.         X[i].unit_price = 0.00;
  43.         X[i].total = 0.00;
  44.         X[i].quantity = 0;
  45.     }
  46. }
  47.  
  48.  
  49. void readData(Items *X, int ni){
  50.     for(int i = 0; i < ni; i++){
  51.         cout << "Enter NAME, UNIT PRICE and QUANTITY for Item " << i + 1 << ": ";
  52.         cin >> X[i].name >> X[i].unit_price >> X[i].quantity;
  53.         X[i].total += X[i].unit_price * X[i].quantity;
  54.         if(X[i].name == "N/A" && X[i].unit_price == 0 && X[i].quantity == 0) return;
  55.     }
  56.     return;
  57. }
  58.  
  59.  
  60. void Calculate_Bill(Items *X, int ni, float &total){
  61.     for(int i = 0; i < ni && X[i].name != "N/A"; i++)
  62.         total += X[i].total;
  63. }
  64.  
  65.  
  66. void Show_Bill(Items *X, int ni, float &total){
  67.     cout.setf (ios :: fixed);
  68.  
  69.     cout << left << setw(4) << "No." << left << setw(17) << "ITEM NAME" << right << setw(10) << "UNIT PRICE" << right << setw(10) << "QUANTITY" << right << setw(12) << "TOTAL" << endl;
  70.     for(int i = 0; i < ni && X[i].name != "N/A"; i++){
  71.         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;
  72.         total += X[i].total;
  73.     }
  74.     if(total > 1000){
  75.         for(int i = 0; i < 53; i++)
  76.             cout << "-";
  77.         cout << endl;
  78.         cout << left << setw(25) << "TOTAL" << right << setw(28) << total << endl;
  79.         cout << left << setw(25) << "+10% Service Charge: " << right << setw(28) << total / 10 << endl;
  80.         total += total / 10;
  81.     }
  82.  
  83.     for(int i = 0; i < 53; i++)
  84.         cout << "-";
  85.     cout << endl;
  86.         for(int i = 0; i < 53; i++)
  87.         cout << "-";
  88.     cout << endl;
  89.     cout << left << setw(25) << "GRAND TOTAL" << right << setw(28) << total << endl;
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement