Question
NEED HELP with the canvas.cpp file: We are asked to implement a class that represents ASCII art images and operations on them. The image is
NEED HELP with the canvas.cpp file: We are asked to implement a class that represents "ASCII art images and operations on them. The image is given below. Also are the header and source files.
The following files are given to you: 1. A C++ header file (canvas.h) declaring the Canvas class. 2. A C++ source file (main.cpp) containing a main() function with tests. Create a new C++ source file named canvas.cpp that implements the class declared in canvas.h so that canvas.cpp and the provided files compile into a program that runs with no failed tests.
main.cpp - https://gist.github.com/anonymous/fcbd92935c5e98aa6642824c556d5d55 canvas.h - https://gist.github.com/anonymous/1b1ecd154e31065f3ba6d00d9387efc7 main.cpp
#include #include #include #include "canvas.h" using namespace std; inline void _test(const char* expression, const char* file, int line) { cerr 'D') invalid_chars += line[i]; if (invalid_chars.size() > 0) { cout 0) { Canvas C(line); C.replace('#', ink); cout#ifndef CANVAS_H #define CANVAS_H #include using namespace std; // In this homework, you'll manipulate ASCII art images // consisting of a rectangular grid of chararacter pixels. class Canvas { public: // Allocates a canvas of the given width and height 5 that // consists entirely of ' ' (space) chars. Canvas(int width); // Allocates a canvas with width 5 and height 5 that looks like: // // ### #### #### #### // # # # # # # # // ##### or #### or # or # # // # # # # # # # // # # #### #### #### // // depending upon which character ('A', 'B', 'C', or 'D') is // given as a parameter. If some other character is given, // allocates a canvas of ' ' chars with width 5 and height 5. Canvas(char x); // Allocates a canvas containing the sequence of characters // in the string with 2 columns of space between each pair // of adjacent characters. For instance, Canvas("BADCAB") // should yield: // // #### ### #### #### ### #### // # # # # # # # # # # # // #### ##### # # # ##### #### // # # # # # # # # # # # // #### # # #### #### # # #### // // Any characters in s not from {'A', 'B', 'C', 'D'} should be // replaced with empty 5x5 space, just like previous constructor. Canvas(string s); // Returns the width of the canvas. int width(); // Returns the entire canvas as a single string, consisting of each row // of the canvas, followed by the newline character (' '). string to_string(); // Replaces every instance in the canvas of old_char with new_char. // For instance, if old_char is '#' and new char is '@', then: // // ### @@@ // # # @ @ // ##### becomes @@@@@ // # # @ @ // # # @ @ // void replace(char old_char, char new_char); // Adds a character to the Canvas's sequence of characters. void add(char x); // Destructor. Deallocates all of the memory allocated by the canvas. ~Canvas(); private: // A canvas is represented as a 2D char array, i.e. // an array of pointers to char (sub)arrays. // Each subarray corresponds to a column of the image. char** C; int _width; }; #endifIn this homework, you'll implement a class that represents "ASClI art" images and operations on them, represented as two-dimensional char arrays allocated on the heap (using the new keyword) char** C width char* array char arrays
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started