Program 4 – Phone No. Class

A phone number, such as (212) 767-8900, can be thought of as having three parts: the area code (212), the exchange (767) and the number (8900). Write a program that uses a class to store these three parts of a phone number separately. Call the class phone. Create two class objects of type phone. Initialise one, and have the user input a number for the other one. Display both the numbers.

#include<iostream>
using namespace std;

class Phone{
    private : 
        int exch, aCode, num;
    public:
        Phone()
        {
            this->exch = 767;
            this->aCode = 212;
            this->num = 8900;
        }
        Phone(int exch, int aCode, int num)
        {
            this->aCode = aCode;
            this->num = num;
            this->exch = exch;
        }
        void Display()
        {
            cout<<"("<<aCode<<")"<<" "<<exch<<"-"<<num<<"\n";
        }

}*p1, *p2;

int main()
{
    int exch, aCode, num;
    p1 =  new Phone();
    cout << "Initialised phone class:\n";
    p1->Display();
    cout << "Enter area code: ";
    cin >> aCode;
    cout << "Enter exchange: ";
    cin >> exch;
    cout << "Enter num";
    cin >> num;
    p2 = new Phone(exch , aCode, num);
    cout << "Input phone class:\n";
    p2->Display();


    return 0;
    
}