amlxv

astro

Dec 10th, 2019 (edited)
9,024
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6. void userInformation(string&, char&, char&);
  7. void charge(char, char, double&, double&);
  8. void receipt(string, char, char, double, double);
  9.  
  10. int main(){
  11.  
  12.     bool stop = false;
  13.     string smartCard;
  14.     char packageCode, additionalTV, stopResult;
  15.     double totalBeforeTax, totalWithTax, totalFamilyPack = 0.0, totalFamilyHDPack = 0.0;
  16.  
  17.     while(stop != true){
  18.     userInformation(smartCard, packageCode, additionalTV);
  19.     charge(packageCode, additionalTV, totalBeforeTax, totalWithTax);
  20.     receipt(smartCard, packageCode, additionalTV, totalBeforeTax, totalWithTax);
  21.     if(packageCode == 'A' || packageCode == 'a')
  22.         totalFamilyPack += totalWithTax;
  23.     if(packageCode == 'B' || packageCode == 'b')
  24.         totalFamilyHDPack += totalWithTax;
  25.     cout << "\nEnter N to stop or another key to continue : ";
  26.     cin >> stopResult;
  27.     cout << endl;
  28.     if(stopResult == 'N' || stopResult == 'n')
  29.         stop = true;
  30.     else
  31.         stop = false;
  32.     }
  33.     cout << "----------------------------------------------------------------\n";
  34.     cout << "Total Package Collection\n";
  35.     cout << "Astro Family Pack (RM)      : " << totalFamilyPack ;
  36.     cout << "\nAstro Family HD Pack (RM)   : " << totalFamilyHDPack;
  37.     cout << "\n----------------------------------------------------------------\n";
  38. }
  39.  void userInformation(string &smartCard, char &packageCode, char &additionalTV){
  40.  
  41.     cout << "Enter your smart card number : " ;
  42.     cin >> smartCard;
  43.     cout << "Enter package code : ";
  44.     cin >> packageCode;
  45.     if(packageCode != 'A' && packageCode != 'B'){
  46.         cout << "You have entered invalid package code";
  47.     } else {
  48.         cout << "Enter additional TV series code : ";
  49.         cin >> additionalTV;
  50.     }
  51. }
  52. void charge(char packageCode, char additionalTV, double &totalBeforeTax, double &totalWithTax){
  53.  
  54.     float packagePrice, additionalPrice = 0;
  55.     if(packageCode == 'A' || packageCode == 'a'){
  56.         packagePrice = 130.00;
  57.         if(additionalTV == 'F' || additionalTV == 'f')
  58.             additionalPrice = 25.00;
  59.         else if(additionalTV == 'L' || additionalTV == 'l')
  60.             additionalPrice = 20.00;
  61.             else
  62.                 additionalPrice = 0;
  63.     } else {
  64.         packagePrice = 125.00;
  65.         if(additionalTV == 'S' || additionalTV == 's')
  66.             additionalPrice = 35.00;
  67.         else
  68.             additionalPrice = 0;
  69.     }
  70.     totalBeforeTax = packagePrice + additionalPrice;
  71.     totalWithTax = totalBeforeTax + (totalBeforeTax * 0.06);
  72. }
  73. void receipt(string smartCard, char packageCode, char additionalTV, double totalBeforeTax, double totalWithTax){
  74.  
  75.     string packageName;
  76.  
  77.     if(packageCode == 'A' || packageCode == 'a')
  78.         packageName = "Astro Family Pack";
  79.     else if(packageCode == 'B' || packageCode == 'b')
  80.         packageName = "Astro Family HD Pack";
  81.  
  82.     cout.setf(ios::fixed);
  83.     cout.precision(2);
  84.     cout << "----------------------------------------------------------------\n";
  85.     cout << "ASTRO BILLING SERVICE\n";
  86.     cout << "Smart Card No.                          : " << smartCard      << endl;
  87.     cout << "Package Name                            : " << packageName    << endl;
  88.     cout << "Additional TV Series                    : " << additionalTV   << endl;
  89.     cout << "Total Charge (RM)                       : " << totalBeforeTax << endl;
  90.     cout << "New charge after 6% govt. tax (RM)      : " << totalWithTax   << endl;
  91.  
  92. }
Add Comment
Please, Sign In to add comment