Answer to Question #339862 in C++ for fahmi

Question #339862

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-


1
Expert's answer
2022-05-11T08:48:45-0400
#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();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS