Question
Help me pass all tests. Do not change main.cpp and canvas.h. You can only make changes in a new canvas.cpp file. I will give everyone
Help me pass all tests. Do not change main.cpp and canvas.h. You can only make changes in a new canvas.cpp file. I will give everyone answer a like, just try please :(
----------------main.cpp-------------
#include
using namespace std;
inline void _test(const char* expression, const char* file, int line) { cerr
#define test(EXPRESSION) ((EXPRESSION) ? (void)0 : _test(#EXPRESSION, __FILE__, __LINE__))
int main() {
// Test Canvas(int)
Canvas C0(0); test(C0.width() == 0); test(C0.to_string() == string(""));
Canvas C1(3); test(C1.width() == 3); test(C1.to_string() == string(" ") + " " + " " + " " + " "); Canvas C2(4); test(C2.width() == 4); test(C2.to_string() == string(" ") + " " + " " + " " + " "); Canvas C3(7); test(C3.width() == 7); test(C3.to_string() == string(" ") + " " + " " + " " + " ");
// Test Canvas(char) Canvas C4('A'); test(C4.width() == 5); test(C4.to_string() == string(" ### ") + "# # " + "##### " + "# # " + "# # "); Canvas C5('B'); test(C5.width() == 5); test(C5.to_string() == string("#### ") + "# # " + "#### " + "# # " + "#### "); Canvas C6('C'); test(C6.width() == 5); test(C6.to_string() == string(" #### ") + "# " + "# " + "# " + " #### "); Canvas C7('D'); test(C7.width() == 5); test(C7.to_string() == string("#### ") + "# # " + "# # " + "# # " + "#### "); Canvas C8('E'); test(C8.width() == 5); test(C8.to_string() == string(" ") + " " + " " + " " + " ");
// Test replace() C5.replace('#', '@'); test(C5.width() == 5); test(C5.to_string() == string("@@@@ ") + "@ @ " + "@@@@ " + "@ @ " + "@@@@ "); C5.replace(' ', '-'); test(C5.width() == 5); test(C5.to_string() == string("@@@@- ") + "@---@ " + "@@@@- " + "@---@ " + "@@@@- "); C5.replace('-', '@'); test(C5.width() == 5); test(C5.to_string() == string("@@@@@ ") + "@@@@@ " + "@@@@@ " + "@@@@@ " + "@@@@@ "); C5.replace('@', '$'); test(C5.width() == 5); test(C5.to_string() == string("$$$$$ ") + "$$$$$ " + "$$$$$ " + "$$$$$ " + "$$$$$ "); C6.replace(' ', '*'); test(C6.width() == 5); test(C6.to_string() == string("*#### ") + "#**** " + "#**** " + "#**** " + "*#### "); C7.replace('#', '*'); test(C7.width() == 5); test(C7.to_string() == string("**** ") + "* * " + "* * " + "* * " + "**** "); C8.replace('#', ' '); test(C8.width() == 5); test(C8.to_string() == string(" ") + " " + " " + " " + " ");
// Test add() Canvas C9('A'); C9.add('C'); test(C9.width() == 12); test(C9.to_string() == string(" ### #### ") + "# # # " + "##### # " + "# # # " + "# # #### "); C9.add('B'); test(C9.width() == 19); test(C9.to_string() == string(" ### #### #### ") + "# # # # # " + "##### # #### " + "# # # # # " + "# # #### #### "); C9.add('D'); test(C9.width() == 26); test(C9.to_string() == string(" ### #### #### #### ") + "# # # # # # # " + "##### # #### # # " + "# # # # # # # " + "# # #### #### #### "); C9.add('!'); test(C9.width() == 33); test(C9.to_string() == string(" ### #### #### #### ") + "# # # # # # # " + "##### # #### # # " + "# # # # # # # " + "# # #### #### #### "); C9.add('C'); test(C9.width() == 40); test(C9.to_string() == string(" ### #### #### #### #### ") + "# # # # # # # # " + "##### # #### # # # " + "# # # # # # # # " + "# # #### #### #### #### ");
Canvas C10(0); C10.add('A'); test(C10.width() == 5); test(C10.to_string() == string(" ### ") + "# # " + "##### " + "# # " + "# # ");
Canvas C11(""); C11.add('A'); test(C11.width() == 5); test(C11.to_string() == string(" ### ") + "# # " + "##### " + "# # " + "# # ");
// Test Canvas(string) Canvas C12("ADD"); test(C12.width() == 19); test(C12.to_string() == string(" ### #### #### ") + "# # # # # # " + "##### # # # # " + "# # # # # # " + "# # #### #### "); Canvas C13("VBAD!"); test(C13.width() == 33); test(C13.to_string() == string(" #### ### #### ") + " # # # # # # " + " #### ##### # # " + " # # # # # # " + " #### # # #### "); Canvas C14("DAD CAB"); test(C14.width() == 47); test(C14.to_string() == string("#### ### #### #### ### #### ") + "# # # # # # # # # # # " + "# # ##### # # # ##### #### " + "# # # # # # # # # # # " + "#### # # #### #### # # #### ");
cout
----------------canvas.h------------
In this homework, you'll implement a class that represents "ASCII art" images and operations on them, represented as two-dimensional char arrays allocated on the heap (using the new operator). 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. eturns the entire canvas as a single string, consisting of each row // of the canvas, followed by the newline character (' ). // If the canvas is empty, returns an empty string. 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); // Destructor. Deallocates all of the memory allocated by the canvas. Canvas ( ); // 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: // // \#\#\#\# \#\#\# \#\#\#\# \#\#\#\# \#\#\# \#\#\#\# // ############ // \#\#\#\# \#\#\#\#\#\# \# \# \# \# \#\#\#\#\# \#\#\#\# // \#\#\#\# \# \# \#\#\#\# \#\#\#\# \# \# \#\#\#\# /1 // Any characters in s not from { 'A', 'B', 'C', 'D' } should be // replaced with empty 55 space, just like previous constructor. // If the string is empty (null string), the canvas is empty // (pointer is NULL and _width is ) Canvas(string s); // Adds a character to the Canvas's sequence of characters. void add (char x); private: // A canvas is represented as a 20 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
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