Creating a Simple Employee Database using inheritance in c++.
-
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() -
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() -
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.
-
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() -
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. -
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.