Having troubles with the subject inheritence. This is a myProgramming question u
ID: 3860642 • Letter: H
Question
Having troubles with the subject inheritence. This is a myProgramming question using c++. I was hoping to get some help. Thank you.
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 megabytes of each picture, and an integer named memorySize, representing the number of megabytes 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.
Explanation / Answer
Below is your code. I am assuming Phone class is there, and as I dont know it I cannot write the main function. Let me know in comments if you have any issue: -
class CameraPhone : public Phone { // Declaration of CameraPhone class extending Phone classs
public:
CameraPhone(int imageSize,int memorySize); // Parametrized Contructor
int numPictures(); // function declaration to get number of pictures = memorySize / imageSize
private:
//instance variable declaration
int imageSize;
int memorySize;
};
//Constructor definition with initializer List
CameraPhone::CameraPhone(int imageSize,int memorySize) : imageSize(imageSize), memorySize(memorySize) {}
//Method definition to get number of Pictures
int CameraPhone::numPictures() { return memorySize/imageSize; }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.