Search
 
SCRIPT & CODE EXAMPLE
 

CPP

hierarchical inheritance in c++ employee

/*C++ program to read and print employee information with department and pf information using hierarchical inheritance.*/
 
#include <iostream>
#include <stdio.h>
using namespace std;
 
//Base Class - basicInfo
class basicInfo
{
    protected:  
        char    name[30];
        int     empId;
        char    gender;
    public:
        void getBasicInfo(void)
        {
            cout << "Enter Name: "; 
            cin.ignore(1);
            cin.getline(name,30);
            cout << "Enter Emp. Id: ";
            cin  >> empId;
            cout << "Enter Gender: ";
            cin  >> gender;
        }
};
 
//Base Class - deptInfo
class deptInfo: private basicInfo
{
    protected:  
        char    deptName[30];
        char    assignedWork[30];
        int     time2complete;
    public:
        void getDeptInfo(void)
        {
            getBasicInfo(); //to get basic info of an employee
            cout << "Enter Department Name: "; 
            cin.ignore(1);
            cin.getline(deptName,30);
            cout << "Enter assigned work: ";
            fflush(stdin);
            cin.getline(assignedWork,30);
            cout << "Enter time in hours to complete work: ";
            cin  >> time2complete;
        }
        void printDeptInfo(void)
        {
            cout << "Employee's Information is: "     << endl;
            cout << "Basic Information...:"       << endl;
            cout << "Name: "      << name   << endl;      //accessing protected data
            cout << "Employee ID: " << empId  << endl;        //accessing protected data
            cout << "Gender: "        << gender << endl << endl;//accessing protected data
             
            cout << "Department Information...:"    << endl;
            cout << "Department Name: "             << deptName     << endl; //accessing protected data
            cout << "Assigned Work: "               << assignedWork << endl; //accessing protected data
            cout << "Time to complete work: "       << time2complete<< endl; //accessing protected data
             
        }
};
 
//another Base Class : loadInfo
class loanInfo:private basicInfo
{
    protected:  
        char    loanDetails[30];
        int     loanAmount;
    public:
        void getLoanInfo(void)
        {
            getBasicInfo(); //to get basic info of an employee
            cout << "Enter Loan Details: ";
            cin.ignore(1);
            cin.getline(loanDetails,30);
            cout << "Enter loan amount: ";
            cin  >> loanAmount;
        }
        void printLoanInfo(void)
        {
            cout << "Employee's Information is: "     << endl;
            cout << "Basic Information...:"       << endl;
            cout << "Name: "      << name   << endl;      //accessing protected data
            cout << "Employee ID: " << empId  << endl;        //accessing protected data
            cout << "Gender: "        << gender << endl << endl;//accessing protected data
             
            cout << "Loan Information...:"        << endl;
            cout << "Loan Details: "          << loanDetails    << endl; //accessing protected data
            cout << "Loan Amount : "          << loanAmount   << endl; //accessing protected data         
        }
};
 
int main()
{
    //read and print department information
    deptInfo objD;
     
    objD.getDeptInfo();
    objD.printDeptInfo();
     
    cout << endl << endl ;
    //read and print loan information
    loanInfo objL;
     
    objL.getLoanInfo();
    objL.printLoanInfo();
 
     
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: c++ if statement 
Cpp :: What is a ~ in c++ 
Cpp :: matrix c++ 
Cpp :: cpp vscode multipe compilation 
Cpp :: set size of a vector c++ 
Cpp :: what was the piep piper app 
Cpp :: intlen in c++ 
Cpp :: c++ hash map key count 
Cpp :: volumeof a sphere 
Cpp :: Basic Input / Output in C++ 
Cpp :: c/c++ windows api socket wrappers 
Cpp :: c++ queue 
Cpp :: c++ generic pointer 
Cpp :: Accessing C++ Array Elements 
Cpp :: evennumbers 1 to 100 
Cpp :: how to convert char to int in c++ 
Cpp :: concatenate string in cpp 
Cpp :: how to sort string array in c++ 
Cpp :: c++ check first character of string 
Cpp :: files c++ 
Cpp :: C++ insert character 
Cpp :: conversion of class type data into basic type data in c++ 
Cpp :: online converter c++ to c 
Cpp :: building native binary with il2cpp unity 
Cpp :: The five most significant revisions of the C++ standard are C++98 (1998), C++03 (2003) and C++11 (2011), C++14 (2014) and C++17 (2017) 
Cpp :: *= c++ 
Cpp :: c++ vector move element 
Cpp :: jquery datepicker default date not working 
Cpp :: c++ if 
Cpp :: ordine crescente di numeri indefiniti in c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =