Advertisement
Guest User

Untitled

a guest
Dec 15th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. #define NUM 100
  4. int const fee = 0;
  5. int const fun = 1;
  6.  
  7. // the sorting function the function takes the array party and its size to arrange the parties and their fees descendingly according to fun per fee
  8.  
  9. void partySort(int party[][2], int size) {
  10.  
  11. int insert[2];
  12.  
  13. for (int next = 1; next < size; ++next)
  14. {
  15. insert[0] = party[next][fee];
  16. insert[1] = party[next][fun];
  17.  
  18. int moveItem = next;
  19.  
  20. while (moveItem > 0 && static_cast<double>(party[moveItem - 1][fun]) / party[moveItem - 1][fee] <static_cast<double>(insert[1]) / insert[0])
  21. {
  22. party[moveItem][fee] = party[moveItem - 1][fee];
  23. party[moveItem][fun] = party[moveItem - 1][fun];
  24. moveItem--;
  25. }
  26. party[moveItem][fee] = insert[0];
  27. party[moveItem][fun] = insert[1];
  28. }
  29. }
  30.  
  31. void main() {
  32.  
  33. // welcome statement
  34.  
  35. cout << " *** Welcome to Party Hard... Pay A Lot less *** " << endl << endl << endl;
  36.  
  37. // decalring and initializing variables
  38.  
  39. int number, budget, sum = 0, funsum = 0;
  40. int party[NUM][2];
  41.  
  42. //Inputing the data of parties with user validation process
  43.  
  44. cout << "Please, enter the number of parties: ";
  45. cin >> number;
  46.  
  47. cout << endl << "Please, enter budget (0 ~ 500): ";
  48. cin >> budget;
  49. cout << endl;
  50. for (; budget > 500;)
  51. {
  52. cout << "The budget is too much\n" << "please enter the budget again: "; //user validation for budget between 0 and 500
  53. cin >> budget;
  54. }
  55. //Enter the price for each party
  56.  
  57. for (int i = 0; i<number; i++)
  58. {
  59. cout << "please enter party " << i + 1 << " fee : ";
  60. cin >> party[i][fee];
  61. cout << endl;
  62. for (; (party[i][fee]>25) || (party[i][fee] <5);) //user validation for fee of the party between 5 and 25
  63. {
  64. cout << "The Party's fee is too high\n" << endl << "please enter the fee again of party(5 ~ 25) " << i+1 <<" : ";
  65. cin >> party[i][fee];
  66. cout << endl;
  67. }
  68. //Enter the fun for each party
  69. cout << "please enter party " << i + 1 << " fun (0 ~ 10): ";
  70. cin >> party[i][fun];
  71.  
  72. for (; (party[i][fun]<0) || (party[i][fun]>10);) //user validation for fun of the party between 0 and 10
  73. {
  74. cout << "The Party's fun is not in range\n" << endl << "please enter the fun of the party of party " << i + 1 << " (0 ~ 10) : ";
  75. cin >> party[i][fee];
  76. cout << endl;
  77. }
  78.  
  79.  
  80. cout << endl;
  81. }
  82.  
  83. partySort(party, number); //Calling the sorting function
  84.  
  85. //Outputting the result
  86.  
  87. cout << endl << endl << endl << endl << endl << endl << endl << " Order of parties by fun per fee " << endl << endl << endl;
  88.  
  89. cout << "Party no." << " " << "** Fee :'( **" << " " << "** Fun :D **" << endl << endl;
  90.  
  91. for (int i = 0; i < number; i++)
  92. {
  93. cout << i + 1 << " " << party[i][fee] << " " << party[i][fun] << endl << endl;
  94.  
  95. }
  96. cout << endl << endl << endl << endl << endl << endl << endl << " Our Program Suggests these Parties to get most fun :-) " << endl << endl << endl;
  97. for (int i = 0; i < budget; i++)
  98. {
  99. cout << i + 1 << " " << party[i][fee] << " " << party[i][fun] << endl << endl;
  100.  
  101. cout << endl << endl << endl << " And Dont forget to party HARD :D (o_0) " << endl << endl << endl;
  102. system("pause");
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement