Question #171613

Create a class called employee that contains a name (an object of class string) and an employee number (type long). Include a member function called getdata() to get data from the user for insertion into the object, and another function called putdata()to display the data. Assume the name has no embedded blanks.

Write a main()program to exercise this class


Expert's answer

#include <iostream>
#include <string>
 
using namespace std;
 
class employee
{
public:
	void getdata();
	void putdata();
private:
	string name;
	long number;
};
 
void employee::getdata()
{
	cout << "Enter employee name: ";
	cin >> name;
	cout << "Enter employee number: ";
	cin >> number;
}
 
void employee::putdata()
{
	cout << "Employee name is: " << name << endl;
	cout << "Employee number is: " << number << endl;
}
 
int main()
{
	employee first;
	first.getdata();
	cout << endl;
	first.putdata();
	cout << endl;
	return 0;
}

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!

LATEST TUTORIALS
APPROVED BY CLIENTS