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
#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;
}
Comments
Thanks a lot , it was really helpful
Leave a comment