1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//Prototype
void programInfo();
void licenseP(string & plateNumber);
void inputData(double & vehicleSpeed, double & speedLimit);
void processData(double vehicleSpeed, double & ticketAmount, double & speedOver, double speedLimit, string plateNumber);
void displayData(double vehicleSpeed, double speedLimit);
int main()
{// Variables
double vehicleSpeed =0;
double ticketAmount=0;
double speedOver=0;
double speedLimit=0;
string plateNumber=" ";
string sentinel = "NONE";
programInfo();
cout << fixed << showpoint << setprecision(2);
licenseP(plateNumber);
int ticketCounter = 0; // Set counter
int totalVehicles = 0; // Set counter
// While loop
while (plateNumber != sentinel)
{
inputData(vehicleSpeed, speedLimit);
processData(vehicleSpeed, ticketAmount, speedOver, speedLimit, plateNumber);
// Use the if/else statement to count the vehicles
// being ticket and the total of vehicles pull over
// according to the ticket amount.
if (ticketAmount == 0)
totalVehicles++;
else if (ticketAmount > 0)
{
totalVehicles++;
ticketCounter++;
}
cout << "\n";
licenseP(plateNumber);
}
cout << "Number of Vehicles with tickets is " << ticketCounter << endl;
cout << "Number of Vehicles without tickets is " << totalVehicles - ticketCounter << endl;
cout << " Total of Vehicles ticketed/non-ticketed : " << totalVehicles << endl;
//displayData();
return 0;
}
//Definitions
// Display basic program information
void programInfo()
{
cout << "AHP Program version 2.1 by Gabriela Quevedo Rodriguez.";
cout << "Enter the license plate number, vehicle's current speed, and speed limit in the zone." << endl;
cout << "To stop repeating the process please enter 'NONE'." << endl;
cout << "\n";
}
// Licence plate input
void licenseP(string & plateNumber)
{
cout << "Enter a license plate number --->" << setw(8);
cin >> plateNumber;
}
// Vehicle speed and speed limit input
void inputData(double & vehicleSpeed, double & speedLimit)
{
cout << "Enter current vehicle's speed --->" << setw(8);
cin >> vehicleSpeed;
cout << "Enter speed limit in the zone --->" << setw(8);
cin >> speedLimit;
}
// Determine if a ticket will be given and total ticket cost
void processData(double vehicleSpeed, double & ticketAmount, double & speedOver, double speedLimit, string plateNumber)
{
speedOver = vehicleSpeed - speedLimit;
if (speedOver < 5)
{
cout << "No ticket is issued to " << plateNumber << "." << endl;
ticketAmount = 0.0; // Change from return to ticketAmount to be used in main to count vehicles.
}
else if (speedOver <= 20)
{
ticketAmount = 150.00 + (5.00 * speedOver);
cout << " A ticket of $" << ticketAmount << " is issued to " << plateNumber << "." << endl;
}
else if (speedOver > 20 && speedOver < 50)
{
ticketAmount = 150.00 + (10.00 * speedOver);
cout << " A ticket of $" << ticketAmount << " is issued to " << plateNumber << "." << endl;
}
else if (speedOver >= 50)
{
ticketAmount = 1000.00;
cout << " A ticket of $" << ticketAmount << " is issued to " << plateNumber << "." << endl;
}
}
// Display ticketed vehicle amount out of total vehicles. Determine percent of ticketed vehicles and average ticket amount.
//void displayData(double vehicleSpeed, double speedLimit)
//{
// int totalVehicles = 0;
// int ticketVehicles = 0;
//
// //for (totalVehicles = 0;;);
//
// totalVehicles = inputData(vehicleSpeed, speedLimit);
//
// cout << "Thank you for using our AHP program." << endl;
//}
|