Advertisement
Caeg

Untitled

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