Guest User

Untitled

a guest
Nov 30th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. #include<fstream>
  2. #include<conio.h>
  3. #include<stdio.h>
  4. #include<math.h>
  5. #include<string.h>
  6. #include<process.h>
  7. #include<iostream>
  8. #include<stdlib.h>
  9.  
  10. using namespace std;
  11.  
  12. void clrscr() //Implementing clrscr() in C++ GNU GCC COMPILER
  13. {
  14. system("cls");
  15. }
  16.  
  17.  
  18.  
  19. class train
  20. {
  21. public:
  22. int tno;
  23. char tname[100];
  24. char source[100];
  25. char dest[100];
  26. int PerSeatFare;
  27.  
  28. public:
  29. void getdetail()
  30. {
  31. cout<<"Enter the details as follows\n";
  32. cout<<"Train no:";
  33. cin>>tno;
  34. cin.ignore();
  35. cout<<"Train name:";
  36. gets(tname);
  37. cout<<"Train Source Station:";
  38. gets(source);
  39. cout<<"Tarin Destination Station:";
  40. gets(dest);
  41. cout<<"Fare per seat in train :";
  42. cin>>PerSeatFare;
  43. }
  44. void showdetail()
  45. {
  46. cout<<tno<<"\t"<<tname<<"\t"<<source<<"\t"<<dest<<"\t";
  47. cout<<PerSeatFare;
  48. }
  49. }t;
  50. void storetrain()
  51. {
  52. fstream f;
  53. train t;
  54. f.open("trains.dat",ios::app | ios::binary);
  55. t.getdetail();
  56. f.write((char*)&t,sizeof(t));
  57. f.close();
  58. }
  59. void showalltrain()
  60. {
  61. fstream f;
  62. f.open("trains.dat",ios::in | ios::binary);
  63. train t;
  64. while(f.read((char*)&t,sizeof(t)))
  65. {
  66. t.showdetail();
  67. cout<<endl;
  68. }
  69. getch();
  70. f.close();
  71. }
  72.  
  73. class reserv //Assume that cust select train according to his source and destination.
  74. {
  75.  
  76. public:
  77. int pnr;
  78. int tno;
  79. char tname[100];
  80. char pnames[10][100];
  81. int ages[10];
  82. int SeatNum;
  83. int i;
  84. int d,m,y;
  85. float amt;
  86. char bp[100],dest[100];
  87. void updt_tick()
  88. {
  89. fstream f;
  90. f.open("train.dat",ios::in | ios::binary);
  91. while(f.read((char*)&t,sizeof(t)))
  92. {
  93. if (tno==t.tno)
  94. {
  95. strcpy(bp,t.source);
  96. strcpy(dest,t.dest);
  97. strcpy(tname,t.tname);
  98. amt=SeatNum*t.PerSeatFare;
  99. break;
  100. }
  101. }
  102. f.close();
  103. }
  104.  
  105. public:
  106. void getresdet()
  107. {
  108. cout<<"Enter the details as follows\n";
  109. cout<<"Train no:";
  110. cin>>tno;
  111. cout<<"No of seats required:";
  112. cin>>SeatNum;
  113. cin.ignore();
  114. for(i=0; i<SeatNum ; i++)
  115. {
  116. cout<<"Passenger name:";
  117. gets(pnames[i]);
  118. cout<<"Passenger age:";
  119. cin>>ages[i];
  120. cin.ignore();
  121. }
  122. cout<<"Date of travel:";
  123. cin>>d>>m>>y;
  124. cout<<"Details Accepted\n";
  125. pnr=rand();
  126. updt_tick();
  127. }
  128. void showresdet()
  129. {
  130. cout<<"Pnr no:"<<pnr;
  131. cout<<"\nTrain no:"<<tno;
  132. cout<<"\nTrain name:";
  133. puts(tname);
  134. cout<<"Boarding point:";
  135. puts(bp);
  136. cout<<"Destination pt:";
  137. puts(dest);
  138. cout<<"No of seats reserved:"<<SeatNum;
  139. for(i=0; i<SeatNum; i++)
  140. {
  141. cout<<"Passenger name:";
  142. puts(pnames[i]);
  143. cout<<"Passenger age:"<<ages[i];
  144. }
  145. cout<<"\nDate of reservation:"<<d<<"-"<<m<<"-"<<y;
  146. cout<<"\nYou must pay:"<<amt<<endl;
  147. }
  148. int getpnr()
  149. {
  150. return pnr;
  151. }
  152. };
  153. void showticketbypnr()
  154. {
  155. fstream f;
  156. reserv r;
  157. int flag=0,pnr;
  158. cout<<"\nPlease enter your PNR :";
  159. cin>>pnr;
  160. f.open("reservations.dat",ios::in | ios::binary);
  161. while(f.read((char*)&r,sizeof(r)))
  162. {
  163. if(pnr==r.getpnr())
  164. {
  165. cout<<"Your details are as follows :\n";
  166. r.showresdet();
  167. flag=1;
  168. break;
  169. }
  170. }
  171. if(flag==0)
  172. {
  173. cout<<"This PNR was not found in our database !";
  174. }
  175. f.close();
  176. getch();
  177. }
  178. void bookticket()
  179. {
  180. reserv r;
  181. fstream f;
  182. f.open("reservations.dat",ios::app | ios::in | ios::binary);
  183. r.getresdet();
  184. f.write((char*)&r,sizeof(r));
  185. cout<<"Ticket is Booked";
  186. cout<<"Your details are as follows :\n";
  187. r.showresdet();
  188. getch();
  189. f.close();
  190. }
  191. void menu()
  192. {
  193. int opt,opt1,opt2;
  194. while(1){
  195. clrscr();
  196. cout<<"1.)Administrator Menu\n2.)Passenger Menu\n3.)Exit\n\nEnter your choice :";
  197. cin>>opt;
  198. if(opt==3)
  199. exit(0);
  200. else if(opt==1)
  201. {
  202. clrscr();
  203. cout<<"1.)Add new train to database\n2.)Show all trains in database\n3.)Modify a train information\n4.)Exit\n\nEnter your choice :";
  204. cin>>opt1;
  205. switch(opt1)
  206. {
  207. case 1:storetrain();
  208. break;
  209. case 2:showalltrain();
  210. break;
  211. case 3:break;
  212. default:cout<<"Inavalid choice";
  213. }
  214. }
  215. else if(opt==2)
  216. {
  217. clrscr();
  218. cout<<"Passenger Menu";
  219. cout<<"\n\n\t1.)Book a Ticket\n\t2.)Check ticket info by pnr\n\t3.)Exit";
  220. cin>>opt2;
  221. switch(opt2)
  222. {
  223. case 1:bookticket();
  224. break;
  225. case 2:showticketbypnr();
  226. break;
  227. case 3:
  228. default:break;
  229. }
  230. }
  231.  
  232.  
  233. } //Outermost while bracket
  234. }
  235. int main()
  236. {
  237. clrscr();
  238. /*train t;
  239. //storetrain();
  240. //storetrain();
  241. showalltrain();
  242. reserv r;
  243. bookticket();*/
  244. menu();
  245. return 0;
  246. }
Add Comment
Please, Sign In to add comment