Professional Documents
Culture Documents
2. The traffic section are keeping manual records of motor speeding offenders. The
information kept on each offence include driver's license number, name, address,
travelling speed and fine amount. The fine amount is calculated based on the
If the driver exceed speed limit by 51 km/h or more he/she is liable to appear in court
and will not pay any fine. An officer is then responsible for calculating the total
amount collected from all the offenses. They have approached you a C++ expert to
design a program which caters for the above scenario.
Required
a.) Design a suitable structure which caters for the above scenario (14)
#include <iostream>
struct Traffic{
void setValues(){
cin>>d_l;
cout<<"Enter drivers name"<<endl;
cin>>name;
cout<<"Enter address"<<endl;
cin>>add;
cin>>speed;
cin>>limit;
double calc(){
cout<<diff;
if( diff>=0){
fine= 10.00;
fine= 20.00;
fine= 30.00;
fine= 50.00;
else{
fine= 0;
}
} else{
fine= 0;
return fine;
void display(){
cout<<d_l<<"\t" <<name<<"\t"<<add<<"\t"<<speed<<"\t"<<calc()<<endl;
};
b.) Create your instances within the main where the user will specify the total number
of offenders before displaying the output (5)
int main()
double total=0 ;
int n;
cin>>n;
Traffic t[n];
t[i].setValues();
total+= t[i].calc();
cout<<"Drvers"<<"\t"
<<"Name"<<"\t"<<"Address"<<"\t"<<"Speed"<<"\t"<<"Fine"<<endl;
for(int i= 0; i<n; i++){
t[i].display();
return 0;
Required
a.) Design a suitable structure which caters for the above scenario (14)
Ans:
#include <iostream>
struct Kampala{
/*
*/
char over;
double calcExtra(){
if(over=='Y' || over=='y'){
cin>>hrs;
cin>>costph;
} else{
extra= 0;
return extra;
void setValues(){
fee= 35.00;
cin>>reg;
cout<<"Enter Person"<<endl;
cin>>person;
cin>>over;
calcExtra();
void display(){
cout<<reg<<"\t"<<person<<"\t"<<fee<<"\t"<<extra<<extra + fee<<endl;
}
};
b.) Create your instances within the main where the user will specify the total number
of violators before displaying the output (5)
Ans:
int main()
double total=0 ;
int n;
cin>>n;
Kampala k[n];
k[i].setValues();
cout<<"Reg"<<"\t" <<"Name"<<"\t"<<"Fee"<<"\t"<<"Extra"<<"\t"<<"Total"<<endl;
k[i].display();
return 0;