C++ programming toll plaza simulation program
So the code is;
#include<iostream>
using namespace std;
#define Toll=10.50
#define ESC=27
class tollplaza
{
private:
int totalcar;
double totalcash;
public: tollplaza()
{
totalcar=0;
totalcash=0.0;
}
void payingcar()
{
totalcash=totalcash+Toll;
totalcar=totalcar+1;
}
void nonpayingcar()
{
totalcar++;
}
void printcardetail()
{
cout<<"totalcash";
cout<<"totalcar";
}
};
int main()
{
tollplaza plaza1;
char ch;
cout<<"Press 0 for no pay car\nPress 1 for pay car\nPress ESC to exit program";
do {
cin>>ch;
if(ch=='0')
{
plaza1.nonpayingcar();
}
else if(ch=='1')
{
plaza1.printcardetail();
}
} while(ch!=ESC);
plaza1.printcardetail();
return 0;
}
#include<iostream>
using namespace std;
#define Toll=10.50
#define ESC=27
class tollplaza
{
private:
int totalcar;
double totalcash;
public: tollplaza()
{
totalcar=0;
totalcash=0.0;
}
void payingcar()
{
totalcash=totalcash+Toll;
totalcar=totalcar+1;
}
void nonpayingcar()
{
totalcar++;
}
void printcardetail()
{
cout<<"totalcash";
cout<<"totalcar";
}
};
int main()
{
tollplaza plaza1;
char ch;
cout<<"Press 0 for no pay car\nPress 1 for pay car\nPress ESC to exit program";
do {
cin>>ch;
if(ch=='0')
{
plaza1.nonpayingcar();
}
else if(ch=='1')
{
plaza1.printcardetail();
}
} while(ch!=ESC);
plaza1.printcardetail();
return 0;
}
so I made it from designing and logic part but there is some issue with the #define syntax so I cannot run it will make an update if I find a solution...
some of the previous mistakes I made like writing public payingcar instead of void payingcar and declaring in totalcar member function before making it public...silly of me
so here is the program that works:
#include<iostream>
using namespace std;
//#define toll 10.5
//#define ESC 27
class tollplaza
{
private:
double toll;
int totalcar;
double totalcash;
public: tollplaza()
{
totalcar=0;
totalcash=0.0;
toll=10.5;
}
void payingcar()
{
totalcash=totalcash+toll;
totalcar=totalcar+1;
}
void nonpayingcar()
{
totalcar++;
}
void printcardetail()
{
cout<<"\ntotalcash:"<<totalcash;
cout<<"\ntotalcar:"<<totalcar;
}
};
int main()
{
tollplaza plaza1;
char ch;
cout<<"\nPress 0 for no pay car\nPress 1 for pay car\nPress 2 to exit program\n";
do {
cin>>ch;
if(ch=='0')
{
plaza1.nonpayingcar();
}
else if(ch=='1')
{
plaza1.payingcar();
}
} while(ch!='2');
plaza1.printcardetail();
return 0;
}
so here is the program that works:
#include<iostream>
using namespace std;
//#define toll 10.5
//#define ESC 27
class tollplaza
{
private:
double toll;
int totalcar;
double totalcash;
public: tollplaza()
{
totalcar=0;
totalcash=0.0;
toll=10.5;
}
void payingcar()
{
totalcash=totalcash+toll;
totalcar=totalcar+1;
}
void nonpayingcar()
{
totalcar++;
}
void printcardetail()
{
cout<<"\ntotalcash:"<<totalcash;
cout<<"\ntotalcar:"<<totalcar;
}
};
int main()
{
tollplaza plaza1;
char ch;
cout<<"\nPress 0 for no pay car\nPress 1 for pay car\nPress 2 to exit program\n";
do {
cin>>ch;
if(ch=='0')
{
plaza1.nonpayingcar();
}
else if(ch=='1')
{
plaza1.payingcar();
}
} while(ch!='2');
plaza1.printcardetail();
return 0;
}
Comments
Post a Comment
Feel free to leave a comment...