Traffic Violation System-Applications of Programming-C Plus Plus Code, Exercises of Applications of Computer Sciences

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

2011/2012

Uploaded on 08/01/2012

omni
omni 🇮🇳

4.6

(9)

46 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
using namespace std;
#include<iostream>
#include<conio.h>
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;
docsity.com
pf2

Partial preview of the text

Download Traffic Violation System-Applications of Programming-C Plus Plus Code and more Exercises Applications of Computer Sciences in PDF only on Docsity!

using namespace std; #include #include<conio.h>

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;

docsity.com

//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');

docsity.com