Question: Write a C++program to print the pattern of a simple tree. This tree has two parts, including the treetop and the trunk. After the program

Write a C++program to print the pattern of a simple tree. This tree has two parts, including the treetop and the trunk. After the program starts, the user inputs an integer value (data type: int) , representing the treetop's width, i.e., the number of * in the last row of the treetop.

We assume that is an odd number and is no smaller than 5. So, the program needs to check the correctness of this input. If it is invalid, the user needs to input another value again.

When the input is valid, print the tree according to the following requirements:

The treetop is an isosceles triangle composed of rows, and each row has an increasing odd number of "*" starting from 1.

The trunk is a hollow rectangle with the width and the height +. When the width is greater than 1, only the left-most and the right-most columns are printed.

After the valid is provided, the user needs to further input one character (data type: char) .

We assume is correct, i.e., no need to check its correctness. If is either u or U, please print the tree in a normal way.

If is either r or R, please print the tree in a reversed way, i.e., from truck to the treetop. The shape of each part in the tree still follows the requirements above.

Note.

1.It is NOT necessary to include any other library, except .

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!