Answer to Question #312695 in C++ for see

Question #312695

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. 


1
Expert's answer
2022-03-16T14:48:52-0400
#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();
}

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

Pragya
14.06.22, 12:11

Nice

Leave a comment