Answer to Question #248604 in C++ for Zeeshan

Question #248604
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. It should create an array of type employee,
and then invite the user to input data for up to 100 employees. Finally, it should print out
the data for all the employees.
1
Expert's answer
2021-10-08T23:51:37-0400
#include<iostream>


using namespace std;
class employee{
	private:
		string name;
		long number;
	public:
		void getdata(){
			cout<<"Enter the name of the employee\n";
			cin.ignore();
			string n;
		getline(cin, n);
		
		
		name =n;
		
			cout<<"Enter the number of the employee\n";
			long num;
			cin>>num;
			number = num;
		}
		
		void putdata(){
			cout<<"Name:  "<<name<<endl;
			cout<<"Number:  "<<number<<endl;
		}
		
		
		
};
int main(){
	employee em[100];
		cout<<"Enter details of employees"<<endl;
		
	for(int i=0; i<100; i++){
		cout<<"Employee "<<(i+1)<<":"<<endl;
		em[i].getdata();
	}
	cout<<"Employees' Details as follows: \n";
	for(int i=0; i<100; i++){
		cout<<"Employee "<<(i+1)<<endl;
		em[i].putdata();
	}
	
	
}

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

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS