Answer to Question #214248 in Programming & Computer Science for Laraib

Question #214248

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.


1
Expert's answer
2021-07-06T08:23:47-0400
#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;
}





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