Sunday, 6 August 2017

Write C++ program of a company management by using Classes and Inheritance

Write C++ program of a company management by using Classes and Inheritance , values enter by user :

What is Inheritance ?

Inheritance in Object Oriented Programming can be described as a procedure of creating new class from current classes. New classes inherit some of the properties and conduct of the existing classes. An present class this is "parent" of a brand new class is referred to as a base class.

What Is Derived Classes ?

A class may be derived from multiple classes, this means that it can inherit information and features from a couple of base classes. To define a derived class, we use a category derivation list to specify the base class(es).
A class derivation list names one or more base classes and has the form:

Class derived-class: access-specifier base-class

Where get right of entry to-specifier is one in every of public, protected, or private, and base-class is the name of a previously described class. If the get acces-specifier is not used, then it's private via default.

Code:

// 2employ.cpp
// multiple levels of inheritance
#include <iostream>
using namespace std;
const int LEN = 80; //maximum length of names
////////////////////////////////////////////////////////////////
class employee
{
private:
char name[LEN]; //employee name
unsigned long number; //employee number
public:
void getdata()
{
cout << "\n Enter last name: "; cin >> name;
cout << " Enter number: "; cin >> number;
}
void putdata() const
{
cout << "\n Name: "<< name;
cout << "\n Number: " << number;
}
};
////////////////////////////////////////////////////////////////
class manager : public employee //manager class
{
private:
char title[LEN]; //”vice-president” etc.
double dues; //golf club dues
public:
void getdata()
{
employee::getdata();
cout << " Enter title: "; cin >> title;
cout << " Enter golf club dues: "; cin >> dues;
}
void putdata() const
{
employee::putdata();
cout << "\n Title: " << title;
cout << "\n Golf club dues: "<< dues;
}
};
////////////////////////////////////////////////////////////////
class scientist : public employee //scientist class
{
private:
int pubs; //number of publications
public:
void getdata()
{
employee::getdata();
cout << "Enter number of pubs: "; cin >> pubs;
}
void putdata() const
{
employee::putdata();
cout << "\n Number of publications: " << pubs;
}
};
////////////////////////////////////////////////////////////////
class laborer : public employee //laborer class
{
};
////////////////////////////////////////////////////////////////
class foreman : public laborer //foreman class
{
private:
float quotas; //percent of quotas met successfully
public:
void getdata()
{
laborer::getdata();
cout << " Enter quotas: "; cin >> quotas;
}
void putdata() const
{
laborer::putdata();
cout << "\n Quotas: " << quotas;
}
};
////////////////////////////////////////////////////////////////
int main()
{
laborer l1;
foreman f1;
cout << endl;
cout << "\nEnter data for laborer 1";
l1.getdata();
cout << "\nEnter data for foreman 1";
f1.getdata();
cout << endl;
cout << "\nData on laborer 1";
l1.putdata();
cout << "\nData on foreman 1";
f1.putdata();
cout << endl;
return 0;
}

Output:















Try it yourself.
If you have any problem you can tell me on comment box i will help you.
thanks.



Viral Programs

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.

1 comments: