Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

Sol38:

Here's a possible solution in C++:

class CameraPhone : public Phone {

private:

int imageSize;

int memorySize;

public:

CameraPhone(int imageSize, int memorySize) {

this->imageSize = imageSize;

this->memorySize = memorySize;

}

int numPictures() {

return memorySize / imageSize;

}

};

Explanation:

  • The CameraPhone class is derived from the Phone class using the public access specifier, which means that all public members of the Phone class are inherited by CameraPhone.
  • The CameraPhone class has two data members, imageSize and memorySize, which are initialized using a constructor that accepts two integer parameters.
  • The numPictures function calculates and returns the number of pictures that can be stored in the camera's memory by dividing the memorySize by the imageSize.

Note: This is just one possible implementation. Depending on the requirements and constraints of the problem, the implementation may vary.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro Android Graphics

Authors: Wallace Jackson

1st Edition

1430257857, 978-1430257851

More Books

Students also viewed these Programming questions

Question

48. Verify the formula given for the Pi of the M/M/k.

Answered: 1 week ago

Question

46. In the G/M/1 model if G is exponential with rate show that = /.

Answered: 1 week ago