Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <string>
- #include <cctype>
- using namespace std;
- int TicketYN();
- void DateOfOffence(int&, int&);
- void DriverName(string&);
- void CalculateFine(int, double[], int);
- void OfficerBadgeNumber(const int[], const int, const string[], int&);
- int InputSpeed();
- int PrintTicket(int, int, const int, string, double, int, string const, double);
- int CalcuateFine(int, int[], int);
- void main()
- {
- const int YEAR = 2011;
- const int MAX_NAMES = 4;
- const int BADGES[4] = {1234, 2345, 3456, 4567};
- const string NAMES[4] = {"Sandra Claus", "Jack Frost", "Peter Snow", "Wendy White"};
- double fines[4] = {0};
- double offendorFine;
- int badge;
- int day;
- int month;
- string offender;
- while (TicketYN() == 1)
- {
- cout << endl;
- DateOfOffence(day, month);
- cout << endl;
- cin.ignore();
- OfficerBadgeNumber(BADGES, MAX_NAMES, NAMES, badge);
- cin.ignore();
- DriverName(offender);
- CalculateFine(InputSpeed(), fines, badge);
- system("cls");
- PrintTicket(day, month, YEAR, offender, offendorFine, badge, NAMES, fines);
- }
- }
- int TicketYN()
- {
- string yN;
- do
- {
- do
- {
- cout << "Enter ticket info (Y or N)? ";
- getline (cin, yN);
- }
- while (yN.empty() || yN.size() > 1);
- yN = toupper (yN[0]);
- }
- while (yN[0] != 'Y' && yN[0] != 'N');
- if (yN[0] == 'Y')
- return 1;
- else
- return 0;
- }
- void DateOfOffence(int& day, int& month)
- {
- do
- {
- cout << "Day of offence (1 to 31): ";
- cin >> day;
- }
- while (day < 1 || day > 31);
- do
- {
- cout << "Month of offence (1 to 12): ";
- cin >> month;
- }
- while (month < 1 || month > 12);
- }
- void DriverName(string& fullName)
- {
- string firstName;
- string lastName;
- int counter;
- do
- {
- cout << "Driver's first name (20 chars max): ";
- getline (cin, firstName);
- }
- while (firstName.empty() || firstName.size() > 20);
- do
- {
- cout << "Driver's last name (25 chars max): ";
- getline (cin, lastName);
- }
- while (lastName.empty() || lastName.size() > 25);
- firstName[0] = toupper (firstName[0]);
- lastName[0] = toupper (lastName[0]);
- for (counter = 1; counter < firstName.size(); counter++)
- firstName[counter] = tolower (firstName[counter]);
- for (counter = 1; counter < lastName.size(); counter++)
- lastName[counter] = tolower (lastName[counter]);
- fullName = firstName + " " + lastName;
- }
- void OfficerBadgeNumber(const int BADGES[], const int MAX_NAMES, const string NAMES[], int& badge)
- {
- int counter;
- cout << "Possible Officer Badge #s are ";
- for (counter = 0; counter < MAX_NAMES; counter++)
- cout << BADGES[counter] << ", ";
- cout << endl;
- do
- {
- cout << "Officer badge #: ";
- cin >> badge;
- for (counter = 0; counter < MAX_NAMES; counter++)
- if (badge == BADGES[counter])
- break;
- }
- while (counter == MAX_NAMES);
- badge = counter;
- }
- int InputSpeed()
- {
- int speed;
- do
- {
- cout << "Vehicle speed (71 to 180): ";
- cin >> speed;
- }
- while (speed < 71 || speed > 180);
- return speed;
- }
- void CalculateFine(int speed, double fine[], int badge, double offendorFine)
- {
- if (speed > 110)
- {
- fine[badge] += (speed - 70 ) * 22.00;
- offendorFine = (speed - 70 ) * 22.00;
- }
- else if (speed > 100)
- {
- fine[badge] += (speed - 70 ) * 15.50;
- offendorFine = (speed - 70 ) * 15.00;
- }
- else if (speed > 90)
- {
- fine[badge] += (speed - 70 ) * 8.50;
- offendorFine = (speed - 70 ) * 8.50;
- }
- else
- {
- fine[badge] += (speed - 70 ) * 4.00;
- offendorFine = (speed - 70 ) * 4.00;
- }
- }
- void PrintTicket(int day, int month, const int YEAR, string offender, double offendorFine, int badge, string const NAMES[], double fines[])
- {
- cout << "Arrest made by " << NAMES[badge] << endl;
- cout << "Offender " << offendor << " was fined " << offendorFine;
- }
Add Comment
Please, Sign In to add comment