Answer to Question #171613 in C++ for ADITYA MATHUR

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


1
Expert's answer
2021-03-14T18:36:04-0400
#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!

Comments

ADITYA MATHUR
15.03.21, 08:41

Thanks a lot , it was really helpful

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS