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

ks1322
  • 33,961
  • 14
  • 109
  • 164
Aaryan_mb
  • 3
  • 1
  • 4
    _"i am using turbo c"_ use a compiler from the current millennium please. – πάντα ῥεῖ Dec 03 '22 at 17:55
  • Have another array that tells you whether a particular room is empty or not. Or use an empty name to indicate that a room is empty. – john Dec 03 '22 at 17:56
  • 1
    What you're learning isn't C++ as it has been standardized the last 24 years. – Some programmer dude Dec 03 '22 at 17:57
  • 1
    Please read: [Why doesn't a simple "Hello World"-style program compile with Turbo C++?](https://stackoverflow.com/questions/44863062/why-doesnt-a-simple-hello-world-style-program-compile-with-turbo-c) which should explain why trying to help you with a 20+ year old compiler will be difficult. – Richard Critten Dec 03 '22 at 18:00
  • @Aaryan_mb I am sorry but we will have to dig deep to remember what we used to do 20+ years ago. Also we have no way to test our answers. – Richard Critten Dec 03 '22 at 18:02
  • its okay sir thanks for letting me know that i have to move to an new compiler – Aaryan_mb Dec 03 '22 at 18:04
  • 2
    Your college is really doing you a disservice. I recommend you try to learn modern C++ on the side, doing all exercises and assignments using modern dialect and modern environments, and only when you really need to submit something tweak it to work in Turbo-C++ (instead of doing the other way around). – Some programmer dude Dec 03 '22 at 18:08
  • *Open Watcom* is compatible with *Turbo C*, but modern. – Sandburg Dec 03 '22 at 21:32

1 Answers1

0

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.

David G
  • 94,763
  • 41
  • 167
  • 253