Advertisement
Hadsadas

c++ assignment

Dec 12th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.63 KB | None | 0 0
  1. //These are called libraries that define a certain thing within the program that each do different things.
  2. #include <iostream>
  3. #include <string>
  4. #include <stdlib.h>
  5. #include <iomanip>
  6. //This removes the STD:: in c++ so it is easier to code.
  7. using namespace std;
  8.  
  9. //Base account class that I made called BaseAccount
  10. class BaseAccount {
  11. //Protected makes them not be able to identify outside the class
  12. protected:
  13.     //Int stores integers,such as whole numbers
  14.     int freeData;
  15.     int freeCalls;
  16.     int freeTexts;
  17.     int freeMins;
  18.  
  19.     //Bool is short for boolean which can store values with either true or false
  20.     bool freeNum;
  21.     bool pinkTether;
  22.  
  23.     int userData;
  24.     int userCalls;
  25.     int userTexts;
  26.     int userMins;
  27.  
  28.     const float dataCost = 3.19;
  29.     const float callCost = 1.99;
  30.     const float textCost = 0.99;
  31.     const float minsCost = 0.20;
  32.  
  33.     //Stores whole numbers with decimals
  34.     double monthlyCostVAT;
  35.     double monthlyCost;
  36.     double dataTotal;
  37.     double callTotal;
  38.     double textTotal;
  39.     double minsTotal;
  40.  
  41. //Anything under public can be accessed by anybody
  42. public:
  43.     //Void lets me set any piece of work into the application at any time that I can later use
  44.     void setFreeData(int fData) {
  45.         freeData = fData;
  46.     }
  47.  
  48.     void setFreeCalls(int fCalls) {
  49.         freeCalls = fCalls;
  50.     }
  51.  
  52.     void setFreeTexts(int fTexts) {
  53.         freeTexts = fTexts;
  54.     }
  55.  
  56.     void setFreeMins(int fMins) {
  57.         freeMins = fMins;
  58.     }
  59.  
  60.     void setFreeNum(bool fNum) {
  61.         freeNum = fNum;
  62.     }
  63.  
  64.     void setPinkTether(bool pTether) {
  65.         pinkTether = pTether;
  66.     }
  67.  
  68.     void setMonthlyCost(double mCost) {
  69.         monthlyCost = mCost;
  70.     }
  71.  
  72.     void setUserCalls(double uCalls) {
  73.         userCalls = uCalls;
  74.     }
  75.  
  76.     void setUserData(double uData) {
  77.         userData = uData;
  78.     }
  79.  
  80.     void setUserTexts(double uTexts) {
  81.         userTexts = uTexts;
  82.     }
  83.  
  84.     //These are all my calculations for all the data, calls, texts and minutes they are using
  85.     double calcDataCost() {
  86.         if (userData > freeData) {
  87.             dataTotal = (userData - freeData) * dataCost;
  88.         }
  89.         else {
  90.             dataTotal = 0;
  91.         }
  92.         return dataTotal;
  93.     }
  94.  
  95.     double calcCallCost() {
  96.         if (userCalls > freeCalls) {
  97.             callTotal = (userCalls - freeCalls) * callCost;
  98.         }
  99.         else {
  100.             callTotal = 0;
  101.         }
  102.         return callTotal;
  103.     }
  104.  
  105.     double calcTextCost() {
  106.         if (userTexts > freeTexts) {
  107.             textTotal = (userTexts - freeTexts) * textCost;
  108.         }
  109.         else {
  110.             textTotal = 0;
  111.         }
  112.         return textTotal;
  113.     }
  114.  
  115.     double calcMinCost() {
  116.         if (userMins > freeMins) {
  117.             minsTotal = (userMins - freeMins) * minsCost;
  118.         }
  119.         else {
  120.             minsTotal = 0;
  121.         }
  122.         return minsTotal;
  123.     }
  124.  
  125.    
  126.     //These are the true or false booleans that are getting so I can declare it later on when calling the booleans
  127.     bool getFreeNum() {
  128.         return freeNum;
  129.     }
  130.  
  131.     bool getPinkTether() {
  132.         return pinkTether;
  133.     }
  134.  
  135.     double getMonthlyCost() {
  136.         return monthlyCost;
  137.     }
  138.  
  139.     //This is the basic input of the MonthlyCostVAT that I need for the VAT to work and calculate correcly
  140.     double getMonthlyCostVAT() {
  141.         calcDataCost();
  142.         calcCallCost();
  143.         calcTextCost();
  144.         calcMinCost();
  145.         return (dataCost + minsCost + callCost + textCost + monthlyCost) * 20;
  146.     }
  147. };
  148.  
  149. //This is my pinkLight class that I made with the BaseAccount implementation at the top
  150. class Light : public BaseAccount {
  151. public:
  152.     Light() {
  153.         setFreeData(500);
  154.         setFreeCalls(1000);
  155.         setFreeTexts(300);
  156.         setMonthlyCost(14.99);
  157.         setPinkTether(false);
  158.         setFreeNum(false);
  159.     }
  160. };
  161.  
  162. //This is my pinkData class that I made with the BaseAccount implementation at the top
  163. class Data : public BaseAccount {
  164. public:
  165.     Data() {
  166.         setFreeData(5000);
  167.         setFreeCalls(10000);
  168.         setFreeTexts(500);
  169.         setMonthlyCost(24.99);
  170.         setPinkTether(true);
  171.         setFreeNum(false);
  172.     }
  173. };
  174.  
  175. //This is my pinkFreedom class that I made with the BaseAccount implementation at the top
  176. class Freedom : public BaseAccount {
  177. public:
  178.     Freedom() {
  179.         setFreeData(20000);
  180.         setFreeTexts(1000);
  181.         setMonthlyCost(34.99);
  182.         setPinkTether(true);
  183.         setFreeNum(true);
  184.     }
  185. };
  186.  
  187. bool exitProg = false;
  188. int menu1Option;
  189. char userName[20];
  190. int packageType;
  191. int dataAmount;
  192. int callAmount;
  193. int textAmount;
  194. int minsAmount;
  195.  
  196. string menu2[5] = {
  197.     "Please Enter Your Name.",
  198.     "Please Choose Your Package Type.",
  199.     "1 - Light",
  200.     "2 - Data",
  201.     "3 - Freedom" };
  202.  
  203.  
  204. Light lAccount;
  205. Data dAccount;
  206. Freedom fAccount;
  207.  
  208. //Main is the basic function that will get caught inside the exitProg boolean that creates the GUI for people to use
  209. int main() {
  210.     while (!exitProg) {
  211.         //This is the menu and options so that someone can input a number and it will navigate them through the application.
  212.         cout << "Please Choose An Option:" << endl;
  213.         cout << "0 - Exit" << endl;
  214.         cout << "1 - Enter User Details And Choose Account Type" << endl;
  215.         cout << "2 - Enter Usage Details" << endl;
  216.         cout << "3 - Display Bill" << endl;
  217.         cout << "4 - Display Package Information" << endl;
  218.         cin >> menu1Option;
  219.         //system,cls will clear the input when the program runs through it
  220.         system("CLS");
  221.         //Basic if statement that prompts the user to exit the program with "Y" or "N"
  222.         if (menu1Option == 0) {
  223.             char choice;
  224.             cout << "Are you sure you want to exit the program? Type 'Y' or 'N'" << endl;
  225.             cin >> choice;
  226.             //If they have chosen Y then the program will exit but if they chose N it will then exit
  227.             if (choice == 'Y' || choice == 'y') {
  228.                 exitProg = true;
  229.             }
  230.             else {
  231.                 exitProg = false;
  232.                 system("CLS");
  233.             }
  234.         }
  235.         if (menu1Option == 1) {
  236.             cout << menu2[0] << endl;
  237.             cin.ignore();
  238.             cin.getline(userName, 20);
  239.             system("CLS");
  240.             cout << menu2[1] << endl;
  241.             cout << menu2[2] << endl;
  242.             cout << menu2[3] << endl;
  243.             cout << menu2[4] << endl;
  244.             cin >> packageType;
  245.             system("CLS");
  246.             if (packageType == 1) {
  247.                 cout << "You've Chosen Light As An Account Type." << endl;
  248.     //system,pause will pause the program and display a msg saying press any button to continue which continues them onto the next page
  249.                 system("PAUSE");
  250.                 system("CLS");
  251.             }
  252.             if (packageType == 2) {
  253.                 cout << "You've Chosen Data As An Account Type." << endl;
  254.                 system("PAUSE");
  255.                 system("CLS");
  256.             }
  257.             if (packageType == 3) {
  258.                 cout << "You've Chosen Freedom As An Account Type." << endl;
  259.                 system("PAUSE");
  260.                 system("CLS");
  261.             }
  262.         }
  263.         //Error checking that will display if they haven't chosen a package type and will return them to the main menu
  264.         if (menu1Option == 2) {
  265.             if (packageType == NULL) {
  266.                 cout << "Make Sure You Have Chosen An Account Type." << endl;
  267.                 system("PAUSE");
  268.                 system("CLS");
  269.             }
  270.             else {
  271.                 cout << "Enter Amount Of Data: ";
  272.                 cin >> dataAmount;
  273.                 cout << "Enter Amount Of Calls: ";
  274.                 cin >> callAmount;
  275.                 cout << "Enter Amount Of Texts: ";
  276.                 cin >> textAmount;
  277.                 cout << "Enter Amount Of Minutes: ";
  278.                 cin >> minsAmount;
  279.                 if (packageType == 1) {
  280.                     lAccount.setUserData(dataAmount);
  281.                     lAccount.setUserCalls(callAmount);
  282.                     lAccount.setUserData(textAmount);
  283.                     lAccount.setUserCalls(minsAmount);
  284.                 }
  285.                 if (packageType == 2) {
  286.                     dAccount.setUserData(dataAmount);
  287.                     dAccount.setUserCalls(callAmount);
  288.                     dAccount.setUserData(textAmount);
  289.                     dAccount.setUserCalls(minsAmount);
  290.                 }
  291.                 if (packageType == 3) {
  292.                     fAccount.setUserData(dataAmount);
  293.                     fAccount.setUserCalls(callAmount);
  294.                     fAccount.setUserData(textAmount);
  295.                     fAccount.setUserCalls(minsAmount);
  296.                 }
  297.                 cout << "Your Info Has Been Stored" << endl;
  298.                 system("PAUSE");
  299.                 system("CLS");
  300.             }
  301.         }
  302.  
  303.         //Error checking that will display if they haven't chosen a package type and will return them to the main menu
  304.         if (menu1Option == 3) {
  305.             if (packageType == NULL) {
  306.                 cout << "Make Sure You Have Chosen An Account Type." << endl;
  307.                 system("PAUSE");
  308.                 system("CLS");
  309.             }
  310.             else {
  311.                 //Displays their billing total with and without vat
  312.                 cout << "Your Billing Total is: " << endl;
  313.                 if (packageType == 1) {
  314.                     cout << "Without VAT it comes up to:  " << "\x9c" << lAccount.getMonthlyCost() << endl;
  315.                     cout << "With VAT it comes up to:  " << "\x9c" << fixed << setprecision(2) << lAccount.getMonthlyCostVAT() << endl;
  316.                 }
  317.                 if (packageType == 2) {
  318.                     cout << "Without VAT it comes up to:  " << "\x9c" << dAccount.getMonthlyCost() << endl;
  319.                     cout << "With VAT it comes up to:  " << "\x9c" << fixed << setprecision(2) <<  dAccount.getMonthlyCostVAT() << endl;
  320.                 }
  321.                 if (packageType == 3) {
  322.                     cout << "Without VAT it comes up to:  " << "\x9c" << fAccount.getMonthlyCost() << endl;
  323.                     cout << "With VAT it comes up to:  " << "\x9c" << fixed << setprecision(2) << fAccount.getMonthlyCostVAT() << endl;
  324.                 }
  325.                 system("PAUSE");
  326.                 system("CLS");
  327.             }
  328.         }
  329.  
  330.         //Error checking that will display if they haven't chosen a package type and will return them to the main menu
  331.         if (menu1Option == 4) {
  332.             if (packageType == NULL) {
  333.                 cout << "Make Sure You Have Chosen An Account Type." << endl;
  334.                 system("PAUSE");
  335.                 system("CLS");
  336.             }
  337.             else {
  338.                 //This shall display the basic information about the package type they chose and the boolean
  339.                 if (packageType == 1) {
  340.                     cout << "PINK LIGHT PACKAGE INFORMATION" << endl;
  341.                     cout << "With Pink Light, you are allowed to have 500MB of data free, 300 texts and 1000 minutes of free calls." << endl;
  342.                     //These are the booleans that I displayed to say if they are allowed to have pink tether or call 080 numbers for free
  343.                     //Boolalpha is making the boolean display true or false instead of 1 or 0
  344.                     cout << "This is the output whether you are allowed pink tether" << "  >>  " << boolalpha << false << "  <<  " << endl;
  345.                     cout << "This is the output whether you are allowed free 080 numbers" << "  >>  " << boolalpha << false << "  <<  " << endl;
  346.                 }
  347.                 if (packageType == 2) {
  348.                     cout << "PINK DATA PACKAGE INFORMATION" << endl;
  349.                     cout << "With Pink Data, you are allowed to have 5GB of data free, 500 texts and unlimited calls." << endl;
  350.                     cout << "This is the output whether you are allowed pink tether" << "  >>  " << boolalpha << true << "  <<  " << endl;
  351.                     cout << "This is the output whether you are allowed free 080 numbers" << "  >>  " << boolalpha << false << " <<  " << endl;
  352.                 }
  353.                 if (packageType == 3) {
  354.                     cout << "PINK FREEDOM PACKAGE INFORMATION" << endl;
  355.                     cout << "With Pink Freedom, you are allowed to have 20GB of data free, 1000 texts and unlimited calls." << endl;
  356.                     cout << "This is the output whether you are allowed pink tether" << "  >>  " << boolalpha <<  true << "  <<  " << endl;
  357.                     cout << "This is the output whether you are allowed free 080 numbers" << "  >>  " << boolalpha << true << "  <<  " << endl;
  358.                 }
  359.                 system("PAUSE");
  360.                 system("CLS");
  361.             }
  362.         }
  363.     }
  364.     return 0;
  365. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement