Write a program to print the pattern of a simple tree. This tree has two parts,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. • IfD 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 3 Example 2: Please input the width of the treetop: 7 Please input the direction: u Example 3: Please input the width of the treetop: 9 Please input the direction: R 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. • IfD 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 3 Example 2: Please input the width of the treetop: 7 Please input the direction: u Example 3: Please input the width of the treetop: 9 Please input the direction: R
Expert Answer:
Related Book For
Auditing and Assurance services an integrated approach
ISBN: 978-0132575959
14th Edition
Authors: Alvin a. arens, Randal j. elder, Mark s. Beasley
Posted Date:
Students also viewed these programming questions
-
Write a program to print Hello World 25 times without writing a single line in the main function except system(pause).
-
Write a program to print the diamond shape using user-specified character and size, where the size should be an even number greater than or equal to 6. The program will keep asking the user for a...
-
write a program to print the output as shown below by using while loop. IN C++ 2 1 2 1 3 2 1 4 3 2 1 5 4 3 2 1
-
A coil of wire 0.1 m long and having 15 turns carries a current of 1.0 A. (a) Compute the flux density if the coil is within a vacuum. (b) A bar of an iron-silicon alloy, the B-H behavior for which...
-
A study has estimated the effect of changes in interest rates and consumer confidence on the demand for money to be: log M = 14.666 + .021 log C - .036 log r, where M denotes real money balance. C is...
-
Automotive researchers have reported that building the Ford Mustang required an average of 22.3 labor hours. Under the assumption that this finding was based on the sample data in file XR09041,...
-
Why a temporary restraining order or preliminary injunction may be necessary?
-
Consider the January transactions for Davis Consulting that were presented in Chapter 5. (Cost data have been removed from the sale transactions.) Davis uses the perpetual inventory system. Jan. 2...
-
McDonalds is among the largest restaurant chains in the world. What are the some of the strategies used by McDonalds to turn around their slipping sales? Who drove the turnaround? please do fast and...
-
Tax Software Assignment - Fall 2023 Ms. Jeanette Letourneau (SIN 123-456-789) was born in Montreal on December 15, 1979. She has spent most of her working life a song writer but also has a part-time...
-
The following scenario is the basis for the next four questions. A small, family-owned bakery has received a contract to supply bread to several play centers operated in nearby malls by a...
-
Sphere Foods Company produces a candy called "Little Stars," a bag of dozen, individually wrapped, star-shaped candies made primarily from a blend chocolate, macadamia nuts, and a blend of heavy...
-
The following salaried employees of Mountain Stone Brewery in Fort Collins, Colorado, are paid semimonthly. Some employees have union dues or garnishments deducted from their pay. You do not need to...
-
why are open-ended questions are best when surveying?
-
Consider the material structure tree for item A above. If 20 units are needed, how many units of D are needed if there are already 10 B's and 10 C's in inventory?
-
An organization hosting a 5K race is looking to sell t-shirts at the event. Demand for t-shirts is believed to be normally distributed with a mean of 100 and standard deviation of 15. With a marginal...
-
I would like you to write a paragraph persuading your classmates and I to do something. It could be anything: try a sport, donate to a charity, join a political party, try a new type of food. It's up...
-
In Exercises 516, find the focus and directrix of the parabola with the given equation. Then graph the parabola. y 2 = 4x
-
Explain why inherent risk is set for segments rather than for the overall audit. What is the effect on the amount of evidence the auditor must accumulate when inherent risk is increased from medium...
-
The following (1 through 18) are the balance-related, transaction-related, and presentation and disclosure related audit objectives. Balance-Related Audit Objectives 1. Existence 2. Completeness 3....
-
Ray, the owner of a small company, asked Holmes, a CPA, to conduct an audit of the company's records. Ray told Holmes that an audit was to be completed in time to submit audited financial statements...
-
a. What responsibility does the auditor have when he believes material errors or irregularities may exist? b. What are the possible effects of the foregoing on the auditor's standard report?
-
Watts and Williams, a firm of certified public acccountants, audited the accounts of Sampson Skins, Inc., a corporation that imports and deals in fine furs. Upon completion of the examination the...
-
a. Can an examination made in accordance with generally accepted auditing standards be relied upon to detect illegal acts? Why or why not? b. What are the possible effects of illegal acts on the...
Study smarter with the SolutionInn App