Answer to Question #241688 in C++ for Joseph

Question #241688

Create a class employee which stores is name, ID and salary of an employee by user input. The ID should be generated upon the creation of object, starting from 1. Include all the constructors and destructor in the class. Create one object using each of the constructors and display it.


1
Expert's answer
2021-09-24T11:26:05-0400
#include <iostream>


using namespace std;


class employee {
public:
	employee() {
		ID++;
		name = "no name";
	}
	employee(string nam) {
		name = nam;
		ID++;
	}
	employee(float sala) { salary = sala; }
	employee(float sal, string nam) { salary = sal; name = nam; }
	void set_name(string nam) { name = nam; }
	void set_salary(float sal) { salary = sal; }
	string get_name() { return name; }
	float get_salary() { return salary; }


	~employee() { ID = 0; }
private:
	static int ID;
	string name;
	float salary;
};
int employee::ID = 0;


int main(int argc, char* argv[]) {
	employee W1, W2("John"), W3(2000), W4(2500, "Ithan");
}

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

Joseph
03.10.21, 10:35

Thank you so much AssignmentExpert

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS