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
Leave a comment