Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. #include<iostream>
  2. #include<fstream>
  3. #include<stdio.h>
  4. #include<stdlib.h>
  5. #include<string>
  6. #include<conio.h>
  7. using namespace std;
  8. class hotel
  9. {
  10.  
  11. int room_no;
  12. char name[30];
  13. char phone[10];
  14.  
  15. public:
  16. void main_menu();
  17. void add();
  18. void rooms();
  19. void modify();
  20. void delete_rez();
  21. int check(int);
  22.  
  23.  
  24.  
  25. };
  26.  
  27. void hotel::main_menu()
  28. {
  29. int choice=0;
  30. while(choice!=5)
  31. {
  32.  
  33.  
  34. int choice;
  35. cout<<"\n\tMeniu\n";
  36. cout<<"1.Rezerva o camera.\n";
  37. cout<<"2.Modificati rezervarea.\n";
  38. cout<<"3.Camere ocupate\n";
  39. cout<<"4.Stergere rezervare\n";
  40. cout<<"5.Exit\n";
  41. cout<<"Intruduceti alegerea dumneavoastra.\n";
  42. cin>>choice;
  43.  
  44. switch(choice)
  45. {
  46. case 1: add();
  47. break;
  48. case 2: modify();
  49. break;
  50. case 3: rooms();
  51. break;
  52. case 4: delete_rez();
  53. break;
  54. case 5: exit(1);
  55. default:
  56. {
  57. cout<<"\nOptiune incorecta\n";
  58. cout<<"Apasa tasta s pentru a continua!\n";
  59. getch();
  60. }
  61. }
  62. }
  63. }
  64.  
  65. void hotel::add()
  66. {
  67.  
  68. int r,flag;
  69. ofstream fout("Record.dat",ios::app);
  70.  
  71. cout<<"Detalii client:\n";
  72. cout<<"***************\n";
  73.  
  74. cout<<"Numarul camerei: \n";
  75. cin>>r;
  76. flag=check(r);
  77.  
  78. if(flag)
  79. cout<<"Camere deja ocupata\n";
  80.  
  81. else
  82. {
  83. room_no=r;
  84. cout<<endl;
  85. cout<<"Nume:";
  86. cin>>name;
  87. cout<<endl;
  88. cout<<"Telefon:";
  89. cin>>phone;
  90. fout.write((char*)this,sizeof(hotel));
  91. cout<<"Ati rezervat camera. \n";
  92. }
  93.  
  94. cout<<" Apasa tasta s pentru a continua!\n";
  95. getch();
  96. fout.close();
  97. }
  98.  
  99.  
  100.  
  101. int hotel::check(int r)
  102. {
  103. int flag=0;
  104. ifstream fin("Record.dat",ios::in);
  105. while(!fin.eof())
  106. {
  107. fin.read((char*)this,sizeof(hotel));
  108. if(room_no==r)
  109. {
  110. flag=1;
  111. break;
  112. }
  113. }
  114.  
  115. fin.close();
  116. return(flag);
  117. }
  118.  
  119.  
  120. void hotel::modify()
  121. {
  122. long pos, flag=0;
  123. int r;
  124. cout<<"Numarul camerei:";
  125. cin>>r;
  126. cout<<endl;
  127. fstream file("Record.dat",ios::in|ios::out|ios::binary);
  128. while(!file.eof())
  129. {
  130. pos=file.tellg();
  131. file.read((char*)this,sizeof(hotel));
  132. if(room_no==r)
  133. {
  134. cout<<"\nIntroduceti noi detalii:";
  135. cout<<endl;
  136. cout<<"**************************\n";
  137. cout<<"Nume:";
  138. cin>>name;
  139. cout<<"Telefon:";
  140. cin>>phone;
  141. file.seekg(pos);
  142. file.write((char*)this,sizeof(hotel));
  143. cout<<"Date modificate";
  144. flag=1;
  145. break;
  146.  
  147. }
  148. }
  149.  
  150. if(flag==0)
  151. cout<<"Aceasta camera este ocupata";
  152. file.close();
  153. }
  154.  
  155. void hotel::rooms()
  156. {
  157. ifstream file("Record.dat",ios::in);
  158. cout<<"\nCamere rezervate:";
  159. cout<<"\n****************\n";
  160. while(!file.eof())
  161. {
  162. file.read((char*)this,sizeof(hotel));
  163. cout<<"\n Camera: "<<room_no<<"\n Name: "<<name;
  164. cout<<"\n Telefon: "<<phone;
  165.  
  166. }
  167.  
  168. cout<<"\n Apasa s pentru a continua!";
  169. getch();
  170. file.close();
  171.  
  172.  
  173. }
  174.  
  175. void hotel:: delete_rez()
  176. {
  177. int flag=0;
  178. char ch;
  179. int r;
  180. cout<<"Numar camera:";
  181. cin>>r;
  182. ifstream fin("Record.dat",ios::in);
  183. ofstream fout("temp.dat",ios::out);
  184. while(!fin.eof())
  185. {
  186. fin.read((char*)this,sizeof(hotel));
  187. if(room_no==r)
  188. {
  189. cout<<"\n Nume: "<<name;
  190. cout<<"\n Telefon: "<<phone;
  191. cout<<"\n\n Do you want to delete this record(y/n): ";
  192. cin>>ch;
  193.  
  194. if(ch=='n')
  195. fout.write((char*)this,sizeof(hotel));
  196. flag=1;
  197. }
  198. else
  199. fout.write((char*)this,sizeof(hotel));
  200. }
  201.  
  202. fin.close();
  203. fout.close();
  204. if(flag==0)
  205. cout<<"\n Camera nu este rezervata.";
  206. else
  207. {
  208. remove("Record.dat");
  209. rename("temp.dat","Record.dat");
  210. }
  211. }
  212.  
  213. int main()
  214. {
  215. hotel h;
  216.  
  217.  
  218. h.main_menu();
  219. return 0;
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement