using C++ languange Use of functions and re-use of functions whenever possible.
ID: 3771908 • Letter: U
Question
using C++ languange
Use of functions and re-use of functions whenever possible. ?
Use of arrays ?
Qatar University Dept. of Computer Science& Engineering Computer Programming (GEN106) ATAR UNIVERSITY Traffic Violation System This system tracks car traffic violation tickets, the data in this system include: car plate number, ticket number, violation type, fine, status (paid or unpaid). The following table shows examples of such records 112233 223344 334455 445566 556677 12 23 1101 Using mobile while drivi Driving in the Seat Belt Parking in a Walk from ri 300 Paid 6000 Unpaid 500 Unpaid 500 Paid 3000 bited area Assume the system will be used by employees in the traffic department. When the system runs, the program starts by loading the traffic violoations data from a fixed file. Then the system displays the following menu: 1- Add a new ticket. 2- Delete a ticket (only unpaid tickets can be deleted) 3- Pay a ticket. 4 Display all violation tickets. 5- Search for tickets by car plate no. 6- Display all tickets that are not paid yet. 7- Exit. When the user selects 1: the system asks for plate number, violation type, fine, and the ticket number When the user selects 2: the system asks for plate number. Since only unpaid tickets can be deleted, if there is no unpaid ticket for that plate number, a message is displayed "This car has no unpaid ticket". Otherwise, the system displays all unpaid tickets and asks user to input ticket number to be deleted. The system ensures that number is correct and belongs to that car, if it is correct, system deletes that ticket When the user selects 3: the system asks for plate no, if there is no unpaid ticket for that plate number, a message is displayed “ this car has no unpaid ticket". Otherwise, the system displays all unpaid tickets and asks user to input the ticket number to be paid, system ensures that number is correct and belongs to that car, if it is correct, system changes the status of that ticket to "Paid" When user selects 4: the system displays data of all tickets. .Explanation / Answer
//Header files
#include //this header file is included to use cout and cin
#include //this header file is included to use clearing screen function
//Main function
void main(void)
{//Start of main function
//Variable declaration
int violationType; //this varaible is used in switch statement for violation type
int fineAmount; //this variable is used in each case for amount of fine
int challanDays; //this varaible is used in each case for days passed to challan
char choice; //this varaible is used in do-while loop for choice to calculate next challan
do
{ //Start of do-while loop
//Clearing Screen
system("cls");
//Show output
cout<<"******* CHALLAN CALCULATOR FOR TRAFFIC VIOLATIONS ******* ";
cout<<"Enter 1 for breaking traffic signal ";
cout<<"Enter 2 for over speeding ";
cout<<"Enter 3 for not wearing seat belt ";
cout<<" Enter the type of traffic voilation (1,2 or 3): ";
//Input for traffic violation
cin>>violationType;
switch(violationType)
{ //Start of switch
case 1:
fineAmount = 500;
cout<<" Enter number of days passed till challan date: ";
cin>>challanDays;
if (challanDays <= 10)
{
cout<<" Total amount of challan is Rs."<<fineAmount;
}
else if (challanDays > 10 && challanDays <=30)
{
cout<<" Total amount of challan is Rs."<<fineAmount * 2;
}
else
{
cout<<" Total amount of challan is Rs."<<fineAmount * 2.5;
}
break;
case 2:
fineAmount = 300;
cout<<" Enter number of days passed till challan date: ";
cin>>challanDays;
if (challanDays <= 10)
{
cout<<" Total amount of challan is Rs."<<fineAmount;
}
else if (challanDays > 10 && challanDays <=30)
{
cout<<" Total amount of challan is Rs."<<fineAmount * 2;
}
else
{
cout<<" Total amount of challan is Rs."<<fineAmount * 2.5;
}
break;
case 3:
fineAmount = 200;
cout<<" Enter number of days passed till challan date: ";
cin>>challanDays;
if (challanDays <= 10)
{
cout<<" Total amount of challan is Rs."<<fineAmount;
}
else if (challanDays > 10 && challanDays <=30)
{
cout<<" Total amount of challan is Rs."<<fineAmount * 2;
}
else
{
cout<<" Total amount of challan is Rs."<<fineAmount * 2.5;
}
break;
//Default case when user will entered wrong value
default:
cout<<" Enter a valid type of traffic violation";
break;
} //End of switch
cout<<" Do you want to calculate another challan (y/n): ";
cin>> choice;
} //end of do-while loop
while (choice == 'y' || choice == 'Y');
}//End of main function
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.