Write a program that would print the information (name, year of joining, address) of three employees by creating a class Employee. Create a method called setDetails(...) that takes 3 parameters and initialises the values of the parameters to the corresponding member variables. Create a method printInfo() that prints details of each employee. Create the main method and produce the following outputs: Name Year of joining Address Robert 1994 64C- WallsStreat Sam 2000 68D- WallsStreat John 1999 26B- WallsStreat Note: Write both the class Employee and the main method on the same file called Employee.cpp.
#include <iostream>
#include <string>
using namespace std;
class Employee
{
string name;
int year_of_join;
string address;
public:
void setDetails(string _name, int _year_of_join, string _address)
{
name = _name;
year_of_join = _year_of_join;
address = _address;
}
void printInfo()
{
cout << "\nEmplolyee`s name: " << name;
cout << "\nEmplolyee`s year of join: " << year_of_join;
cout << "\nEmplolyee`s address: " << address<<endl;
}
};
int main()
{
Employee a;
a.setDetails("Robert", 1994, "64C - WallsStreat");
Employee b;
b.setDetails("Sam", 2000, "68D- WallsStreat");
Employee c;
c.setDetails("John", 1999, "26B- WallsStreat");
a.printInfo();
b.printInfo();
c.printInfo();
}
Comments
Nice
Leave a comment