Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone convert this C++ code into C language . #include<conio.h> #include<i

ID: 3726683 • Letter: C

Question

Can someone convert this C++ code into C language .

#include<conio.h>

#include<iostream.h>

#include<string.h>

#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:"<<endl;

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<<"

"<<p[u][d[u].h].na<<" is removed from the waiting list";

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 "<<p[n2][d[n2].h].na;

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<<"

"<<p[i1][i].na<<" "<<p[i1][i].age<<" "<<p[i1][i].seatno<<endl;

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:"<<endl;

}

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):"<<endl;

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;

}

}

Explanation / Answer

#include<stdio.h>

#include<string.h>

struct reserve

{

struct passenger

{

int seatno,age;

char na[15];

}p[10][5];

struct detail

{

int h,t,count,sr;

}d[10];

}r;

void c_reserve()

{

for(int v=0;v<10;v++)

{

r.d[v].count=0;

r.d[v].h=0;

r.d[v].sr=0;

r.d[v].t=-1;

}

}

int isqueueempty(int n3)

{

return(r.d[n3].count==0?1:0);

}

int isqueuefull(int n3)

{

return(r.d[n3].count==(3+r.d[n3].sr)?1:0);

}

void disp()

{

printf("SEDHU EXPRESS FROM:THOOTHUKUDI TO: SALEM");

printf("BAGATH EXPRESS FROM:THENI TO: BANGALORE");

printf("HOWRAH EXPRESS FROM:AGRA TO: DELHI");

printf("RAJDHANI EXPRESS FROM:BIHAR TO: ORISSA");

printf("PANDIAN EXPRESS FROM:CHENNAI TO: TRICHY");

printf("Enter your choice: ");

}

int enqueue(int t1)

{

int i,m1,s,g,u;

char ch,ch1;

if(t1==-1)

{

disp();

printf("Enter the row which is to be enqueued:");

scanf("%d",&i);

i=i-1;

m1=i;

t1++;

}

else

{

m1=t1;

i=5;

}

s=t1+i;

u=5+t1;

if(r.d[s].sr<2)

{

printf("Do you belong to special reservation category say y or n: ");

scanf("%c",&ch);

if(ch=='y')

r.d[s].sr++;

}

if(!isqueuefull(s)||!isqueuefull(m1))

{

if(isqueueempty((5+m1))||(isqueuefull(m1)&&!isqueueempty((5+m1))))

{

r.d[s].t=(r.d[s].t+1)%5;

r.d[s].count++;

printf("Enter the name of the passenger:");

scanf("%s",r.p[s][r.d[s].t].na);

printf("Enter the age of the passenger:");

scanf("%d",&r.p[s][r.d[s].t].age);

if(r.p[s][r.d[s].t].age>110)

{

printf("INVALID DATA Enter the age of the passenger:");

scanf("%d",&r.p[s][r.d[s].t].age);

}

printf("Enter the ticket number of the passenger:");

scanf("%d",&r.p[s][r.d[s].t].seatno);

}

else

{

r.d[t1].t=(r.d[t1].t+1)%5;

strcpy(r.p[t1][r.d[t1].t].na,r.p[u][r.d[u].h].na);

r.p[t1][r.d[t1].t].age=r.p[u][r.d[u].h].age;

r.p[t1][r.d[t1].t].seatno=r.p[u][r.d[u].h].seatno;

printf(" %s is removed from the waiting list",r.p[u][r.d[u].h].na);

r.d[u].h=(r.d[u].h+1)%5;

r.d[u].count--;

r.d[t1].count++;

}

}

else

{

printf("Queue is full. You cannot reserve......");

if(!isqueuefull(5+m1))

{

printf("Do you want to be in the waiting list:");

scanf("%c",&ch1);

if(ch1=='y')

g=enqueue(m1);

}

}

return r.d[s].t;

}

int dequeue()

{

int n2,g;

printf("Enter the queue which has to be dequeued:");

disp();

scanf("%d",&n2);

n2=n2-1;

if(!isqueueempty(n2))

{

printf("The service is provided to customer %s",r.p[n2][r.d[n2].h].na);

r.d[n2].h=(r.d[n2].h+1)%5;

r.d[n2].count=r.d[n2].count-1;

if(!isqueueempty(n2+5))

g=enqueue(n2);

}

else

printf("There are no passengers. You cannot provide service..");

return r.d[n2].h;

}

void display(int i1)

{

i1--;

int i=r.d[i1].h,j=1;

printf("=======================================================");

printf("NAME: AGE: SEATNO:");

while(j<=r.d[i1].count)

{

printf(" %s %d %d ",r.p[i1][i].na,r.p[i1][i].age,r.p[i1][i].seatno);

i=(i+1)%5;

j++;

}

printf("=======================================================");

}

int main()

{

int n,nn=1,m,t=0,k;

char ch;

c_reserve();

while(nn==1)

{

printf("Do you want to reserve or cancel Enter either 1 or 2:");

scanf("%d",&n);

switch(n)

{

case 1:

k=enqueue(-1);

break;

case 2:

k=dequeue();

break;

case 3:

printf("Do you want to display all say y or n (if waiting list press w): ");

scanf("%c",&ch);

if(ch=='y')

{

m=0;

while(m<5)

{

display(m);

m++;

}

}

else

{

disp();

printf("Enter the choice :");

scanf("%d",&m);

}

if(ch=='w')

display(5+m);

if(ch=='n')

display(m);

break;

}

printf(" do you want to continue press 1:");

scanf("%d",&nn);

}

return 0;

}