#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <graphics.h>
#include <stdlib.h>
#include <ctype.h>
//#include <dos.h>
typedef enum{false,true}boolean;
static int p = 0;
class a
{
char busn[5], driver[10], arrival[5], depart[5], from[10], to[10], seat[8][4][10];
public:
void install();
void allotment();
void empty();
void show();
void avail();
void position(int i);
}
bus[10];
void vline(char ch)
{
for (int i=80;i>0;i--)
cout<<ch;
}
void a::install()
{
cout<<"Enter bus no: ";
cin>>bus[p].busn;
cout<<"\nEnter Driver's name: ";
cin>>bus[p].driver;
// cin>>bus[p].arrival;
//==================
char temp[20];
boolean OK;
do{
OK = true;
cout<<"\nArrival time: ";
gets(bus[p].arrival);
if (strlen(bus[p].arrival)!=4){
printf("\t\t<< should not be Empty or It should \n\t\t only 4 digits >>\n");
OK= false;
}
for(int count=0; bus[p].arrival[count]!='\0'; count++)
if (!isdigit(bus[p].arrival[count])){
printf("\t\t<< Must be digits! >>\n");
OK = false;
// strcpy(bus[p].arrival,temp[count]);
break;
}
}while(!OK);
//////////////////
cout<<"\nDeparture: ";
cin>>bus[p].depart;
cout<<"\nFrom: \t\t\t";
cin>>bus[p].from;
cout<<"\nTo: \t\t\t";
cin>>bus[p].to;
bus[p].empty();
p++;
}
void a::allotment()
{
int seat;
char number[5];
top:
cout<<"Bus no: ";
cin>>number;
int n;
for(n=0;n<=p;n++)
{
if(strcmp(bus[n].busn, number)==0)
break;
}
while(n<=p)
{
cout<<"\nSeat Number: ";
cin>>seat;
if(seat>32)
{
cout<<"\nThere are only 32 seats available in this bus.";
}
else
{
if (strcmp(bus[n].seat[seat/4][(seat%4)-1], "Empty")==0)
{
cout<<"Enter passanger's name: ";
cin>>bus[n].seat[seat/4][(seat%4)-1];
break;
}
else
cout<<"The seat no. is already reserved.\n";
}
}
if(n>p)
{
cout<<"Enter correct bus no.\n";
goto top;
}
}
void a::empty()
{
for(int i=0; i<8;i++)
{
for(int j=0;j<4;j++)
{
strcpy(bus[p].seat[i][j], "Empty");
}
}
}
void a::show()
{
int n;
char number[5];
cout<<"Enter bus no: ";
cin>>number;
for(n=0;n<=p;n++)
{
if(strcmp(bus[n].busn, number)==0)
break;
}
while(n<=p)
{
vline('*');
cout<<"Bus no: \t"<<bus[n].busn
<<"\nDriver: \t"<<bus[n].driver<<"\t\tArrival time: \t"
<<bus[n].arrival<<"\tDeparture time:"<<bus[n].depart
<<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t"<<
bus[n].to<<"\n";
vline('*');
bus[0].position(n);
int a=1;
for (int i=0; i<8; i++)
{
for(int j=0;j<4;j++)
{
a++;
if(strcmp(bus[n].seat[i][j],"Empty")!=0)
cout<<"\nThe seat no "<<(a-1)<<" is reserved for "<<bus[n].seat[i][j]<<".";
}
}
break;
}
if(n>p)
cout<<"Enter correct bus no: ";
}
void a::position(int l)
{
int s=0;p=0;
for (int i =0; i<8;i++)
{
cout<<"\n";
for (int j = 0;j<4; j++)
{
s++;
if(strcmp(bus[l].seat[i][j], "Empty")==0)
{
cout.width(5);
cout.fill(' ');
cout<<s<<".";
cout.width(10);
cout.fill(' ');
cout<<bus[l].seat[i][j];
p++;
}
else
{
cout.width(5);
cout.fill(' ');
cout<<s<<".";
cout.width(10);
cout.fill(' ');
cout<<bus[l].seat[i][j];
}
}
}
cout<<"\n\nThere are "<<p<<" seats empty in Bus No: "<<bus[l].busn;
}
void a::avail()
{
for(int n=0;n<p;n++)
{
vline('*');
cout<<"Bus no: \t"<<bus[n].busn<<"\nDriver: \t"<<bus[n].driver
<<"\t\tArrival time: \t"<<bus[n].arrival<<"\tDeparture Time: \t"
<<bus[n].depart<<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t\t"
<<bus[n].to<<"\n";
vline('*');
vline('_');
}
}
void main()
{
clrscr();
int w;
int gd=DETECT, gm;
initgraph(&gd, &gm, "f:\\borlandc\\bgi");
setbkcolor(BLUE);
while(1)
{
cout<<"\n\n\n\n\n";
cout<<"\t\t\t1.Install\n\t\t\t"
<<"2.Reservation\n\t\t\t"
<<"3.Show\n\t\t\t"
<<"4.Buses Available. \n\t\t\t"
<<"5.Exit";
cout<<"\n\t\t\tEnter your choice:-> ";
cin>>w;
switch(w)
{
case 1: bus[p].install();
break;
case 2: bus[p].allotment();
break;
case 3: bus[0].show();
break;
case 4: bus[0].avail();
break;
case 5: exit(0);
case 6:
if(w>6)
cout<<"Incorrect Option";
//cleardevice();
}
}
//while(w>0&&w<=5) ;
}
reyaanhelp -6 Newbie Poster
csurfer 422 Posting Pro
Please Note:
You are using a completely outdated compiler because it is letting you use "conio"
"clrscr"
and all the ".h"
extensions. Get a standard compiler.
You have just posted the code and the line "How to convert Structure in class" that too with a spelling mistake and that doesn't explain your needs at all because I see no structure.
If you want help please write in what exact help you want from us and do it in a way people can understand.
tux4life 2,072 Postaholic
And an addition to csurfer's post:
Get rid of that void main(), it's evil!
Change void main() to int main().
>How to convert structure to class in C++?
Theoretically in C++ a structure is a class.
Edit:: BTW, is your code working? As I cannot compile this crap on my compiler.
reyaanhelp -6 Newbie Poster
I'm a beginner and trying to convert this code in class.I want this code in a class form.kindly do it for me.
And if anyone have "bus reservation system" c++ code in classes format then please give it to me.
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
#include <string.h>
#include <graphics.h>
#include <stdlib.h>
#include <ctype.h>
//#include <dos.h>
typedef enum{false,true}boolean;
static int p = 0;
struct a
{
char busn[5], driver[10], arrival[5], depart[5], from[10], to[10], seat[8][4][10];
public:
void install();
void allotment();
void empty();
void show();
void avail();
void position(int i);
}
bus[10];
void vline(char ch)
{
for (int i=80;i>0;i--)
cout<<ch;
}
void a::install()
{
cout<<"Enter bus no: ";
cin>>bus[p].busn;
cout<<"\nEnter Driver's name: ";
cin>>bus[p].driver;
// cin>>bus[p].arrival;
//==================
char temp[20];
boolean OK;
do{
OK = true;
cout<<"\nArrival time: ";
gets(bus[p].arrival);
if (strlen(bus[p].arrival)!=4){
printf("\t\t<< should not be Empty or It should \n\t\t only 4 digits >>\n");
OK= false;
}
for(int count=0; bus[p].arrival[count]!='\0'; count++)
if (!isdigit(bus[p].arrival[count])){
printf("\t\t<< Must be digits! >>\n");
OK = false;
// strcpy(bus[p].arrival,temp[count]);
break;
}
}while(!OK);
//////////////////
cout<<"\nDeparture: ";
cin>>bus[p].depart;
cout<<"\nFrom: \t\t\t";
cin>>bus[p].from;
cout<<"\nTo: \t\t\t";
cin>>bus[p].to;
bus[p].empty();
p++;
}
void a::allotment()
{
int seat;
char number[5];
top:
cout<<"Bus no: ";
cin>>number;
int n;
for(n=0;n<=p;n++)
{
if(strcmp(bus[n].busn, number)==0)
break;
}
while(n<=p)
{
cout<<"\nSeat Number: ";
cin>>seat;
if(seat>32)
{
cout<<"\nThere are only 32 seats available in this bus.";
}
else
{
if (strcmp(bus[n].seat[seat/4][(seat%4)-1], "Empty")==0)
{
cout<<"Enter passanger's name: ";
cin>>bus[n].seat[seat/4][(seat%4)-1];
break;
}
else
cout<<"The seat no. is already reserved.\n";
}
}
if(n>p)
{
cout<<"Enter correct bus no.\n";
goto top;
}
}
void a::empty()
{
for(int i=0; i<8;i++)
{
for(int j=0;j<4;j++)
{
strcpy(bus[p].seat[i][j], "Empty");
}
}
}
void a::show()
{
int n;
char number[5];
cout<<"Enter bus no: ";
cin>>number;
for(n=0;n<=p;n++)
{
if(strcmp(bus[n].busn, number)==0)
break;
}
while(n<=p)
{
vline('*');
cout<<"Bus no: \t"<<bus[n].busn
<<"\nDriver: \t"<<bus[n].driver<<"\t\tArrival time: \t"
<<bus[n].arrival<<"\tDeparture time:"<<bus[n].depart
<<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t"<<
bus[n].to<<"\n";
vline('*');
bus[0].position(n);
int a=1;
for (int i=0; i<8; i++)
{
for(int j=0;j<4;j++)
{
a++;
if(strcmp(bus[n].seat[i][j],"Empty")!=0)
cout<<"\nThe seat no "<<(a-1)<<" is reserved for "<<bus[n].seat[i][j]<<".";
}
}
break;
}
if(n>p)
cout<<"Enter correct bus no: ";
}
void a::position(int l)
{
int s=0;p=0;
for (int i =0; i<8;i++)
{
cout<<"\n";
for (int j = 0;j<4; j++)
{
s++;
if(strcmp(bus[l].seat[i][j], "Empty")==0)
{
cout.width(5);
cout.fill(' ');
cout<<s<<".";
cout.width(10);
cout.fill(' ');
cout<<bus[l].seat[i][j];
p++;
}
else
{
cout.width(5);
cout.fill(' ');
cout<<s<<".";
cout.width(10);
cout.fill(' ');
cout<<bus[l].seat[i][j];
}
}
}
cout<<"\n\nThere are "<<p<<" seats empty in Bus No: "<<bus[l].busn;
}
void a::avail()
{
for(int n=0;n<p;n++)
{
vline('*');
cout<<"Bus no: \t"<<bus[n].busn<<"\nDriver: \t"<<bus[n].driver
<<"\t\tArrival time: \t"<<bus[n].arrival<<"\tDeparture Time: \t"
<<bus[n].depart<<"\nFrom: \t\t"<<bus[n].from<<"\t\tTo: \t\t\t"
<<bus[n].to<<"\n";
vline('*');
vline('_');
}
}
void main()
{
clrscr();
int w;
int gd=DETECT, gm;
initgraph(&gd, &gm, "f:\\borlandc\\bgi");
setbkcolor(BLUE);
while(1)
{
cout<<"\n\n\n\n\n";
cout<<"\t\t\t1.Install\n\t\t\t"
<<"2.Reservation\n\t\t\t"
<<"3.Show\n\t\t\t"
<<"4.Buses Available. \n\t\t\t"
<<"5.Exit";
cout<<"\n\t\t\tEnter your choice:-> ";
cin>>w;
switch(w)
{
case 1: bus[p].install();
break;
case 2: bus[p].allotment();
break;
case 3: bus[0].show();
break;
case 4: bus[0].avail();
break;
case 5: exit(0);
case 6:
if(w>6)
cout<<"Incorrect Option";
//cleardevice();
}
}
//while(w>0&&w<=5) ;
}
jephthah commented: I'm not that kind of guy. -2
Tom Gunn 1,164 Practically a Master Poster
I'm a beginner and trying to convert this code in class.
It's already a class. The only difference between struct and class in C++ is the default access rights. struct is public by default and class is private.
kindly do it for me.
Sorry my friend, but it doesn't work that way here. Kindly do it yourself and everyone here will kindly help you. ;)
csurfer 422 Posting Pro
kindly do it for me and please give it to me these are the two things we hate. We will neither do both.You do it and we will help.
And why the conversion from post #1 to post #4 ??? you had it in the form of a class only then.You messed it up later...Go on with the thing you have written in post #1 and continue and we are here to help you if you get any errors.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.