Assume the existence of a Phone class. Define a derived class, CameraPhone that contains two data members: an integer named, imageSize, representing the size in megapixels of each picture, and an integer named memorySize, representing the number of gigabytes in the camera’s memory. There is a constructor that accepts two integer parameters corresponding to the above two data members and which are used to initialize the respective data members. There is also a function named numPictures that returns (as an integer) the number of pictures the camera’s memory can hold.

LANGUAGE: C++

CHALLENGE:

Assume the existence of a Phone class. Define a derived class, CameraPhone that contains two data members: an integer named, imageSize, representing the size in megapixels of each picture, and an integer named memorySize, representing the number of gigabytes in the camera’s memory. There is a constructor that accepts two integer parameters corresponding to the above two data members and which are used to initialize the respective data members. There is also a function named numPictures that returns (as an integer) the number of pictures the camera’s memory can hold.

SOLUTION:


class CameraPhone :public Phone {
    public:
    CameraPhone(int, int);
    int numPictures();
    private:
    int imageSize;
    int memorySize;
};

CameraPhone::CameraPhone(int myimageSize, int mymemorySize) {
        imageSize  = myimageSize;
        memorySize = mymemorySize;
    } 

    int CameraPhone::numPictures() {
        return memorySize /  imageSize;
     }