Advertisement
Caeg

Untitled

May 5th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iomanip>
  3. #include <cstdlib>
  4. #include <iostream>
  5. #include <string>
  6. #include <vector>
  7. #include <algorithm>
  8. #include <cstdlib>
  9. #include <ctime>
  10. #include <cctype>
  11. #include <fstream>
  12.  
  13. # define AIRLINES_M
  14.  
  15. using namespace std;
  16. const double TAX = 0.1;
  17.  
  18. class Airline
  19. {
  20. private:
  21. string tickettype;
  22. double ticketprice;
  23. int ticketquantity;
  24.  
  25. public:
  26. Airline(string, double, int);
  27.  
  28. void setticketquantity(int);
  29. string gettickettype() const;
  30. int getticketquantity() const;
  31. double getticketprice() const;
  32. double getTicketSubtotal() const;
  33. double gettax() const;
  34. double subtotal;
  35. };
  36.  
  37. int main()
  38. {
  39. string strOpt;
  40. int iTemp;
  41. static int iCounter = 0;
  42. ofstream outputfile;
  43.  
  44. const int SIZE = 3;
  45.  
  46. Airline airlines[SIZE] = { Airline("Standard", 250.0, 0), Airline("Economy", 350.0, 0), Airline("Standard", 450.0, 0) };
  47.  
  48. const char Standard = 'A', Economy = 'B', Business = 'C', Quit = 'D';
  49.  
  50.  
  51. do {
  52. cout << "\tAirlines Ticket Menu\n";
  53. cout << "A. Standard Ticket" << "\t$250.00 each\n";
  54. cout << "B. Economy Ticket" << "\t$350.00 each\n";
  55. cout << "C. Business Ticket" << "\t$450.00 each\n";
  56. cout << "D. Quit the menu";
  57.  
  58. cout << "\nPlease enter your choice of A, B, C, or D: ";
  59. getline(cin, strOpt);
  60.  
  61. switch (toupper(strOpt[0]))
  62. {
  63. case Standard:
  64. cout << "\nHow many tickets would you like to purchase? ";
  65. cin >> iTemp;
  66.  
  67. airlines[0].setticketquantity(iTemp);
  68.  
  69. cout << airlines[0].gettickettype() << ": $" << airlines[0].getticketprice() << " Each" << "\tTicket: ";
  70. cout << iTemp << "\tCharge: $" << setw(7) << airlines[0].getticketprice() * iTemp;
  71. cout << "\tTax: $" << setw(7) << airlines[0].getticketprice() * iTemp * TAX << endl;
  72.  
  73. outputfile << airlines[0].getTicketSubtotal();
  74. iCounter++;
  75.  
  76. break;
  77.  
  78. default:
  79. cout << "The valid menu choices are from A through D only. \n";
  80.  
  81. }
  82.  
  83. for (int i = 0; i < 3; i++)
  84. {
  85. cout << "Total " << airlines[i].gettickettype() << "\t" << "Ticket: " << airlines[i].getticketquantity();
  86. cout << "\tCharge: $" << setw(7) << airlines[i].getTicketSubtotal() << "\tTax: $" << setw(7) << airlines[i].gettax();
  87. }
  88.  
  89. double subtotal = 0;
  90. for (int i = 0; i < 3; i++)
  91. subtotal += airlines[i].getTicketSubtotal();
  92. cout << "\nSub Total: \t" << setw(15) << subtotal << endl;
  93. cout << "Tax: \t\t" << setw(15) << subtotal * TAX;
  94. cout << endl << "\nTotal charges: \t" << setw(15) << (i + TAX) * subtotal << endl << endl;
  95. } while (toupper(strOpt[0] != Quit));
  96.  
  97. outputfile.close();
  98.  
  99. cout << endl << "Enjoy your flight! \n";
  100. cout << "See you next time. \n";
  101. cout << "\nIf you are a custmoer, you can exit this program now.\n";
  102. cout << "Please enter 'Y/y' for yes or 'N/n' if you would like to continue: ";
  103. getline(cin, strOpt);
  104.  
  105. if (toupper(strOpt[0]) == 'Y')
  106. {
  107. cout << "\nThank you for the business! \n";
  108. cout << "Please press the enter key to exit.";
  109. cin.get();
  110. return 0;
  111. }
  112. else
  113. cout << "\nPlease continue this program. \n";
  114.  
  115.  
  116.  
  117. return 0;
  118. }
  119.  
  120.  
  121. int binaryseach(int iArray[], int iSize, int iMin, int iMax, int iValue)
  122. {
  123. if (iMax < iMin)
  124. return -1;
  125. else
  126. {
  127. int iMid = (iMin + iMax) / 2;
  128. if (iArray[iMid] > iValue)
  129. return binaryseach(iArray, iSize, iMid, iMid - 1, iValue);
  130. else if (iArray[iMid] < iValue)
  131. return binaryseach(iArray, iSize, iMid + 1, iMax, iValue);
  132. else
  133. return iMid;
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140. }
  141.  
  142.  
  143. Airline::Airline(string type, double price, int quantity)
  144. {
  145. tickettype = type;
  146. ticketprice = price;
  147. ticketquantity = quantity;
  148.  
  149. }
  150.  
  151. void Airline::setticketquantity(int quantity)
  152. {
  153. ticketquantity += quantity;
  154. }
  155.  
  156. int Airline::getticketquantity() const
  157. {
  158. return ticketquantity;
  159. }
  160.  
  161. double Airline::getticketprice() const
  162. {
  163. return ticketprice;
  164. }
  165.  
  166. string Airline::gettickettype() const
  167. {
  168. return tickettype;
  169. }
  170.  
  171. double Airline::getTicketSubtotal() const
  172. {
  173. return ticketprice * ticketquantity;
  174. }
  175.  
  176. double Airline::gettax() const
  177. {
  178. return getTicketSubtotal() * TAX;
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement