Question: THIS IS A C++ ASSIGNMENT Libraries you may use: iostream fstream The use of any other libraries will result in the loss of points. Purpose:

THIS IS A C++ ASSIGNMENT

Libraries you may use:

iostream

fstream

The use of any other libraries will result in the loss of points.

Purpose: The purpose of this assignment is to continue to build our familiarity with classes and the object oriented paradigm as well as to proctice working with recursion, specifically flood fill!. We are revisiting our painting program from before, but with several variations: the actual painting will be done inside a class called canvas, the program should be able to load images from file, and there will be an additional flood functionality. Again, this is a chance for you to show off some creativity!

Task: First, you will need to define a canvas class with the following member attributes and functionality:

char arr[MAX_ARRAY][MAX_ARRAY] - this is your new 2D array for all painting. It should be private.

int rows - this should be private, it denotes how many rows make up your drawing. It should be less than MAX_ARRAY.

int cols - this should be private, it denotes how many columns make up your drawing. It should be less than MAX_ARRAY.

void print() - this function needs to be accessible by everyone. It will need to loop over your arr and print all data to the console.

void paint_pixel(int row, int col, char pixel) - this function needs to be accessible by everyone. It will accept a location, as well as a character denoting what value to place in that location of the array. If an invalid location is provided, your function should inform the user and return, making no changes

void swap_all(char orig, char target) - this function needs to be accessible by everyone. It should loop over your array and replace every instance of orig with target.

void save_to_file(char str[]) - save your canvas out to the indicated file. It should first print out the number of rows and then the number of columns used, then it should simply the contents of your 2D array arr. (This way it can be read in and modified later).

void flood(int row, int col, char fill, char block) - this is your flood fill function. For the base assignment, you need to make sure you flood up, down, left, and right. You will flood until you hit the edge of your canvas, or you see the character block.

canvas() - a default constructor. Make sure all member variables are initialized properly (don't forget to initizlize arr!).

void load_data(char str[]) - allow the user to load a saved image to work from if they desire.

In your main, you will need to create a canvas object, and then pass it to one other function you will need to implement in main.cpp:

paint(canvas& c) - this should launch the main driver of your program, where you will ask the user what they want to do, and continue until they indicate they would like to quit the program

Make sure that your program can (minimally) handle a 30x30 canvas.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!