YWrite a class LocalPhone that contains an attribute phone to store local phone number. The class contains member functions to input and display phone number. Write a child class NatPhone for national phone number that inherits LocPhone class. It additionally contains an attribute to store city code. It also contains member functions to input and display the city code. Write another class intPhone for international phone number that inherits NatPhone Class. It additionally contains an attribute to store country code. It also contains member functions to input and show the country code.
#include <iostream>
#include <string>
using namespace std;
class LocPhone
{
private:
string phone;
public:
virtual void input()
{
cout<<"Enter phone: ";
getline(cin,phone);
}
virtual void display()
{
cout <<"Phone: "<< phone<<"\n";
}
};
class NatPhone : public LocPhone
{
private:
string cityCode;
public:
virtual void input()
{
LocPhone::input();
cout<<"Enter city code: ";
getline(cin,cityCode);
}
virtual void display()
{
LocPhone::display();
cout <<"City code: "<< cityCode<<"\n";
}
};
class IntPhone : public NatPhone
{
private:
string countryCode;
public:
void input()
{
NatPhone::input();
cout<<"Enter country code: ";
getline(cin,countryCode);
}
void display()
{
NatPhone::display();
cout <<"Country code: "<< countryCode<<"\n";
}
};
int main()
{
LocPhone* localPhone = new LocPhone();
localPhone->input();
localPhone->display();
cout <<"\n\n";
LocPhone* nationalPhone = new NatPhone();
nationalPhone->input();
nationalPhone->display();
cout <<"\n\n";
LocPhone* intPhone = new IntPhone();
intPhone->input();
intPhone->display();
cout <<"\n\n";
delete localPhone;
delete nationalPhone;
delete intPhone;
system("pause");
return 0;
}
Comments
Leave a comment