A
anchitgood
Hey, I have developed the following code and it is executing well on
windows. But I don't have LINUX installed on my system. I would be
grateful to you guys if you check whether this code is working fine on
linux. I know that C++ is independent of OS, but still check it on g++
compiler.
Thanks a lot in advance.
Anchit
CODE:
#include<iostream>
#include<string>
using namespace std;
int m=0, min, k[10], c;
class parkedcar //class holds data of the car in parking
{
string make;
int model;
string color;
string licnumber;
int minutesparked;
public:
parkedcar()
{
make=" ";
model=0;
licnumber=" ";
color=" ";
minutesparked=0;
}
void setmake(string mk)
{
make=mk;
}
void setmodel(int ml)
{
model=ml;
}
void setcolor(string c)
{
color=c;
}
void setlicnumber(string l)
{
licnumber=l;
}
void setminutesparked(int mnp)
{
minutesparked=mnp;
}
string getmake() const
{
return (make);
}
int getmodel() const
{
return (model);
}
string getcolor() const
{
return (color);
}
string getlicnumber() const
{
return (licnumber);
}
int getminutesparked() const
{
return (minutesparked);
}
void print();
};
void parkedcar:rint() //outside class definition
{
cout<<"Car Make :"<<getmake()<<endl;
cout<<"Car Model :"<<getmodel()<<endl;
cout<<"Car License Number :"<<getlicnumber()<<endl;
cout<<"Car Color :"<<getcolor()<<endl;
}
class parkingticket: public parkedcar //class calculates and shows
fine (if any)
{
int fine;
int minutes;
void calfine(); //helper function, calculates fine
public:
void showfine(); //function to show the fine
void getticket (int min) //calls the helper function calfine()
{
minutes=min;
calfine();
cout<<endl;
}
int getfine() const
{
return(fine);
}
};
void parkingticket::calfine() //outside class definition
{
if(minutes/60<=0)
{
fine = 45;
}
else
{
int mn;
mn=minutes - 60;
fine = 45 + 30 + 30*(mn/60);
}
}
void parkingticket::showfine() //outside class definition
{
cout<<" ILLEGAL PARKING"<<endl;
cout<<" Time in violation is "<<minutes/60<<" hours & "<<minutes
%60<<" minutes "<<endl;
cout<<" Fine : Rs. "<<getfine()<<endl;
}
parkingticket tck[10]; //Parking ticket array of objects created
class parkingmeter //This class take carea of number of minutes
purchased
{
int minpurchased;
public:
parkingmeter()
{
minpurchased=0;
}
void setminpurchased(int m)
{
minpurchased=m;
}
int getminpurchased() const
{
return(minpurchased);
}
void print()
{
cout<<"Mins purchased are"<<getminpurchased();
}
};
class policeofficer //Responsible for patrolling and issuing
parkingticket
{ //in case vehicle is illegally parked
string name;
string badgenumber;
parkingticket *ticket; //Pointer of the type parkingticket class
public:
policeofficer()
{
name=" ";
badgenumber=" ";
ticket = NULL;
}
void setname(string n)
{
name=n;
}
void setbadgenumber(string b)
{
badgenumber=b;
}
string getname() const
{
return(name);
}
string getbadgenumber() const
{
return(badgenumber);
}
parkingticket* patrol(parkingticket pc1, parkingmeter pc2) //Patrol
function
{
if ( pc1.getminutesparked() < pc2.getminpurchased() ||
pc1.getminutesparked() == pc2.getminpurchased() )
{
return NULL; //No crimes
}
else //Illegal parking
{
tck[m].getticket(pc1.getminutesparked() - pc2.getminpurchased());
cout<<"--------------------------------------------------------------------------------"<<endl;
tck[m].showfine();
ticket=&tck[m];
return(ticket);
}
}
void print()
{
cout<<"Name: "<<getname()<<endl;
cout<<"Badge Number: "<<getbadgenumber()<<endl;
}
};
void intro()
{
cout<<"********************************************************************************"<<endl;
cout<<" THIS IS PARKING TICKET SIMULATOR"<<endl;
cout<<"********************************************************************************"<<endl;
}
void choice()
{
cin>>c;
if(c==0)
{
m++;
}
else if(c==1)
{
}
else
{
cout<<"Invalid Entry, try again :"<<endl;
choice();
}
}
int main()
{
system("cls");
int i=0, y;
intro();
cout<<"PARKING RATES ::"<<endl;
cout<<"Parking rate is Rs. 25 for 60 minutes"<<endl;
cout<<endl<<endl;
cout<<"FINE RATES ::"<<endl;
cout<<"In case number of minutes car has been parked exceeds the
number of minutes purchased, then a fine is applied."<<endl;
cout<<"Rs 45 for first hour or part of an hour that the car is
illegally parked and Rs 30 for every additional hour or part of an
hour that the car is illegally parked."<<endl;
cout<<"________________________________________________________________________________"<<endl;
policeofficer officer; //Police Officer object created
string pname, pbadge;
cout<<"OFFICER'S INFORMATION ::"<<endl;
cout<<"Name: ";
cin>>pname;
cout<<"Badge Number: ";
cin>>pbadge;
officer.setname(pname);
officer.setbadgenumber(pbadge);
parkingmeter meter[10]; //Parking meter array of objects created
parkingticket* ticket = NULL;
do //Iteration of statements
{
system("cls");
intro();
cout<<"PARKED CAR'S INFORMATION ::"<<endl; //Officer inputs the data
of the car
string mk;
cout<<"Make :";
cin>>mk;
tck[m].setmake(mk);
int mod;
cout<<"Model :";
cin>>mod;
tck[m].setmodel(mod);
string lic;
cout<<"License number :";
cin>>lic;
y=0;
while(y<=m)
{
if (y!=m)
{
if (lic == tck[y].getlicnumber()) //License number being a
primary key
{
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Car with this License Number already exists"<<endl;
tck[y].print();
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Try re-entering the license number :";
cin>>lic;
}
}
y++;
}
tck[m].setlicnumber(lic);
string col;
cout<<"Color :";
cin>>col;
tck[m].setcolor(col);
int parmin; //The number of minutes a car has been parked
cout<<"Minutes in parking :";
cin>>parmin;
tck[m].setminutesparked(parmin);
int purmin; //The number of minutes purchased
cout<<"Minutes purchased :";
cin>>purmin;
meter[m].setminpurchased(purmin);
system("cls");
intro();
ticket = officer.patrol(tck[m], meter[m]); //The officer patrols
if(ticket==NULL)
{
// Display the ticket information.
tck[m].print();
cout<<endl;
cout<<endl;
cout<<"----------------------"<<endl;
cout<<"| NO CRIMES COMMITTED |"<<endl;
cout<<"----------------------"<<endl;
}
else
{
cout<<endl<<"Non-permitted vehicle ::"<<endl;
ticket->print(); // Display the ticket information.
cout<<"--------------------------------------------------------------------------------"<<endl;
ticket = NULL;
}
k[m] = tck[m].getminutesparked() - meter[m].getminpurchased();
cout<<endl<<endl<<endl<<endl<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"Enter your choice -"<<endl;
cout<<"0 - Patrol another car 1 - View cars patrolled"<<endl;
choice();
}while (c == 0);
system("cls");
intro();
for(i=0;i<=m;i++)
{
cout<<" PARKED CAR "<<i+1<<endl<<endl;
tck.print();
cout<<endl<<endl;
if (k>0)
{
tck.showfine();
cout<<"--------------------------------------------------------------------------------"<<endl;
}
else
{
cout<<"Vehicle permitted for "<<-k/60<<" hours & "<<-k%60<<"
minutes"<<endl;
}
cout<<"================================================================================"<<endl;
}
cout<<"Officer responsible for issuing these tickets and
patroling ::"<<endl;
officer.print();
return 0;
}
windows. But I don't have LINUX installed on my system. I would be
grateful to you guys if you check whether this code is working fine on
linux. I know that C++ is independent of OS, but still check it on g++
compiler.
Thanks a lot in advance.
Anchit
CODE:
#include<iostream>
#include<string>
using namespace std;
int m=0, min, k[10], c;
class parkedcar //class holds data of the car in parking
{
string make;
int model;
string color;
string licnumber;
int minutesparked;
public:
parkedcar()
{
make=" ";
model=0;
licnumber=" ";
color=" ";
minutesparked=0;
}
void setmake(string mk)
{
make=mk;
}
void setmodel(int ml)
{
model=ml;
}
void setcolor(string c)
{
color=c;
}
void setlicnumber(string l)
{
licnumber=l;
}
void setminutesparked(int mnp)
{
minutesparked=mnp;
}
string getmake() const
{
return (make);
}
int getmodel() const
{
return (model);
}
string getcolor() const
{
return (color);
}
string getlicnumber() const
{
return (licnumber);
}
int getminutesparked() const
{
return (minutesparked);
}
void print();
};
void parkedcar:rint() //outside class definition
{
cout<<"Car Make :"<<getmake()<<endl;
cout<<"Car Model :"<<getmodel()<<endl;
cout<<"Car License Number :"<<getlicnumber()<<endl;
cout<<"Car Color :"<<getcolor()<<endl;
}
class parkingticket: public parkedcar //class calculates and shows
fine (if any)
{
int fine;
int minutes;
void calfine(); //helper function, calculates fine
public:
void showfine(); //function to show the fine
void getticket (int min) //calls the helper function calfine()
{
minutes=min;
calfine();
cout<<endl;
}
int getfine() const
{
return(fine);
}
};
void parkingticket::calfine() //outside class definition
{
if(minutes/60<=0)
{
fine = 45;
}
else
{
int mn;
mn=minutes - 60;
fine = 45 + 30 + 30*(mn/60);
}
}
void parkingticket::showfine() //outside class definition
{
cout<<" ILLEGAL PARKING"<<endl;
cout<<" Time in violation is "<<minutes/60<<" hours & "<<minutes
%60<<" minutes "<<endl;
cout<<" Fine : Rs. "<<getfine()<<endl;
}
parkingticket tck[10]; //Parking ticket array of objects created
class parkingmeter //This class take carea of number of minutes
purchased
{
int minpurchased;
public:
parkingmeter()
{
minpurchased=0;
}
void setminpurchased(int m)
{
minpurchased=m;
}
int getminpurchased() const
{
return(minpurchased);
}
void print()
{
cout<<"Mins purchased are"<<getminpurchased();
}
};
class policeofficer //Responsible for patrolling and issuing
parkingticket
{ //in case vehicle is illegally parked
string name;
string badgenumber;
parkingticket *ticket; //Pointer of the type parkingticket class
public:
policeofficer()
{
name=" ";
badgenumber=" ";
ticket = NULL;
}
void setname(string n)
{
name=n;
}
void setbadgenumber(string b)
{
badgenumber=b;
}
string getname() const
{
return(name);
}
string getbadgenumber() const
{
return(badgenumber);
}
parkingticket* patrol(parkingticket pc1, parkingmeter pc2) //Patrol
function
{
if ( pc1.getminutesparked() < pc2.getminpurchased() ||
pc1.getminutesparked() == pc2.getminpurchased() )
{
return NULL; //No crimes
}
else //Illegal parking
{
tck[m].getticket(pc1.getminutesparked() - pc2.getminpurchased());
cout<<"--------------------------------------------------------------------------------"<<endl;
tck[m].showfine();
ticket=&tck[m];
return(ticket);
}
}
void print()
{
cout<<"Name: "<<getname()<<endl;
cout<<"Badge Number: "<<getbadgenumber()<<endl;
}
};
void intro()
{
cout<<"********************************************************************************"<<endl;
cout<<" THIS IS PARKING TICKET SIMULATOR"<<endl;
cout<<"********************************************************************************"<<endl;
}
void choice()
{
cin>>c;
if(c==0)
{
m++;
}
else if(c==1)
{
}
else
{
cout<<"Invalid Entry, try again :"<<endl;
choice();
}
}
int main()
{
system("cls");
int i=0, y;
intro();
cout<<"PARKING RATES ::"<<endl;
cout<<"Parking rate is Rs. 25 for 60 minutes"<<endl;
cout<<endl<<endl;
cout<<"FINE RATES ::"<<endl;
cout<<"In case number of minutes car has been parked exceeds the
number of minutes purchased, then a fine is applied."<<endl;
cout<<"Rs 45 for first hour or part of an hour that the car is
illegally parked and Rs 30 for every additional hour or part of an
hour that the car is illegally parked."<<endl;
cout<<"________________________________________________________________________________"<<endl;
policeofficer officer; //Police Officer object created
string pname, pbadge;
cout<<"OFFICER'S INFORMATION ::"<<endl;
cout<<"Name: ";
cin>>pname;
cout<<"Badge Number: ";
cin>>pbadge;
officer.setname(pname);
officer.setbadgenumber(pbadge);
parkingmeter meter[10]; //Parking meter array of objects created
parkingticket* ticket = NULL;
do //Iteration of statements
{
system("cls");
intro();
cout<<"PARKED CAR'S INFORMATION ::"<<endl; //Officer inputs the data
of the car
string mk;
cout<<"Make :";
cin>>mk;
tck[m].setmake(mk);
int mod;
cout<<"Model :";
cin>>mod;
tck[m].setmodel(mod);
string lic;
cout<<"License number :";
cin>>lic;
y=0;
while(y<=m)
{
if (y!=m)
{
if (lic == tck[y].getlicnumber()) //License number being a
primary key
{
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Car with this License Number already exists"<<endl;
tck[y].print();
cout<<"-------------------------------------------------------------------------------"<<endl;
cout<<"Try re-entering the license number :";
cin>>lic;
}
}
y++;
}
tck[m].setlicnumber(lic);
string col;
cout<<"Color :";
cin>>col;
tck[m].setcolor(col);
int parmin; //The number of minutes a car has been parked
cout<<"Minutes in parking :";
cin>>parmin;
tck[m].setminutesparked(parmin);
int purmin; //The number of minutes purchased
cout<<"Minutes purchased :";
cin>>purmin;
meter[m].setminpurchased(purmin);
system("cls");
intro();
ticket = officer.patrol(tck[m], meter[m]); //The officer patrols
if(ticket==NULL)
{
// Display the ticket information.
tck[m].print();
cout<<endl;
cout<<endl;
cout<<"----------------------"<<endl;
cout<<"| NO CRIMES COMMITTED |"<<endl;
cout<<"----------------------"<<endl;
}
else
{
cout<<endl<<"Non-permitted vehicle ::"<<endl;
ticket->print(); // Display the ticket information.
cout<<"--------------------------------------------------------------------------------"<<endl;
ticket = NULL;
}
k[m] = tck[m].getminutesparked() - meter[m].getminpurchased();
cout<<endl<<endl<<endl<<endl<<endl;
cout<<"________________________________________________________________________________"<<endl;
cout<<"Enter your choice -"<<endl;
cout<<"0 - Patrol another car 1 - View cars patrolled"<<endl;
choice();
}while (c == 0);
system("cls");
intro();
for(i=0;i<=m;i++)
{
cout<<" PARKED CAR "<<i+1<<endl<<endl;
tck.print();
cout<<endl<<endl;
if (k>0)
{
tck.showfine();
cout<<"--------------------------------------------------------------------------------"<<endl;
}
else
{
cout<<"Vehicle permitted for "<<-k/60<<" hours & "<<-k%60<<"
minutes"<<endl;
}
cout<<"================================================================================"<<endl;
}
cout<<"Officer responsible for issuing these tickets and
patroling ::"<<endl;
officer.print();
return 0;
}