Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

Students also viewed these Databases questions

Question

What is the factor form of f ( x ) = 8 x 3 + 2 0 x 2 - 2 x - 5

Answered: 1 week ago