Answer to Question #190749 in C++ for bcvkhjv

Question #190749

 Write a class LocalPhone that contains an attribute phone to store a local telephone 

number. The class contains member functions to input and display phone number. Write a child class NatPhone for national phone numbers that inherits LocPhone class. It additionally contains an attribute to store city code. It also contains member functions to input and show the city code. Write another class IntPhone for international phone numbers that inherit NatPhone class. It additionally contains an attribute to store country code. It also contains member functions to input and show the country code. Test these classes from main() by creating objects of derived classes and testing functions in a way that clear concept of multi-level Inheritance.


1
Expert's answer
2021-05-08T14:27:55-0400
#include <iostream>


using namespace std;


class LocPhone
{
private:
    string phone;


public:
    void input()
    {
        cin >> phone;
    }
    void display()
    {
        cout << phone;
    }
};


class NatPhone : public LocPhone
{
private:
    string cityCode;


public:
    void input()
    {
        cin >> cityCode;
    }
    void display()
    {
        cout << cityCode;
    }
};


class IntPhone : public NatPhone
{
private:
    string countryCode;


public:
    void input()
    {
        cin >> countryCode;
    }
    void display()
    {
        cout << countryCode;
    }
};




int main()
{
    LocPhone* localPhone = new LocPhone();
    cout << "Enter phone: ";
    localPhone->input();


    cout << "Local phone: ";
    localPhone->display();
    cout << endl << endl;


    LocPhone* nationalPhone = new NatPhone();
    cout << "Enter city code: ";
    nationalPhone->input();


    cout << "City code: ";
    nationalPhone->display();
    cout << endl << endl;


    LocPhone* internationalPhone = new IntPhone();
    cout << "Enter country code: ";
    internationalPhone->input();


    cout << "Country code: ";
    internationalPhone->display();
    cout << endl << endl;




    delete localPhone;
    delete nationalPhone;
    delete internationalPhone;


    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