Question
C++ Goals: Problem solving and debugging. User-defined functions. This contains a C++ program designed to draw several pictures of triangles and rectangles. The main function
C++ Goals:
Problem solving and debugging.
User-defined functions. This contains a C++ program designed to draw several pictures of triangles and rectangles. The main function will read in a series of data sets (from a file via Linux redirection) until the end of file is reached. Each data set will start with an R or a T, rectangle or triangle. If the data set starts with a T, it will be followed by 1 integer and 1 character. The integer represents the length of the height and base of a right triangle. The character is to be used when drawing the triangle. If the data set starts with an R, it will be followed by 2 integers and 1 character. The first integer is the vertical height (length) of the rectangle and the second integer is the horizontal width of the rectangle.
The draw_rectangle and draw_triangle functions are incomplete. The prototypes and headings have been supplied, but the statements for the bodies of the functions are needed. For draw_rectangle,
If the length and/or width are less than 2, the function should display an error message that includes the requested length and width and states that the rectangle will not be drawn.
If the length and width are both greater than or equal to 2, then the function should display a label that includes the requested length and width and then draw the rectangle as a hollow shape using the specified character to form the outline (see examples below).
For draw_triangle,
If the length of the base/height is less than 1, the function should display an error message that includes the requested base/height and states that the triangle will not be drawn.
If the base/height value is 1 or more, then the function should display a label that includes the requested base/height and then draw the triangle oriented as shown in the program documentation and samples below.
REQUIREMENTS
Add the statements to implement the draw_triangle and draw_rectangle functions as described in the program. These statements MUST be placed in the body of each function. Do not make any changes to the main function other than adding the print statement mentioned above.
Sample terminal session: [keys]$ more data4enine T 5 + R 3 8 @ T 3 $ R 2 1 & [keys]$ g++ exercise09.cpp [keys]$ ./a.out < data4enine Triangle with height and base of 5 +++++ ++++ +++ ++ + 3 by 8 Rectangle @@@@@@@@ @ @ @@@@@@@@ Triangle with height and base of 3 $$$ $$ $ 2 by 1 Rectangle will not be drawn The code:
//The purpose of this program is to draw a series of geometric figures, //rectangles and right triangles. //Expected input: a file (via Linux redirection) that contains several sets //of data. Each data set consists of a character that indicates the figure //to be drawn, R or T. If the figure is a triangle, the T will be followed //by 1 integer and 1 character. The integer is the length of the height and //base of the triangle. The character is used for the drawing. //If the figure is a rectangle, the R will be followed by 2 integers and 1 //character. The first integer is the vertical height (length) of the rectangle \ //and the second integer is the horizontal width of the rectangle. The character //is used for the drawing.
//Expected output is a labelled drawing of the requested figure or //an appropriate error message. See function descriptions below for details.
#include
void draw_triangle(int,char); void draw_rectangle(int,int,char);
int main() { int height; //the height (or vertical length) of the figure to draw int width; //horizontal width of rectangle to be drawn char symbol; //character used to draw the figure char shape; //shape to be drawn R=rectangle, T=triangle cin >> shape; while (cin) { cin >> height; if (shape == 'R') cin >> width; cin >> symbol; if (shape == 'R') draw_rectangle(height,width,symbol); else draw_triangle(height,symbol); cout << endl; cin >> shape; } }
void draw_triangle(int length, char draw) //Given the length of the height and base of a right triangle along with //a character to be used for drawing it, //If the length is > 0, display the triangle oriented //as follows: ### // ## // # //Include a label that states the length of the height and base. //If the length is <= 0, display message that includes the length and //states that the triangle will not be drawn. {
} void draw_rectangle(int length, int width, char draw) //Given the vertical length and horizontal width of a rectangle along with //a character to be used for drawing it, if both length and width are >= 2, //display the outline of the rectangle with a label that includes the length //and width. //For example, if length=3, width=5, and draw='$', display // $$$$$ // $ $ // $$$$$ //If the length and/or the width are less than 2, display a message //stating that the rectangle will not be drawn. Include the requested dimensions //in the message. {
}
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