Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<fstream>
- #include<stdio.h>
- #include<stdlib.h>
- #include<string>
- #include<conio.h>
- using namespace std;
- class hotel
- {
- int room_no;
- char name[30];
- char phone[10];
- public:
- void main_menu();
- void add();
- void rooms();
- void modify();
- void delete_rez();
- int check(int);
- };
- void hotel::main_menu()
- {
- int choice=0;
- while(choice!=5)
- {
- int choice;
- cout<<"\n\tMeniu\n";
- cout<<"1.Rezerva o camera.\n";
- cout<<"2.Modificati rezervarea.\n";
- cout<<"3.Camere ocupate\n";
- cout<<"4.Stergere rezervare\n";
- cout<<"5.Exit\n";
- cout<<"Intruduceti alegerea dumneavoastra.\n";
- cin>>choice;
- switch(choice)
- {
- case 1: add();
- break;
- case 2: modify();
- break;
- case 3: rooms();
- break;
- case 4: delete_rez();
- break;
- case 5: exit(1);
- default:
- {
- cout<<"\nOptiune incorecta\n";
- cout<<"Apasa tasta s pentru a continua!\n";
- getch();
- }
- }
- }
- }
- void hotel::add()
- {
- int r,flag;
- ofstream fout("Record.dat",ios::app);
- cout<<"Detalii client:\n";
- cout<<"***************\n";
- cout<<"Numarul camerei: \n";
- cin>>r;
- flag=check(r);
- if(flag)
- cout<<"Camere deja ocupata\n";
- else
- {
- room_no=r;
- cout<<endl;
- cout<<"Nume:";
- cin>>name;
- cout<<endl;
- cout<<"Telefon:";
- cin>>phone;
- fout.write((char*)this,sizeof(hotel));
- cout<<"Ati rezervat camera. \n";
- }
- cout<<" Apasa tasta s pentru a continua!\n";
- getch();
- fout.close();
- }
- int hotel::check(int r)
- {
- int flag=0;
- ifstream fin("Record.dat",ios::in);
- while(!fin.eof())
- {
- fin.read((char*)this,sizeof(hotel));
- if(room_no==r)
- {
- flag=1;
- break;
- }
- }
- fin.close();
- return(flag);
- }
- void hotel::modify()
- {
- long pos, flag=0;
- int r;
- cout<<"Numarul camerei:";
- cin>>r;
- cout<<endl;
- fstream file("Record.dat",ios::in|ios::out|ios::binary);
- while(!file.eof())
- {
- pos=file.tellg();
- file.read((char*)this,sizeof(hotel));
- if(room_no==r)
- {
- cout<<"\nIntroduceti noi detalii:";
- cout<<endl;
- cout<<"**************************\n";
- cout<<"Nume:";
- cin>>name;
- cout<<"Telefon:";
- cin>>phone;
- file.seekg(pos);
- file.write((char*)this,sizeof(hotel));
- cout<<"Date modificate";
- flag=1;
- break;
- }
- }
- if(flag==0)
- cout<<"Aceasta camera este ocupata";
- file.close();
- }
- void hotel::rooms()
- {
- ifstream file("Record.dat",ios::in);
- cout<<"\nCamere rezervate:";
- cout<<"\n****************\n";
- while(!file.eof())
- {
- file.read((char*)this,sizeof(hotel));
- cout<<"\n Camera: "<<room_no<<"\n Name: "<<name;
- cout<<"\n Telefon: "<<phone;
- }
- cout<<"\n Apasa s pentru a continua!";
- getch();
- file.close();
- }
- void hotel:: delete_rez()
- {
- int flag=0;
- char ch;
- int r;
- cout<<"Numar camera:";
- cin>>r;
- ifstream fin("Record.dat",ios::in);
- ofstream fout("temp.dat",ios::out);
- while(!fin.eof())
- {
- fin.read((char*)this,sizeof(hotel));
- if(room_no==r)
- {
- cout<<"\n Nume: "<<name;
- cout<<"\n Telefon: "<<phone;
- cout<<"\n\n Do you want to delete this record(y/n): ";
- cin>>ch;
- if(ch=='n')
- fout.write((char*)this,sizeof(hotel));
- flag=1;
- }
- else
- fout.write((char*)this,sizeof(hotel));
- }
- fin.close();
- fout.close();
- if(flag==0)
- cout<<"\n Camera nu este rezervata.";
- else
- {
- remove("Record.dat");
- rename("temp.dat","Record.dat");
- }
- }
- int main()
- {
- hotel h;
- h.main_menu();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement