Caeg

Untitled

May 5th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 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.  
  17. void selectionSort(int *, int);
  18. int binarysearch(int[], int, int, int, int);
  19.  
  20. const double TAX = 0.1;
  21.  
  22. class Airline
  23. {
  24. private:
  25. string tickettype;
  26. double ticketprice;
  27. int ticketquantity;
  28.  
  29. public:
  30. Airline(string, double, int);
  31.  
  32.  
  33. void setticketquantity(int);
  34. string gettickettype() const;
  35. int getticketquantity() const;
  36. double getticketprice() const;
  37. double getTicketSubtotal() const;
  38. double gettax() const;
  39. double subtotal;
  40. };
  41.  
  42. int main()
  43. {
  44.  
  45. const int SIZE = 3;
  46.  
  47. Airline airlines[SIZE] = { Airline("Standard", 250.0, 0), Airline("Economy", 350.0, 0), Airline("Business", 450.0, 0) };
  48.  
  49. const char Standard = 'A', Economy = 'B', Business = 'C', Quit = 'D';
  50.  
  51. string strOpt;
  52. string sTemp;
  53. int iTemp;
  54. static int iCounter = 0;
  55. ofstream outputfile;
  56. outputfile.open("ticketCharge.txt");
  57. ifstream inputfile;
  58.  
  59.  
  60. do
  61. {
  62. cout << "\tAirlines Ticket Menu\n";
  63. cout << "A. Standard Ticket" << "\t$250.00 each\n";
  64. cout << "B. Economy Ticket" << "\t$350.00 each\n";
  65. cout << "C. Business Ticket" << "\t$450.00 each\n";
  66. cout << "D. Quit the menu";
  67. cout << "\nPlease enter your choice of A, B, C, or D: ";
  68. getline(cin, strOpt);
  69.  
  70.  
  71.  
  72. switch (toupper(strOpt[0]))
  73. {
  74. case Standard:
  75. cout << "\nHow many tickets would you like to purchase? ";
  76. cin >> iTemp;
  77.  
  78. airlines[0].setticketquantity(iTemp);
  79.  
  80. cout << airlines[0].gettickettype() << ": $" << airlines[0].getticketprice() << " Each" << "\tTicket: ";
  81. cout << iTemp << "\tCharge: $" << setw(7) << airlines[0].getticketprice() * iTemp;
  82. cout << "\tTax: $" << setw(7) << airlines[0].getticketprice() * iTemp * TAX << endl;
  83.  
  84. outputfile << airlines[0].getTicketSubtotal();
  85. iCounter++;
  86.  
  87. break;
  88.  
  89. case Economy:
  90. cout << "\nHow many tickets would you like to purchase? ";
  91. cin >> iTemp;
  92.  
  93. airlines[0].setticketquantity(iTemp);
  94.  
  95. cout << airlines[1].gettickettype() << ": $" << airlines[1].getticketprice() << " Each" << "\tTicket: ";
  96. cout << iTemp << "\tCharge: $" << setw(7) << airlines[1].getticketprice() * iTemp;
  97. cout << "\tTax: $" << setw(7) << airlines[1].getticketprice() * iTemp * TAX << endl;
  98.  
  99. outputfile << airlines[1].getTicketSubtotal();
  100. iCounter++;
  101. break;
  102.  
  103. case Business:
  104. cout << "\nHow many tickets would you like to purchase? ";
  105. cin >> iTemp;
  106.  
  107. airlines[2].setticketquantity(iTemp);
  108.  
  109. cout << airlines[2].gettickettype() << ": $" << airlines[2].getticketprice() << " Each" << "\tTicket: ";
  110. cout << iTemp << "\tCharge: $" << setw(7) << airlines[2].getticketprice() * iTemp;
  111. cout << "\tTax: $" << setw(7) << airlines[2].getticketprice() * iTemp * TAX << endl;
  112.  
  113. outputfile << airlines[2].getTicketSubtotal();
  114. iCounter++;
  115. break;
  116.  
  117.  
  118.  
  119. default:
  120. cout << "The valid menu choices are from A through D only. \n";
  121.  
  122. }
  123.  
  124. for (int i = 0; i < 3; i++)
  125. {
  126. cout << "\nTotal " << airlines[i].gettickettype() << "\t" << "Ticket: " << airlines[i].getticketquantity();
  127. cout << "\tCharge: $" << setw(7) << airlines[i].getTicketSubtotal() << "\tTax: $" << setw(7) << airlines[i].gettax();
  128. }
  129.  
  130. double subtotal = 0;
  131. for (int i = 0; i < 3; i++)
  132. subtotal += airlines[i].getTicketSubtotal();
  133. cout << "\nSub Total: \t" << setw(15) << subtotal << endl;
  134. cout << "Tax: \t\t" << setw(15) << subtotal * TAX;
  135. cout << endl << "\nTotal charges: \t" << setw(15) << (1 + TAX) * subtotal << endl << endl;
  136. } while (toupper(strOpt[0] != Quit));
  137.  
  138. outputfile.close();
  139.  
  140. cout << endl << "Enjoy your flight! \n";
  141. cout << "See you next time. \n";
  142. cout << "\nIf you are a custmoer, you can exit this program now.\n";
  143. cout << "Please enter 'Y/y' for yes or 'N/n' if you would like to continue: ";
  144. getline(cin, strOpt);
  145.  
  146. if (toupper(strOpt[0]) == 'Y')
  147. {
  148. cout << "\nThank you for the business! \n";
  149. cout << "Please press the enter key to exit.";
  150. cin.get();
  151. return 0;
  152. }
  153. else
  154. cout << "\nPlease continue this program. \n";
  155.  
  156.  
  157.  
  158. return 0;
  159. }
  160.  
  161.  
  162. int binarysearch(int iArray[], int iSize, int iMin, int iMax, int iValue)
  163. {
  164. if (iMax < iMin)
  165. return -1;
  166. else
  167. {
  168. int iMid = (iMin + iMax) / 2;
  169. if (iArray[iMid] > iValue)
  170. return binarysearch(iArray, iSize, iMid, iMid - 1, iValue);
  171. else if (iArray[iMid] < iValue)
  172. return binarysearch(iArray, iSize, iMid + 1, iMax, iValue);
  173. else
  174. return iMid;
  175. }
  176.  
  177.  
  178.  
  179.  
  180.  
  181. }
  182.  
  183. void selectionsort(int *ticketcharge, int size)
  184. {
  185. int start, smallestid, smallestvalue;
  186. for (start = 0; start < (size - 1); start++)
  187. {
  188.  
  189. }
  190.  
  191. }
  192.  
  193.  
  194.  
  195. Airline::Airline(string type, double price, int quantity)
  196. {
  197. tickettype = type;
  198. ticketprice = price;
  199. ticketquantity = quantity;
  200.  
  201. }
  202.  
  203. void Airline::setticketquantity(int quantity)
  204. {
  205. ticketquantity += quantity;
  206. }
  207.  
  208. int Airline::getticketquantity() const
  209. {
  210. return ticketquantity;
  211. }
  212.  
  213. double Airline::getticketprice() const
  214. {
  215. return ticketprice;
  216. }
  217.  
  218. string Airline::gettickettype() const
  219. {
  220. return tickettype;
  221. }
  222.  
  223. double Airline::getTicketSubtotal() const
  224. {
  225. return ticketprice * ticketquantity;
  226. }
  227.  
  228. double Airline::gettax() const
  229. {
  230. return getTicketSubtotal() * TAX;
  231. }
Advertisement
Add Comment
Please, Sign In to add comment