Guest User

Untitled

a guest
Apr 21st, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4. #include <cctype>
  5.  
  6. using namespace std;
  7.  
  8. int TicketYN();
  9. void DateOfOffence(int&, int&);
  10. void DriverName(string&);
  11. void CalculateFine(int, double[], int);
  12. void OfficerBadgeNumber(const int[], const int, const string[], int&);
  13. int InputSpeed();
  14. int PrintTicket(int, int, const int, string, double, int, string const, double);
  15. int CalcuateFine(int, int[], int);
  16.  
  17.  
  18. void main()
  19. {
  20. const int YEAR = 2011;
  21. const int MAX_NAMES = 4;
  22. const int BADGES[4] = {1234, 2345, 3456, 4567};
  23. const string NAMES[4] = {"Sandra Claus", "Jack Frost", "Peter Snow", "Wendy White"};
  24.  
  25. double fines[4] = {0};
  26. double offendorFine;
  27. int badge;
  28. int day;
  29. int month;
  30.  
  31. string offender;
  32.  
  33.  
  34.  
  35. while (TicketYN() == 1)
  36. {
  37. cout << endl;
  38.  
  39. DateOfOffence(day, month);
  40. cout << endl;
  41. cin.ignore();
  42.  
  43. OfficerBadgeNumber(BADGES, MAX_NAMES, NAMES, badge);
  44.  
  45. cin.ignore();
  46. DriverName(offender);
  47.  
  48. CalculateFine(InputSpeed(), fines, badge);
  49.  
  50. system("cls");
  51. PrintTicket(day, month, YEAR, offender, offendorFine, badge, NAMES, fines);
  52. }
  53. }
  54.  
  55. int TicketYN()
  56. {
  57. string yN;
  58.  
  59. do
  60. {
  61. do
  62. {
  63. cout << "Enter ticket info (Y or N)? ";
  64. getline (cin, yN);
  65. }
  66. while (yN.empty() || yN.size() > 1);
  67.  
  68. yN = toupper (yN[0]);
  69. }
  70. while (yN[0] != 'Y' && yN[0] != 'N');
  71.  
  72. if (yN[0] == 'Y')
  73. return 1;
  74. else
  75. return 0;
  76. }
  77.  
  78. void DateOfOffence(int& day, int& month)
  79. {
  80. do
  81. {
  82. cout << "Day of offence (1 to 31): ";
  83. cin >> day;
  84. }
  85. while (day < 1 || day > 31);
  86.  
  87. do
  88. {
  89. cout << "Month of offence (1 to 12): ";
  90. cin >> month;
  91. }
  92. while (month < 1 || month > 12);
  93. }
  94.  
  95. void DriverName(string& fullName)
  96. {
  97. string firstName;
  98. string lastName;
  99. int counter;
  100.  
  101. do
  102. {
  103. cout << "Driver's first name (20 chars max): ";
  104. getline (cin, firstName);
  105. }
  106. while (firstName.empty() || firstName.size() > 20);
  107.  
  108. do
  109. {
  110. cout << "Driver's last name (25 chars max): ";
  111. getline (cin, lastName);
  112. }
  113. while (lastName.empty() || lastName.size() > 25);
  114.  
  115. firstName[0] = toupper (firstName[0]);
  116. lastName[0] = toupper (lastName[0]);
  117.  
  118. for (counter = 1; counter < firstName.size(); counter++)
  119. firstName[counter] = tolower (firstName[counter]);
  120.  
  121. for (counter = 1; counter < lastName.size(); counter++)
  122. lastName[counter] = tolower (lastName[counter]);
  123.  
  124. fullName = firstName + " " + lastName;
  125. }
  126.  
  127. void OfficerBadgeNumber(const int BADGES[], const int MAX_NAMES, const string NAMES[], int& badge)
  128. {
  129. int counter;
  130.  
  131. cout << "Possible Officer Badge #s are ";
  132. for (counter = 0; counter < MAX_NAMES; counter++)
  133. cout << BADGES[counter] << ", ";
  134. cout << endl;
  135.  
  136. do
  137. {
  138. cout << "Officer badge #: ";
  139. cin >> badge;
  140.  
  141. for (counter = 0; counter < MAX_NAMES; counter++)
  142. if (badge == BADGES[counter])
  143. break;
  144. }
  145. while (counter == MAX_NAMES);
  146.  
  147. badge = counter;
  148. }
  149.  
  150. int InputSpeed()
  151. {
  152. int speed;
  153.  
  154. do
  155. {
  156. cout << "Vehicle speed (71 to 180): ";
  157. cin >> speed;
  158. }
  159. while (speed < 71 || speed > 180);
  160.  
  161. return speed;
  162. }
  163.  
  164. void CalculateFine(int speed, double fine[], int badge, double offendorFine)
  165. {
  166. if (speed > 110)
  167. {
  168. fine[badge] += (speed - 70 ) * 22.00;
  169. offendorFine = (speed - 70 ) * 22.00;
  170. }
  171. else if (speed > 100)
  172. {
  173. fine[badge] += (speed - 70 ) * 15.50;
  174. offendorFine = (speed - 70 ) * 15.00;
  175. }
  176. else if (speed > 90)
  177. {
  178. fine[badge] += (speed - 70 ) * 8.50;
  179. offendorFine = (speed - 70 ) * 8.50;
  180. }
  181. else
  182. {
  183. fine[badge] += (speed - 70 ) * 4.00;
  184. offendorFine = (speed - 70 ) * 4.00;
  185. }
  186. }
  187.  
  188. void PrintTicket(int day, int month, const int YEAR, string offender, double offendorFine, int badge, string const NAMES[], double fines[])
  189. {
  190.  
  191.  
  192.  
  193.  
  194. cout << "Arrest made by " << NAMES[badge] << endl;
  195. cout << "Offender " << offendor << " was fined " << offendorFine;
  196. }
Add Comment
Please, Sign In to add comment