1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
#include<iostream>
#include<string.h>
using namespace std;
int room[10],price;
int top;
struct hotel{
int bed;
char firstname[30],lastname[30];
hotel *next;
};
typedef struct hotel *ptr;
typedef ptr list;
hotel *push(list h,char fn[30],char ln[30],int b)
{
hotel *temp;
if(h==NULL)
{
h=new hotel;
strcpy(h->firstname,fn);
strcpy(h->lastname,ln);
h->bed=b;
h->next=NULL;
}
else
{
temp=new hotel;
strcpy(temp->firstname,fn);
strcpy(temp->lastname,ln);
temp->bed=b;
temp->next=h;
h=temp;
}
return h;
}
void push1(int r)
{
if(top==10)
{
cout<<"error:stack overflow \n";
}
else
{
top++; room[top]=r;
}
}
void print(list h,int b)
{
hotel *temp=h;
while(temp!=NULL)
{cout<<"name is:"<<temp->firstname<<"\t"<<temp->lastname<<endl;
if(b==1)
{
cout<<"price is: 1000$"<<endl;
}
if(b==2)
{
cout<<"price is: 1500$"<<endl;
}
temp=temp->next;}
}
int pop1()
{
if (pop1<0)
{
cout<<"error:stack underflow \n";
}
else
{
return room[top--];
}
}
hotel *pop(list h)
{
hotel *temp;
temp=h;
h=temp->next;
delete temp;
return h;
}
void main()
{
int b;
char fn[30],ln[30];
top=-1;
list head=NULL;
cout<<"enter your full name:";
cin>>fn>>ln;
cout<<"enterthe number of bed 1 or 2:";
cin>>b;
head=push(head,fn,ln,b);
print(head,b);
push1(1);
cout<<"room is:";
cout<<pop1();
head=pop(head);
}
|