如何解决 C++ 中的错误(包含开关的函数未内联展开)[关闭]

how to solve error ( functions containing switch are not expanded inline ) in C++ [closed]

提问人:Aaryan_mb 提问时间:12/4/2022 最后编辑:ks1322Aaryan_mb 更新时间:12/4/2022 访问量:298

问:


编辑问题以包括所需的行为、特定问题或错误以及重现问题所需的最短代码。这将帮助其他人回答这个问题。

12个月前关闭。

#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 值

C Turbo-C++ Turbo-C

评论

4赞 πάντα ῥεῖ 12/4/2022
“我正在使用 Turbo C”请使用当前千年的编译器。
0赞 john 12/4/2022
有另一个数组来告诉你一个特定的房间是否是空的。或者使用空名称来指示房间是空的。
1赞 Some programmer dude 12/4/2022
你正在学习的不是 C++,因为它在过去 24 年中已经标准化。
1赞 Richard Critten 12/4/2022
请阅读:为什么一个简单的“Hello World”风格的程序不能用 Turbo C++ 编译?这应该解释为什么尝试帮助您使用 20+ 年的编译器会很困难。
2赞 Some programmer dude 12/4/2022
你的大学真的在伤害你。我建议你尝试学习现代 C++,使用现代方言和现代环境进行所有练习和作业,并且只有在你真的需要提交一些东西时才调整它以在 Turbo-C++ 中工作(而不是反过来)。

答:

0赞 David G 12/4/2022 #1

你有一堆语法错误。

  1. 缺少语句的右大括号。if (h == 1)
  2. 该行的分号放错了位置(应该在末尾)cout<<"what do u want to update ? ";<<endl
  3. 函数中最外层语句缺少右大括号。elsedisplay_1()
  4. 缺少 的右大括号。display_1()
  5. 缺少班级的右大括号。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 需要什么