Question
Can someone convert this C++ code into C language . #include #include #include #define null 0 namespace train { class reserve { private: struct passenger
Can someone convert this C++ code into C language .
#include
#include
#include
#define null 0
namespace train
{
class reserve
{
private:
struct passenger
{
int seatno,age;
char na[15];
}p[10][5];
struct detail
{
int h,t,count,sr;
}d[10];
public:
reserve();
int enqueue(int);
int isqueuefull(int);
int isqueueempty(int);
int dequeue();
void display(int);
void disp();
~reserve();
};
}
#include "q1h.h"
using namespace train;
reserve::reserve()
{
for(int v=0;v<10;v++)
{
d[v].count=0;
d[v].h=0;d[v].sr=0;
d[v].t=-1;
}
}
int reserve::isqueueempty(int n3)
{
return(d[n3].count==0?1:0);
}
int reserve::isqueuefull(int n3)
{
return(d[n3].count==(3+d[n3].sr)?1:0);
}
int reserve::enqueue(int t1)
{
int i,m1,s,g,u;
char ch,ch1;
if(t1==-1)
{
disp();
cout<<"Enter the row which is to be enqueued:";
cin>>i;
i=i-1;
m1=i;
t1++;
}
else
{
m1=t1;
i=5;}
s=t1+i;
u=5+t1;
if(d[s].sr<2)
{
cout<<"
Do you belong to special reservation category say y or n:"< cin>>ch; if(ch=='y') d[s].sr++; } if(!isqueuefull(s)||!isqueuefull(m1)) { if(isqueueempty((5+m1))||(isqueuefull(m1)&&!isqueueempty((5+m1)))) { d[s].t=(d[s].t+1)%5; d[s].count++; cout<<" Enter the name of the passenger:"; cin>>p[s][d[s].t].na; cout<<" Enter the age of the passenger:"; cin>>p[s][d[s].t].age; if(p[s][d[s].t].age>110) { cout<<" INVALID DATA Enter the age of the passenger:"; cin>>p[s][d[s].t].age; } cout<<" Enter the ticket number of the passenger:"; cin>>p[s][d[s].t].seatno; } else { d[t1].t=(d[t1].t+1)%5; strcpy(p[t1][d[t1].t].na,p[u][d[u].h].na); p[t1][d[t1].t].age=p[u][d[u].h].age; p[t1][d[t1].t].seatno=p[u][d[u].h].seatno; cout<<" "< d[u].h=(d[u].h+1)%5; d[u].count--; d[t1].count++; } } else { cout<<" Queue is full. You cannot reserve......" ; if(!isqueuefull(5+m1)) { cout<<" Do you want to be in the waiting list:"; cin>>ch1; if(ch1=='y') g=enqueue(m1); } } return d[s].t; } int reserve::dequeue() { int n2,g; cout<<" Enter the queue which has to be dequeued:"; disp(); cin>>n2; n2=n2-1; if(!isqueueempty(n2)) { cout<<" The service is provided to customer "< d[n2].h=(d[n2].h+1)%5; d[n2].count=d[n2].count-1; if(!isqueueempty(n2+5)) g=enqueue(n2); } else cout<<" There are no passengers. You cannot provide service.."; return d[n2].h; } void reserve::display(int i1) { i1--; int i=d[i1].h,j=1; cout<<"======================================================="; cout<<" NAME: AGE: SEATNO: "; while(j<=d[i1].count) { cout<<" "< i=(i+1)%5; j++; } cout<<"======================================================="; } void reserve::disp() { cout<<" SEDHU EXPRESS FROM:THOOTHUKUDI TO: SALEM"; cout<<" BAGATH EXPRESS FROM:THENI TO: BANGALORE"; cout<<" HOWRAH EXPRESS FROM:AGRA TO: DELHI"; cout<<" RAJDHANI EXPRESS FROM:BIHAR TO: ORISSA"; cout<<" PANDIAN EXPRESS FROM:CHENNAI TO: TRICHY"; cout<<" Enter your choice:"< } reserve::~reserve() { } #include"q1h.h" void main() { int n,nn=1,m,t=0,k; char ch; train::reserve r; while(nn==1) { cout<<"Do you want to reserve or cancel Enter either 1 or 2:"; cin>>n; switch(n) { case 1: k=r.enqueue(-1); break; case 2: k=r.dequeue(); break; case 3: cout<<" Do you want to display all say y or n (if waiting list press w):"< cin>>ch; if(ch=='y') { m=0; while(m<5) { r.display(m); m++; } } else { r.disp();cout<<" Enter the choice";cin>>m; } if(ch=='w') r.display(5+m); if(ch=='n') r.display(m); break; } cout<<" do you want to continue press 1:"; cin>>nn; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started