Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need help writing this code thank you For both problems, write your code incrementally. This means write only enough code to solve a particular step

image text in transcribed
need help writing this code thank you
For both problems, write your code incrementally. This means write only enough code to solve a particular step in the algorithms provided below and then compile and test that portion thoroughly before writing your solution to the next algorithmic step. Test your code on small input values first and handle boundary and error cases early in coding your solution. 1. Program hour-glass.cpp using the starter template provided: (a) Prompt and read in the number of '#'s in the top row; (b) If the number of '#'s is less than three, print the error message "Size of the top row must be at least three.", and prompt again for the number of '#'s in the top row. Repeat until the user enters a valid number. (Use a while loop.) (c) Prompt and read in the number of rows from the top row to the middle row. (d) If the number of rows is invalid then print "Invalid number of rows." and prompt again for the number rows. An invalid number of rows would be a number less than 1 or a number that leads to a row in the hour glass with less than two '#'s. Repeat until the user enters a valid number of rows. (Use a while loop.) (e) Display an empty line. (f) Use for loops to display the hour glass. Your outer for loop will iterate over the number of rows times. For each row use one nested for loop to display blanks (the top row contains no blanks) and another nested for loop to display the characters First, test your code on a top row size of 3 '#'s and one row. Your program should display only one total row. Second, test your code on a top row size of 4 '#'s and two rows. Continue testing your code for larger input values and combinations. Test your code on invalid input to ensure that only valid values are used when displaying the hour glass

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions