Write a program to print the following details Assign and print the ID of each employee, (1+1+1.5+1.5) 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.
#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