Write a program that would print the information (name, year of joining, salary,address) of three employees by creating a class named 'Employee'. The outputshould be as follows: Name Year of joining Address Robert 1994 64C-
#include<iostream>
#include<string>
using namespace std;
class Employee
{
string name;
int yearOfjoin;
double salary;
string address;
public:
Employee(){}
Employee(string _name, int _yearOfjoin, double _salary, string _address)
:name(_name), yearOfjoin(_yearOfjoin), salary(_salary), address(_address){}
void Assign()
{
cout << "Please, enter a name of employee: ";
cin >> name;
cout << "Please, enter year of joining of employee: ";
cin >> yearOfjoin;
cout << "Please, enter salary of employee: ";
cin >> salary;
cout << "Please, enter an address of employee: ";
cin >> address;
}
void Display()
{
cout << name<< "\t" << yearOfjoin<< "\t\t" << address
<< "\t" << salary<<endl;
}
};
int main()
{
Employee arr[3] = { Employee("Robert", 1994, 2000, "64C"),
Employee("John", 1998, 2500, "334B"),Employee("Mary", 1995, 1800, "6A") };
cout << "\nName\tYear of joining\tAddress\tSalary:\n";
for (int i = 0; i < 3; i++)
{
arr[i].Display();
}
}
Comments
Leave a comment