Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assume the existence of a Phone class . Define a derived class , CameraPhone tha

ID: 3545399 • Letter: A

Question

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.

Explanation / Answer

I'm giving the solution which can be compiled in Visual C++,

#include "stdafx.h"

#include "iostream"

using namespace std;

class Phone

{

public:

Phone()

{

cout<<"Phone class constructer fired"<<endl;

}

};

class cameraphone : public Phone

{

private:

int filesize,memory;

public:

cameraphone();

cameraphone(int a, int b)

{

filesize=a;

memory=b;

}

int numpic()

{

int t;

t=(1024*memory)/filesize;

return t;

}

};


int _tmain(int argc, _TCHAR* argv[])

{

cameraphone c;

int fs,m;

cout<<"Enter file size and memory"<<endl;

cin>>fs>>m;

int result;

result=c.numpic();

cout<<"The number of pictures which can be stored on the memorycard are "<<result;


return 0;

}


Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote