ИСПОЛЬЗОВАНИЕ флага = функция проверки для проверки статуса номера для проекта процесса гостиничного номера - PullRequest
0 голосов
/ 06 августа 2020

Мой запрос состоит в том, что когда я пытаюсь использовать флажок проверки для проверки статуса комнаты, он выдает ошибку. Однако и без него код работает нормально. Также была объявлена ​​функция check (int). Код также сохраняет запись и соответствующим образом редактирует журналы, если кто-то может посмотреть и проверить, что за ошибка. Я также прикрепляю ошибку компиляции, когда код запускается с "flag = check (rn)" введите здесь описание изображения

    #include<iostream>
#include<fstream>
#include<iomanip>
#include<stdio.h>
#include<conio.h>

 
using namespace std;

class Hotel
{
    char name[30], address[50],phone[10];
     int idnum,rn,room_no;
;
     public:
        int check(int);         
    void getdata();     
    void showdata() const;  
    int getIDNum() const;
}; 

void Hotel::getdata()
{
  int check(int);           
    int flag;
    cout<<"Enter The Room NO :"; cin>>rn;
    /////flag=check(rn);   ???????? Not working
    if(flag)
cout<<"\nRoom is already booked! Choose another Room!";
else
{
    room_no=rn;
    cout<<"\nEnter The ID number of the Customer: ";
    cin>>idnum;
cout<<"\n\nEnter Customers Name: ";
    cin.ignore();
    cin.getline(name,50);
    cout<<"\nEnter Address : ";
    cin>>address;
    cout<<"\nEnter Phone Number: ";
    cin>>phone;
}
}
 
void Hotel::showdata() const
{
cout<<"\nCustomer Details";
cout<<"\n----------------";
cout<<"\nName: "<<name;
cout<<"\nID No: "<<idnum;
cout<<"\nAddress: "<<address;
cout<<"\nPhone no: "<<phone;
cout<<"\nRoom no: "<<rn;    
}
  
 
int  Hotel::getIDNum() const
{
    return idnum;
}

void write_cust()
{
    Hotel cust;
    ofstream outFile;
    outFile.open("Customer.dat",ios::binary|ios::app);
    cust.getdata();
    outFile.write(reinterpret_cast<char *> (&cust), sizeof(Hotel));
    cout<<"\n\nCustomer record Has Been Created ";
    outFile.close();
    getch();
}
 
void display_all()
{
    Hotel cust;
    ifstream inFile;
    inFile.open("Customer.dat",ios::binary);
    if(!inFile)
    {
        cout<<"File could not be open !! Press any Key...";
        cin.ignore();
        cin.get();
        return;
    }
    cout<<"==============Records=============="<<endl<<endl;
    while(inFile.read(reinterpret_cast<char *> (&cust), sizeof(Hotel)))
    {
        cust.showdata();
        cout<<"\n\n====================================\n";
    }
    inFile.close();
    cin.ignore();
    cin.get();
}
 
void display_sp(int n)
{
    Hotel cust;
    ifstream inFile;
    inFile.open("Customer.dat",ios::binary);
    if(!inFile)
    {
        cout<<"File could not be opened! Press any Key...";
        cin.ignore();
        cin.get();
        return;
    }
    bool flag=false;
    while(inFile.read(reinterpret_cast<char *> (&cust), sizeof(Hotel)))
    {
        if(cust.getIDNum()==n)
        {
             cust.showdata();
             flag=true;
        }
    }
    inFile.close();
    if(flag==false)
        cout<<"\n\nrecord not exist";
    cin.ignore();
    cin.get();
}
 void modify_Cust(int n)
{
    bool found=false;
    Hotel cust;
    fstream File;
    File.open("Customer.dat",ios::binary|ios::in|ios::out);
    if(!File)
    {
        cout<<"File could not be opened ! Press any Key...";
        cin.ignore();
        cin.get();
        return;
    }
        while(!File.eof() && found==false)
    {
 
        File.read(reinterpret_cast<char *> (&cust), sizeof(Hotel));
        if(cust.getIDNum()==n)
        {
            cust.showdata();
            cout<<"\n\nPlease Enter The New Details of Customer"<<endl;
            cust.getdata();
                int pos=(-1)*static_cast<int>(sizeof(cust));
                File.seekp(pos,ios::cur);
                File.write(reinterpret_cast<char *> (&cust), sizeof(Hotel));
                cout<<"\n\n\t Record Updated";
                found=true;
        }
    }

 File.close();
    if(found==false)
        cout<<"\n\n Record Not Found ";
    cin.ignore();
    cin.get();
}
 
 
 
void delete_Cust(int n)
{
    Hotel cust;
    ifstream inFile;
    inFile.open("Customer.dat",ios::binary);
    if(!inFile)
    {
        cout<<"File could not be open !! Press any Key...";
        cin.ignore();
        cin.get();
        return;
    }
    ofstream outFile;
    outFile.open("Temp.dat",ios::out);
    inFile.seekg(0,ios::beg);
    while(inFile.read(reinterpret_cast<char *> (&cust), sizeof(Hotel)))
    {
        if(cust.getIDNum()!=n)
    {
            outFile.write(reinterpret_cast<char *> (&cust), sizeof(Hotel));
        }
    }
    outFile.close();
    inFile.close();
    remove("Customer.dat");
    rename("Temp.dat","Customer.dat");
    cout<<"\n\n\tRecord Deleted ..";
    cin.ignore();
    cin.get();
}
 
 

 int main()
{
    char ch;
    int num;
    cout.setf(ios::fixed|ios::showpoint);
    cout<<setprecision(2); 
    do
    {
    system("cls");
    cout<<"\t///////////HOTEL MANAGEMENT/////////";
    cout<<"\n\n\t1.Book A Room";
    cout<<"\n\n\t2.DISPLAY ALL Customer RECORDS";
    cout<<"\n\n\t3.SEARCH Customer RECORD ";
    cout<<"\n\n\t4.MODIFY Customer RECORD";
    cout<<"\n\n\t5.DELETE Customer RECORD";
    cout<<"\n\n\t6.EXIT"<<endl;;
    cout<<"\t-------------------------------------";
    cout<<"\n\n\tPlease Enter Your Choice (1-6): ";
    cin>>ch;
    system("cls");
    switch(ch)
    {
    case '1':   write_cust(); break;
    case '2':   display_all(); break;
    case '3':   cout<<"\n\n\tPlease Enter Customer's ID number: "; cin>>num;
                display_sp(num); break;
    case '4':   cout<<"\n\n\tPlease Enter Customer's ID number: "; cin>>num;
            modify_Cust(num);break;
    case '5':   cout<<"\n\n\tPlease Enter Customer's ID number: "; cin>>num;
            delete_Cust(num);break;
    case '6':   exit(0);;
    default:    cout<<"\a"; 
        
    }
    }while(ch!='6');
 
    return 0;
}
 
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...