gpt4 book ai didi

c++ - 错误 'class HotelRoom' 没有名为 'menu' 的成员,即使它存在

转载 作者:太空宇宙 更新时间:2023-11-04 12:42:41 24 4
gpt4 key购买 nike

我正在尝试用 C++ 构建酒店预订程序。但是,我有一个问题。我不断收到上述错误消息,但似乎找不到解决方法。

请提供一些帮助。任何事情都将不胜感激。以下是我到目前为止所写的内容。

using namespace std;
class HotelRoom{
private:
int roomnum; //Room numbers
int roomcap; //Room capacity
int roomoccuoystst = 0;
int maxperperroom;
double dailyrate;
public:
HotelRoom()
{
roomcap = 0;
maxperperroom = 2;
dailyrate = 175;
}

int gettotal = 0;
int gettotallist = 0;
string room;
string guestroom,message;




void viewrooms()
{
char viewselect, back;
cout<<"Which room list would you like to view ?. 1 - Add rooms, 2 - Reserved rooms : " ;
cin>>viewselect;
switch(viewselect)
{
case '1':
viewaddromm();
break;
case '2':
viewresromm();
break;
default:
cout<<"Please select from the option provided or go back to the main menu. 1 - view rooms, 2 - to the mail menu or any other key to exit the program : ";
cin>>back;
switch(back)
{
case '1':
viewrooms();
break;
case '2':
hotelmenu();
break;
default:
exitpro();

}
}
}

void viewresromm()
{
int occup,rmchoose,up;
string roomtochange, items;
string guestroomdb;
int newaccupancy;
char decisionmade,savinf;
string fname, lname, nationality;
string checkaddroom;
ifstream getdatafromaddroom; //creation of the ifstream object
getdatafromaddroom.open("reserveroom.out");


if(getdatafromaddroom.fail()) //if statement used for error checking
{
cout<<"Could not open file"<<endl; //message that will be printed if the program cannot open the file
}

cout<<endl;
cout<<"First Name"<<'-'<<"Last Name"<<'-'<<"Nationality"<<'-'<<"Guest(s)"<<'-'<<"Room #"<<endl;
cout<<"-------------------------------------------------------"<<endl;
string items;
while(!getdatafromaddroom.eof())
{

// getdatafromaddroom >>fname>>lname>>nationality>>occup>>guestroomdb;
getline(getdatafromaddroom, items);
//cout<<setw(5)<<fname<<' '<<setw(10)<<lname<<' '<<setw(10)<<nationality<<' '<<setw(10)<<occup<<' '<<setw(9)<<guestroomdb<<endl;
gettotallist++;

if( getdatafromaddroom.eof() ) break;
cout<<items<<endl;
}

for(int getlist = 0; getlist < gettotallist; getlist++ )
{
cout<<items<<endl;
// cout<<setw(5)<<fname<<' '<<setw(10)<<lname<<' '<<setw(10)<<nationality<<' '<<setw(10)<<occup<<' '<<setw(9)<<guestroomdb<<endl;
}
}

void viewaddromm()
{
int occup,rmchoose,up;
string roomtochange;
string guestroomdb;
int newaccupancy;
char decisionmade,savinf;
string fname, lname, nationality;
string checkaddroom;
fstream getdatafromaddroom; //creation of the ifstream object
getdatafromaddroom.open("addroom.out");


if(getdatafromaddroom.fail()) //if statement used for error checking
{
cout<<"Could not open file"<<endl; //message that will be printed if the program cannot open the file
}

cout<<endl;
cout<<"First Name"<<'-'<<"Last Name"<<'-'<<"Nationality"<<'-'<<"Guest(s)"<<'-'<<"Room #"<<endl;
cout<<"-------------------------------------------------------"<<endl;
string items;
while(!getdatafromaddroom.eof())
{

// getdatafromaddroom >>fname>>lname>>nationality>>occup>>guestroomdb;
getline(getdatafromaddroom, items);
//cout<<setw(5)<<fname<<' '<<setw(10)<<lname<<' '<<setw(10)<<nationality<<' '<<setw(10)<<occup<<' '<<setw(9)<<guestroomdb<<endl;
gettotallist++;

if( getdatafromaddroom.eof() ) break;
cout<<items<<endl;
}

for(int getlist = 0; getlist < gettotallist; getlist++ )
{
cout<<items<<endl;
// cout<<setw(5)<<fname<<' '<<setw(10)<<lname<<' '<<setw(10)<<nationality<<' '<<setw(10)<<occup<<' '<<setw(9)<<guestroomdb<<endl;
}



}

void exitpro()
{
cout<<"Program closing......Goodbye"<<endl;
system("Pause");
exit(0);
}

menu()
{
char menuchoice;
cout<<"[-------------------------------------------------------]"<<endl;
cout<<"[-Welcome to the hotel booking and reseration menu-]"<<endl;
cout<<"[--------------------------------------------------------]"<<endl;

cout<<setw(30)<<"Addroom -- 1"<<endl;
cout<<setw(32)<<"Reserve a room -- 2"<<endl;
cout<<setw(34)<<" Modify a room -- 3"<<endl;
cout<<setw(36)<<"View roms -- 4"<<endl;
cout<<setw(38)<<" Exist -- 5"<<endl;
cin>>menuchoice;
switch(menuchoice)
{
case '1':
Addroom();
break;
case '2':
reserveroom();
break;
case '3':
modifyroom();
break;
case '4':
viewrooms();
break;
}
}
};

