Implement a class Employee which contains 2 data members (name, surname), a constructor, a function that reads data members from the user, and one that displays name and surname of an Employee object. Implement another class EmployeeInfo which inherits from Employee with additional data members as street, city and postal_code. This class must have access to the public member functions of the base class and implement three additional member functions NewAddress, NewName and Print. Write a main function that has an instance of EmployeeInfo and reads all data members and displays them.
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
class Employee{
public:
string name, surname;
Employee()
{
}
void input()
{
cout<<"Enter your First Name : ";
cin>>name;
cout<<"Enter your Surname : ";
cin>>surname;
}
void display()
{
cout<<"First name : "<<name<<endl;
cout<<"Surname : "<<surname<<endl;
}
};
class EmployeeInfo : public Employee{
public:
int street;
string city;
int postal_code;
void newName(string s1, string s2)
{
name = s1;
surname = s2;
}
void newAddress()
{
cout<<"Enter Street Number : ";
cin>>street;
cout<<"Enter City : ";
cin>>city;
cout<<"Enter Postal Code : ";
cin>>postal_code;
}
void print()
{
cout<<"Street : "<<street<<endl;
cout<<"City : "<<city<<endl;
cout<<"Postal Code : "<<postal_code<<endl;
}
};
int main()
{
cout<<"Enter number of Employees : ";
int n;
cin>>n;
cout<<endl<<"Enter Employee Details "<<endl;
cout<<"----------------------------------------"<<endl;
EmployeeInfo e[n];
for(int i=0; i<n; i++)
{
e[i].input();
e[i].newAddress();
cout<<endl;
}
cout<<"Displaying Employee Details"<<endl;
cout<<"--------------------------------"<<endl;
for(int i=0; i<n; i++)
{
cout<<"Employee"<<i+1<<endl;;
e[i].display();
e[i].print();
cout<<endl;
}
}
Comments
Leave a comment