Advertisement
Caeg

Untitled

May 10th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 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. string filename;
  54. int iTemp;
  55. static int iCounter = 0;
  56. ofstream outputfile;
  57. outputfile.open("ticketCharge.txt");
  58. ifstream inputfile;
  59.  
  60.  
  61. do
  62. {
  63. cout << "\tAirlines Ticket Menu\n";
  64. cout << "A. Standard Ticket" << "\t$250.00 each\n";
  65. cout << "B. Economy Ticket" << "\t$350.00 each\n";
  66. cout << "C. Business Ticket" << "\t$450.00 each\n";
  67. cout << "D. Quit the menu";
  68. cout << "\n\nPlease enter your choice of A, B, C, or D: ";
  69. cin >> strOpt;
  70.  
  71.  
  72.  
  73. switch (toupper(strOpt[0]))
  74. {
  75. case Standard:
  76. cout << "\nHow many tickets would you like to purchase? ";
  77. cin >> iTemp;
  78.  
  79. airlines[0].setticketquantity(iTemp);
  80.  
  81. cout << "\n" << airlines[0].gettickettype() << ": $" << airlines[0].getticketprice() << " Each" << "\tTicket: ";
  82. cout << iTemp << "\tCharge: $" << setw(7) << airlines[0].getticketprice() * iTemp;
  83. cout << "\tTax: $" << setw(7) << airlines[0].getticketprice() * iTemp * TAX << endl;
  84.  
  85. outputfile << airlines[0].getTicketSubtotal();
  86. iCounter++;
  87.  
  88. break;
  89.  
  90. case Economy:
  91. cout << "\nHow many tickets would you like to purchase? ";
  92. cin >> iTemp;
  93.  
  94. airlines[1].setticketquantity(iTemp);
  95.  
  96. cout << "\n" << airlines[1].gettickettype() << ": $" << airlines[1].getticketprice() << " Each" << "\tTicket: ";
  97. cout << iTemp << "\tCharge: $" << setw(7) << airlines[1].getticketprice() * iTemp;
  98. cout << "\tTax: $" << setw(7) << airlines[1].getticketprice() * iTemp * TAX << endl;
  99.  
  100. outputfile << airlines[1].getTicketSubtotal();
  101. iCounter++;
  102. break;
  103.  
  104. case Business:
  105. cout << "\nHow many tickets would you like to purchase? ";
  106. cin >> iTemp;
  107.  
  108. airlines[2].setticketquantity(iTemp);
  109.  
  110. cout << "\n" << airlines[2].gettickettype() << ": $" << airlines[2].getticketprice() << " Each" << "\tTicket: ";
  111. cout << iTemp << "\tCharge: $" << setw(7) << airlines[2].getticketprice() * iTemp;
  112. cout << "\tTax: $" << setw(7) << airlines[2].getticketprice() * iTemp * TAX << endl;
  113.  
  114. outputfile << airlines[2].getTicketSubtotal();
  115. iCounter++;
  116. break;
  117.  
  118.  
  119. case Quit:
  120. cout << endl << "Enjoy your flight! \n";
  121. cout << "See you next time. \n";
  122. cout << "\nIf you are a customer, you can exit this program now.\n";
  123. cout << "Please enter 'Y/y' for yes or 'N/n' if you would like to continue: ";
  124. getline(cin, strOpt);
  125.  
  126. cin.ignore();
  127.  
  128. if (toupper(strOpt[0]) == 'Y')
  129. {
  130. cout << "\nThank you for the business! \n";
  131. cout << "Please press the enter key to exit.";
  132. cin.get();
  133. return 0;
  134. }
  135. else
  136. cout << "\nPlease continue this program. \n\n";
  137. cout << "Please enter the password for the text file: ";
  138. getline(cin, filename);
  139. inputfile.open(filename.c_str());
  140.  
  141. while (!inputfile)
  142. {
  143. inputfile.clear();
  144. cout << "That is not the correct name of the file. Please enter in the correct file name: ";
  145. getline(cin, filename);
  146. inputfile.open(filename.c_str());
  147.  
  148. }
  149.  
  150. if (inputfile)
  151. {
  152. cout << "The array's content before it was sorted is: ";
  153.  
  154. cout << "The array's content after it was sorted is: ";
  155.  
  156. cout << "Please enter the number you wish to search for: ";
  157.  
  158. cout << "Would you like to search more?";
  159.  
  160. cout << "\nEnter Y/y for yes and N/n for no: ";
  161.  
  162.  
  163.  
  164.  
  165. }
  166.  
  167.  
  168.  
  169.  
  170.  
  171. break;
  172.  
  173.  
  174. default:
  175. cout << "The valid menu choices are from A through D only. \n";
  176.  
  177. }
  178.  
  179. for (int i = 0; i < 3; i++)
  180. {
  181. cout << "\nTotal " << airlines[i].gettickettype() << "\t" << "Ticket: " << airlines[i].getticketquantity();
  182. cout << "\tCharge: $" << setw(7) << airlines[i].getTicketSubtotal() << "\tTax: $" << setw(7) << airlines[i].gettax();
  183. }
  184.  
  185. double subtotal = 0;
  186. for (int i = 0; i < 3; i++)
  187. subtotal += airlines[i].getTicketSubtotal();
  188. cout << "\n\nSub Total: \t$" << setw(15) << subtotal << endl;
  189. cout << "Tax: \t\t$" << setw(15) << subtotal * TAX;
  190. cout << endl << "\nTotal charges: \t$" << setw(15) << (1 + TAX) * subtotal << endl << endl;
  191. cout << "-------------------------------------------------------------------------------\n";
  192.  
  193. } while (toupper(strOpt[0] != Quit));
  194.  
  195.  
  196.  
  197. cout << endl << "Enjoy your flight! \n";
  198. cout << "See you next time. \n";
  199. cout << "\nIf you are a customer, you can exit this program now.\n";
  200. cout << "Please enter 'Y/y' for yes or 'N/n' if you would like to continue: ";
  201. getline(cin, strOpt);
  202.  
  203. if (toupper(strOpt[0]) == 'Y')
  204. {
  205. cout << "\nThank you for the business! \n";
  206. cout << "Please press the enter key to exit.";
  207. cin.get();
  208. return 0;
  209. }
  210. else
  211. cout << "\nPlease continue this program. \n";
  212.  
  213.  
  214.  
  215. return 0;
  216. }
  217.  
  218.  
  219. int binarysearch(int iArray[], int iSize, int iMin, int iMax, int iValue)
  220. {
  221. if (iMax < iMin)
  222. return -1;
  223. else
  224. {
  225. int iMid = (iMin + iMax) / 2;
  226. if (iArray[iMid] > iValue)
  227. return binarysearch(iArray, iSize, iMid, iMid - 1, iValue);
  228. else if (iArray[iMid] < iValue)
  229. return binarysearch(iArray, iSize, iMid + 1, iMax, iValue);
  230. else
  231. return iMid;
  232. }
  233.  
  234.  
  235.  
  236.  
  237.  
  238. }
  239.  
  240. void selectionsort(int *ticketcharge, int size)
  241. {
  242. int start, smallestid, smallestvalue;
  243. for (start = 0; start < (size - 1); start++)
  244. {
  245.  
  246. }
  247.  
  248. }
  249.  
  250.  
  251.  
  252. Airline::Airline(string type, double price, int quantity)
  253. {
  254. tickettype = type;
  255. ticketprice = price;
  256. ticketquantity = quantity;
  257.  
  258. }
  259.  
  260. void Airline::setticketquantity(int quantity)
  261. {
  262. ticketquantity += quantity;
  263. }
  264.  
  265. int Airline::getticketquantity() const
  266. {
  267. return ticketquantity;
  268. }
  269.  
  270. double Airline::getticketprice() const
  271. {
  272. return ticketprice;
  273. }
  274.  
  275. string Airline::gettickettype() const
  276. {
  277. return tickettype;
  278. }
  279.  
  280. double Airline::getTicketSubtotal() const
  281. {
  282. return ticketprice * ticketquantity;
  283. }
  284.  
  285. double Airline::gettax() const
  286. {
  287. return getTicketSubtotal() * TAX;
  288. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement