

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Applications of different concepts in programming are in this code. These can be used in learning C plus plus. It includes: Vehicle, Structure, Owner, Function, View, Else, Information, Owner, Address, Transfer
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


using namespace std; #include
main() { int type; //to store the type to traffic violation int fine; //to store the amount of fine against violation type int duration; //to store the number of days passed till challan date int challan; //to store the challan against violation type and number of days passed char choice = 'y'; //to get user's choice whether to calculate another challan or not
do { system("cls"); //clear screen function
//following 4 lines of code are printing information about how to select a specific traffic violation cout << "******* CHALLAN CALCULATOR FOR TRAFFIC VIOLATIONS *******" << endl <<endl; cout << "Enter '1' for breaking signal" << endl; cout << "Enter '2' for over speeding" << endl; cout << "Enter '3' for not wearing seat belt" << endl;
// Taking input from user to select a violation type in variable "type" cout << endl << "Enter the type of traffic violation (1, 2, or 3) : " ; cin >> type;
//if user enters anything except 1, 2, or 3, the error message will be shown and do-while loop will start again due to continue statement if(type <1 || type > 3) { cout << endl <<"Enter a valid type of traffic violation";
//getch() function will get a character from user. Its used here to hold the output screen before executing continue statement so that user can see the error message before screen gets cleared getch(); continue; }
//Taking input for number of days passed till challan date in variable duration cout << "Enter the number of days passed till challan date : "; cin >> duration;
//Checking value of "type" variable and assigning corresponding amount of fine to variable "fine" switch(type) { case 1: fine = 500; break;
case 2: fine = 300; break;
case 3: fine = 200; break;
}
//Calculating total challan according to number of days passed till challan date if(duration <=10) { challan = fine; } else if(duration <=30) { challan = fine * 2; } else { challan = fine * 2 + (fine / 2); }
cout << "The total challan is Rs." << challan << endl << endl;
//taking user's choice whether to calculate another challan or not cout << "Do you want to calculate another challan? (y/n) : "; cin >> choice;
//loop will start again only if the choice is y or Y }while(choice == 'y' || choice == 'Y');