Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating a Simple Employee Database using inheritance in c++.

Creating a Simple Employee Database using inheritance in c++.

Scheduled Pinned Locked Moved C / C++ / MFC
c++databaseoopperformancehelp
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tarun Jha
    wrote on last edited by
    #1

    the following question is to be done using the concept of hierarchical inheritance staff - > teacher, officer, typist typist -> regular, casual my solution is giving an Runtime error below is my code :

    //To maintain a database of an educational institutional using hierarchical relationships. (application of virtual classes)
    #include
    #include
    using namespace std;

    //------------------------------------------------------------------------------------------------------------------------------------------------------------------
    class staff {
    string code, name;
    public:
    staff() : code(0000), name("Unknown") {}

    virtual void getdata(void){
        cout << "Enter employee name : " << endl;
        getline(cin, name);
        cout << "Enter employee code : " << endl;
        cin >> code ;
    }
    virtual void putdata(void){
        cout << "Employee name : " << name << endl
             << "Employee code : " << code << endl ;
    }
    

    };

    class teacher : public staff {
    string subject;
    int publication;
    public:
    teacher() : subject("Empty"), publication(0000) {}
    void getdata(void);
    void putdata(void);
    };

    void teacher::getdata(){
    staff::getdata();
    cout << "Enter subject : " << endl ;
    cin >> subject;
    cout << "Enter total number of publications : " << endl ;
    cin >> publication ;
    }

    void teacher::putdata(){
    staff::putdata();
    cout << "Subject : " << subject << endl
    << "publications : " << publication << endl;
    }

    class officer : public staff {
    int grade;
    string posting ;
    public:
    officer() : grade(0), posting("Unavailable") {}
    void getdata(void);
    void putdata(void);
    };

    void officer::getdata(){
    staff::getdata();
    cout << "Enter the grade : " << endl;
    cin >> grade;
    cout << "Enter the posting : " <> speed;
    cout << "Enter experience (int years) : " << endl;
    cin >> experience ;
    }

    void typist::putdata(){
    staff::putdata()

    L 2 Replies Last reply
    0
    • T Tarun Jha

      the following question is to be done using the concept of hierarchical inheritance staff - > teacher, officer, typist typist -> regular, casual my solution is giving an Runtime error below is my code :

      //To maintain a database of an educational institutional using hierarchical relationships. (application of virtual classes)
      #include
      #include
      using namespace std;

      //------------------------------------------------------------------------------------------------------------------------------------------------------------------
      class staff {
      string code, name;
      public:
      staff() : code(0000), name("Unknown") {}

      virtual void getdata(void){
          cout << "Enter employee name : " << endl;
          getline(cin, name);
          cout << "Enter employee code : " << endl;
          cin >> code ;
      }
      virtual void putdata(void){
          cout << "Employee name : " << name << endl
               << "Employee code : " << code << endl ;
      }
      

      };

      class teacher : public staff {
      string subject;
      int publication;
      public:
      teacher() : subject("Empty"), publication(0000) {}
      void getdata(void);
      void putdata(void);
      };

      void teacher::getdata(){
      staff::getdata();
      cout << "Enter subject : " << endl ;
      cin >> subject;
      cout << "Enter total number of publications : " << endl ;
      cin >> publication ;
      }

      void teacher::putdata(){
      staff::putdata();
      cout << "Subject : " << subject << endl
      << "publications : " << publication << endl;
      }

      class officer : public staff {
      int grade;
      string posting ;
      public:
      officer() : grade(0), posting("Unavailable") {}
      void getdata(void);
      void putdata(void);
      };

      void officer::getdata(){
      staff::getdata();
      cout << "Enter the grade : " << endl;
      cin >> grade;
      cout << "Enter the posting : " <> speed;
      cout << "Enter experience (int years) : " << endl;
      cin >> experience ;
      }

      void typist::putdata(){
      staff::putdata()

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      You need to use the debugger to find out exactly where the error occurs.

      T 1 Reply Last reply
      0
      • L Lost User

        You need to use the debugger to find out exactly where the error occurs.

        T Offline
        T Offline
        Tarun Jha
        wrote on last edited by
        #3

        what is the error saying ?

        L 1 Reply Last reply
        0
        • T Tarun Jha

          what is the error saying ?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          It's probably saying that you are trying to access some element that has not been initialised. And looking at your classes I cannot guess where is the most likely place. Although most of the code is not doing things in the best way. As I have previously suggested to you, you need to get a book on C++ and learn it properly from beginning to end. You cannot learn it by continually posting questions.

          T 1 Reply Last reply
          0
          • T Tarun Jha

            the following question is to be done using the concept of hierarchical inheritance staff - > teacher, officer, typist typist -> regular, casual my solution is giving an Runtime error below is my code :

            //To maintain a database of an educational institutional using hierarchical relationships. (application of virtual classes)
            #include
            #include
            using namespace std;

            //------------------------------------------------------------------------------------------------------------------------------------------------------------------
            class staff {
            string code, name;
            public:
            staff() : code(0000), name("Unknown") {}

            virtual void getdata(void){
                cout << "Enter employee name : " << endl;
                getline(cin, name);
                cout << "Enter employee code : " << endl;
                cin >> code ;
            }
            virtual void putdata(void){
                cout << "Employee name : " << name << endl
                     << "Employee code : " << code << endl ;
            }
            

            };

            class teacher : public staff {
            string subject;
            int publication;
            public:
            teacher() : subject("Empty"), publication(0000) {}
            void getdata(void);
            void putdata(void);
            };

            void teacher::getdata(){
            staff::getdata();
            cout << "Enter subject : " << endl ;
            cin >> subject;
            cout << "Enter total number of publications : " << endl ;
            cin >> publication ;
            }

            void teacher::putdata(){
            staff::putdata();
            cout << "Subject : " << subject << endl
            << "publications : " << publication << endl;
            }

            class officer : public staff {
            int grade;
            string posting ;
            public:
            officer() : grade(0), posting("Unavailable") {}
            void getdata(void);
            void putdata(void);
            };

            void officer::getdata(){
            staff::getdata();
            cout << "Enter the grade : " << endl;
            cin >> grade;
            cout << "Enter the posting : " <> speed;
            cout << "Enter experience (int years) : " << endl;
            cin >> experience ;
            }

            void typist::putdata(){
            staff::putdata()

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            class staff {
            string code, name;
            public:
            staff() : code(0000), name("Unknown") {} // *****

            You have declared code as a string, but you are passing a value of 0, which is a null pointer.

            T 1 Reply Last reply
            0
            • L Lost User

              class staff {
              string code, name;
              public:
              staff() : code(0000), name("Unknown") {} // *****

              You have declared code as a string, but you are passing a value of 0, which is a null pointer.

              T Offline
              T Offline
              Tarun Jha
              wrote on last edited by
              #6

              ok, thank you

              L 1 Reply Last reply
              0
              • T Tarun Jha

                ok, thank you

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                Which is what the debugger would have shown you.

                1 Reply Last reply
                0
                • L Lost User

                  It's probably saying that you are trying to access some element that has not been initialised. And looking at your classes I cannot guess where is the most likely place. Although most of the code is not doing things in the best way. As I have previously suggested to you, you need to get a book on C++ and learn it properly from beginning to end. You cannot learn it by continually posting questions.

                  T Offline
                  T Offline
                  Tarun Jha
                  wrote on last edited by
                  #8

                  i am currently following "C++ The complete reference by : Herbert Schildt"

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups