Caeg

Untitled

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