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

409 Views Asked by At
#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:
}

i am using turbo c

i am making a project named hostel management using classes ,array of objects,and switch case because hostel rooms can be empty but if i used normal array,stack,queue it wont work as it does can not have null value in middle

1

There are 1 best solutions below

1
David G On BEST ANSWER

You have a bunch of syntax errors.

  1. Missing closing brace for the if (h == 1) statement.
  2. Misplaced semicolon for the cout<<"what do u want to update ? ";<<endl line (it should be at the end)
  3. Missing closing brace for the outermost else statement in the display_1() function.
  4. Missing closing brace for display_1().
  5. Missing closing brace for the hostel_mangt class.

And several other errors such as using comparisons (==) where there should be assignments (=), using public: in the main() function (it shouldn't be there), and so on.

Here's your code with those errors fixed:

#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;
}

There are probably still issues with your code but this is what I managed to fix.