提问人:Aaryan_mb 提问时间:12/4/2022 最后编辑:ks1322Aaryan_mb 更新时间:12/4/2022 访问量:298
如何解决 C++ 中的错误(包含开关的函数未内联展开)[关闭]
how to solve error ( functions containing switch are not expanded inline ) in C++ [closed]
问:
#include<iostream.h>
#include<conio.h>
class hostel_mangt
{
public:
int x,h,id,rc,hd;
char name[15],dol[10];
void oprt_1()
{
cout<<"do u want to see or update room's ?"<<endl;
cout<<"enter 1 to see and 0 to do operations = "<<endl;
cin>>h;
}
void display_1()
{
if(h==1)
{
if (name==NULL)
{
cout<<"room is empty "<<endl;
}
else
{
cout<<"id = "<<id<<endl;
cout<<"name = "<<name<<endl;
cout<<"date of leaving = "<<dol<<endl;
}
else
{
cout<<" 1. Update the room member and its data "<<endl;
cout<<" 2. delete the room member and its data "<<endl;
cout<<"enter choice = " ;
cin>>x;
switch(x)
{
case 1:
{
cout<<"what do u want to update ? ";<<endl
cout<<" 1. name "<<endl;
cout<<" 2. date of leaving"<<endl;
cin>>rc;
switch(rc)
{
case 1:
{
cout<<"enter new name = "<<endl;
cin>>name;
}
case 2:
{
cout<<"enter updated date of leaving = ";
cin >>date;
}
}
break;
}
case 2:
{
cout<<"what do you want to be deleted = ";
cout<<" 1. name "<<endl;
cout<<" 2. date of leaving "<<endl;
cin>>hd;
switch(hd)
{
case 1:
{
name==NULL;
break;
}
case 2:
{
dol==NULL;
break;
}
break;
}
}
}
int main()
{
public:
int i,c;
clrscr();
hostel_mangt hm[10];
for(i=0;i<10;i++)
{
hm.oprt_1();
hm.display_1();
cout<<"do u want to continue ? "<<endl<<"if yes enter 1"<<endl;
cin>>c;
if(c!=1)
{
break;
}
}
getch();
return 0:
}
我正在使用 Turbo C
我正在使用类、对象数组和开关大小写制作一个名为 hostel management 的项目,因为旅馆房间可以是空的,但如果我使用普通的 array、stack、queue,它将无法工作,因为它不能在中间有 null 值
答:
0赞
David G
12/4/2022
#1
你有一堆语法错误。
- 缺少语句的右大括号。
if (h == 1)
- 该行的分号放错了位置(应该在末尾)
cout<<"what do u want to update ? ";<<endl
- 函数中最外层语句缺少右大括号。
else
display_1()
- 缺少 的右大括号。
display_1()
- 缺少班级的右大括号。
hostel_mangt
以及其他一些错误,例如在应该有赋值 () 的地方使用 comparisons (),在函数中使用(它不应该在那里)等等。==
=
public:
main()
下面是修复了这些错误的代码:
#include <iostream>
#include <string>
using namespace std;
class hostel_mangt {
public:
int x, h, id, rc, hd;
string name, dol; // use std::string instead of character arrays, they're much easier to use
// char name[15], dol[10];
void oprt_1() {
cout << "do u want to see or update room's ?" << endl;
cout << "enter 1 to see and 0 to do operations = " << endl;
cin >> h;
}
void display_1() {
if (h == 1) {
if (name.empty()) {
cout << "room is empty " << endl;
} else {
cout << "id = " << id << endl;
cout << "name = " << name << endl;
cout << "date of leaving = " << dol << endl;
}
} else {
cout << " 1. Update the room member and its data " << endl;
cout << " 2. delete the room member and its data " << endl;
cout << "enter choice = ";
cin >> x;
switch (x) {
case 1: {
cout << "what do u want to update ? " << endl;
cout << " 1. name " << endl;
cout << " 2. date of leaving" << endl;
cin >> rc;
switch (rc) {
case 1: {
cout << "enter new name = " << endl;
cin >> name;
}
case 2: {
cout << "enter updated date of leaving = ";
cin >> date;
}
}
break;
}
case 2: {
cout << "what do you want to be deleted = ";
cout << " 1. name " << endl;
cout << " 2. date of leaving " << endl;
cin >> hd;
switch (hd) {
case 1: {
name.clear();
// name == NULL;
break;
}
case 2: {
dol.clear();
// dol == NULL;
break;
}
break;
}
}
}
}
}
};
int main() {
int i, c;
clrscr();
hostel_mangt hm[10];
for (i = 0; i < 10; i++) {
// to access an element of an array you use the square brackets []:
hm[i].oprt_1();
hm[i].display_1();
cout << "do u want to continue ? " << endl << "if yes enter 1" << endl;
cin >> c;
if (c != 1) {
break;
}
}
getch();
return 0;
}
您的代码可能仍然存在问题,但这是我设法解决的问题。
评论
1赞
Sandburg
12/4/2022
+ #include <string>;
+ CLRSCR 需要什么
评论