Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Language: C++

image text in transcribed

image text in transcribed

Write a 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) S, representing the treetop's width, i.e., the number of "*" in the last row of the treetop. We assume that S 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 S value again. . . When the input S is valid, print the tree according to the following requirements: The treetop is an isosceles triangle composed of S - 1 rows, and each row has an increasing odd number of "*" starting from 1. The trunk is a hollow rectangle with the width S - 4 and the height (S/2] + 1. When the width is greater than 1, only the left-most and the right-most columns are printed. . After the valid S is provided, the user needs to further input one character (data type: char) D. We assume D is correct, i.e., no need to check its correctness, If D is either 'u' or 'U', please print the tree in a normal way. If D 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. Example 1: Please input the width of the treetop: 3 Invalid input! Please input the width of the treetop: 6 Invalid input! Please input the width of the treetop: 5 Please input the direction: U Example 2: Please input the width of the treetop: 7 Please input the direction: Example 3: Please input the width of the treetop: 9 Please input the direction: R

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions