BIG C++ Cay Horstmann & Timothy Budd
Laboratory Notebook Chapter 18 – Memory Management
Your name:
Your email address:
Your student ID number:
Once this form has been customized for your institution, you can use this button to send your lab work. Be sure to read the instructions before starting your work.
To gain experience with
In this problem, you will define and implement a class that represents a digital, grayscale image. Grayscale images are stored in computers as arrays of data where each value within the array is an integer that ranges between 0 and 255. Zero represents black and 255 represents white. Because image processing algorithms often manipulate large amounts of data, speed is essential. Therefore, you will store the two-dimensional image data within a one dimensional array.
First, define the Image class as provided by the code below. Then, implement all of the functions for this class. Implement only those functions shown. You will be adding functions in later problems.
Note that the constructor takes the name of a file as a parameter. This file should be a text file of integer numbers separated by spaces. There are two images provided for you to test your code: image one is size 56 x 59 and image two is size 60x60. Take a look at the provided text files and corresponding bit-map images before trying to implement the constructor. The displayImage() function should display the stored image to the console window using the following rules: use a space for values less than 64, use a period if the value is greater than or equal to 64 but less than 128, use a * if the value is greater than or equal to 128 but less than 192, and use an @ otherwise.
Text Image (1)
Text Image (2)
Class Image
{
public:
Image(int nRows, int nCols, string filename);
int getRows();
int getCols();
int getPixelValue(int row, int column);
void displayImage();
private:
int* imArray;
int numRows, numCols;
};
Submit all of the code for your answer in the space below.
Enter the type of data stored in the above category.
Provide the code for the destructor in the space below.
P3. Assignment Operator
Next, write an assignment operator for your Image class. Be careful: The size of the image on the left-hand-side of the operator is not necessarily the same size as the image on the right-hand-side. The function declaration is shown below. List your code in the space provided.
Image& Image::operator=(const Image& right);
R4. Reference Counting
In the space provided, proceed through the process of reference counting for each of the three objects existing within the main function below. Include in your answer specific counts after each instruction. You should already be familiar with the operation and implementation of the SharedString class as supplied by the text.
int main()
SharedString a;
SharedString b;
SharedString c;
a = b;
b = c = a;
b = b;
c = b;
a = a;
return 0;
}
Do not forget to send your answers when you are finished.