#endif

最佳答案

#include<string>
#include<iostream>
#include<fstream>
#include<iomanip>

using namespace std;
class HotelRoom
{
private:
int roomnum; // Room numbers
int roomcap; // Room capacity
int roomoccuoystst = 0;
int maxperperroom;
double dailyrate;
public:


HotelRoom()
{
roomcap = 0;
maxperperroom = 2;
dailyrate = 175;
}

int gettotal = 0;
int gettotallist = 0;
string room;
string guestroom, message;




void viewrooms()
{
char viewselect, back;
cout << "Which room list would you like to view ?. 1 - Add rooms, 2 - Reserved rooms : ";
cin >> viewselect;
switch (viewselect)
{
case '1':
viewaddromm();
break;
case '2':
viewresromm();
break;
default:
cout <<
"Please select from the option provided or go back to the main menu. 1 - view rooms, 2 - to the mail menu or any other key to exit the program : ";
cin >> back;
switch (back)
{
case '1':
viewrooms();
break;
case '2':
menu();
break;
default:
exitpro();

}
}
}

void viewresromm()
{

string roomtochange, items;
string guestroomdb;
// int newaccupancy;
// char decisionmade,savinf;
string fname, lname, nationality;
string checkaddroom;
ifstream getdatafromaddroom; // creation of the ifstream object
getdatafromaddroom.open("reserveroom.out");


if (getdatafromaddroom.fail()) // if statement used for error
// checking
{
cout << "Could not open file" << endl; // message that will be
// printed if the program
// cannot open the file
return;
}

cout << endl;
cout << "First Name" << '-' << "Last Name" << '-' << "Nationality" << '-' << "Guest(s)" <<
'-' << "Room #" << endl;
cout << "-------------------------------------------------------" << endl;
// string items;
while (!getdatafromaddroom.eof())
{

// getdatafromaddroom
// >>fname>>lname>>nationality>>occup>>guestroomdb;
getline(getdatafromaddroom, items);
// cout<<setw(5)<<fname<<' '<<setw(10)<<lname<<'
// '<<setw(10)<<nationality<<' '<<setw(10)<<occup<<'
// '<<setw(9)<<guestroomdb<<endl;
gettotallist++;

if (getdatafromaddroom.eof())
break;
cout << items << endl;
}

for (int getlist = 0; getlist < gettotallist; getlist++)
{
cout << items << endl;
// cout<<setw(5)<<fname<<' '<<setw(10)<<lname<<'
// '<<setw(10)<<nationality<<' '<<setw(10)<<occup<<'
// '<<setw(9)<<guestroomdb<<endl;
}
}

void viewaddromm()
{
// int occup,rmchoose,up;
string roomtochange;
string guestroomdb;
// int newaccupancy;
// char decisionmade,savinf;
string fname, lname, nationality;
string checkaddroom;
fstream getdatafromaddroom; // creation of the ifstream object
getdatafromaddroom.open("addroom.out");


if (getdatafromaddroom.fail()) // if statement used for error
// checking
{
cout << "Could not open file" << endl; // message that will be
// printed if the program
// cannot open the file
return;
}

cout << endl;
cout << "First Name" << '-' << "Last Name" << '-' << "Nationality" << '-' << "Guest(s)" <<
'-' << "Room #" << endl;
cout << "-------------------------------------------------------" << endl;
string items;
while (!getdatafromaddroom.eof())
{

// getdatafromaddroom
// >>fname>>lname>>nationality>>occup>>guestroomdb;
getline(getdatafromaddroom, items);
// cout<<setw(5)<<fname<<' '<<setw(10)<<lname<<'
// '<<setw(10)<<nationality<<' '<<setw(10)<<occup<<'
// '<<setw(9)<<guestroomdb<<endl;
gettotallist++;

if (getdatafromaddroom.eof())
break;
cout << items << endl;
}

for (int getlist = 0; getlist < gettotallist; getlist++)
{
cout << items << endl;
// cout<<setw(5)<<fname<<' '<<setw(10)<<lname<<'
// '<<setw(10)<<nationality<<' '<<setw(10)<<occup<<'
// '<<setw(9)<<guestroomdb<<endl;
}



}

void exitpro()
{
cout << "Program closing......Goodbye" << endl;
// system("Pause");
exit(0);
}

void Addroom()
{
std::string mess = __func__;
mess += " is not yet implimented.";
throw new std::logic_error(mess.c_str());
}

void reserveroom()
{
std::string mess = __func__;
mess += " is not yet implimented.";
throw new std::logic_error(mess.c_str());
}

void modifyroom()
{
std::string mess = __func__;
mess += " is not yet implimented.";
throw new std::logic_error(mess.c_str());
}

void menu()
{
while (true)
{
char menuchoice;
cout << "[-------------------------------------------------------]" << endl;
cout << "[-Welcome to the hotel booking and reseration menu-]" << endl;
cout << "[--------------------------------------------------------]" << endl;

cout << setw(30) << "Addroom -- 1" << endl;
cout << setw(30) << "Reserve a room -- 2" << endl;
cout << setw(30) << "Modify a room -- 3" << endl;
cout << setw(30) << "View rooms -- 4" << endl;
cout << setw(30) << "Exit -- 5" << endl;
cin >> menuchoice;
switch (menuchoice)
{
case '1':
Addroom();
break;
case '2':
reserveroom();
break;
case '3':
modifyroom();
break;
case '4':
viewrooms();
break;
case '5':
exitpro();
}
}
}
};

int main()
{
try
{
HotelRoom room;
room.menu();
}
catch(std::logic_error * ex)
{
std::cout << ex->what();
}

}

这个项目还有很多事情要做。我已经修复了您特别询问的部分,它现在是一个运行中的应用程序,具有一些适当的诊断。我不会深入探讨这种语言的工作原理,但您有几个未实现的函数、缺少返回类型以及一般逻辑错误,例如在您确定文件未打开后尝试使用该文件。它现在运行,您可以清楚地知道您需要完成什么。您还有几个未使用的变量。

我至少添加了

void Addroom()
{
std::string mess = __func__;
mess += " is not yet implimented.";
throw new std::logic_error(mess.c_str());
}

void reserveroom()
{
std::string mess = __func__;
mess += " is not yet implimented.";
throw new std::logic_error(mess.c_str());
}

void modifyroom()
{
std::string mess = __func__;
mess += " is not yet implimented.";
throw new std::logic_error(mess.c_str());


}

和菜单的返回类型。`无效菜单()

你不能调用你还没有写过的函数,所有的函数都有一个返回类型,即使它们什么都不返回。

祝你好运!

关于c++ - 错误 'class HotelRoom' 没有名为 'menu' 的成员,即使它存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53376361/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com