Answer to Question #213936 in C++ for Maryam

Question #213936

Write a program to print the following details

  • Assign and print the ID of each employee,
  • Phone number and Address of two staff members having names "ali" and "asif" respectively by creating two objects of the class 'Employee'.
  • throw an exception in case the phone number of employee is inserted in float , double or char value.
  • throw an exception in case the ID of an employee is inserted in float , double or char value.
1
Expert's answer
2021-07-05T18:14:32-0400
#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;
}

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