Write a program to print the following details
#include <iostream>
using namespace std;
class Employee{
private:
int id;
string phoneNo;
string name;
string address;
public:
Employee(){
}
Employee(string n){
name=n;
}
string getPhoneNo(){
try {
cout<<"\nEnter Phone Number: ";
cin>>phoneNo;
return phoneNo;
}
catch (exception e) {
cout <<"\nError";
}
}
string getAddress(){
try {
cout<<"\nEnter name: ";
cin>>address;
return address;
}
catch (exception e) {
cout <<"\nError";
}
}
int getID(){
try {
cout<<"\nEnter ID: ";
cin>>id;
return id;
}
catch (exception e) {
cout <<"\nError";
}
}
};
int main()
{
Employee e1;
Employee e2("ali");
Employee e3("asif");
int id1=e2.getID();
cout<<"\nAli's ID:"<<id1;
int id2=e3.getID();
cout<<"\nAsif's ID:"<<id2;
e2.getPhoneNo();
e3.getAddress();
return 0;
}
Comments