QuestionQuestion

Transcribed TextTranscribed Text

Printing Shapes Task A. Box Write a program box.cpp that asks the user to input width and height and prints a solid rectangular box of the requested size using asterisks. Also, print a line Shape: between user input and the printed shape (to separate input from output). Example: Input width: 7 Input height: 4 Shape: ******* ******* ******* ******* Hint: First find how to print one row of stars (print the asterisk character width times followed by end-of-line). Then, once you know how to print one line of stars, repeat it height times (using a loop). Task B. Checkerboard Write a program checkerboard.cpp that asks the user to input width and height and prints a rectangular checkerboard of the requested size using asterisks and spaces (alternating). Example: Input width: 11 Input height: 6 Shape: ****** ***** ****** ***** ****** ***** Hint: You used nested loops in the previous task that looked probably like for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { ... } } Inside the loops, you can add an if statement that will be conditionally printing asterisk * or (space) depending on the coordinates row and col . Task C. Cross Write a program cross.cpp that asks the user to input the shape size , and prints a diagonal cross of that dimension. Example: Input size: 8 Shape: ** ** ** ** ** ** ** ** Task D. Lower triangle Write a program lower.cpp that prints the bottom-left half of a square, given the side length . Example: Input side length: 6 Shape: * ** *** **** ***** ****** Task E. Upper triangle Write a program upper.cpp that prints the top-right half of a square, given the side length . Example: Input side length: 5 Shape: ***** **** *** ** * Task F. Upside-down trapezoid Write a program trapezoid.cpp that prints an upside-down trapezoid of given width and height . However, if the input height is impossibly large for the given width, then the program should report, Impossible shape! Example 1: Input width: 12 Input height: 5 Shape: ************ ********** ******** ****** **** Example 2: Input width: 12 Input height: 7 Impossible shape! Hint: You can start with the number of spaces = 0; stars = width; On each line, print that number of spaces followed by that number of stars. After that, the number of spaces gets incremented by 1, while the number of stars gets decremented by 2: spaces += 1; stars -= 2; Task G. Checkerboard (3x3) Write a program checkerboard3x3.cpp that asks the user to input width and height and prints a checkerboard of 3-by-3 squares. (It should work even if the input dimensions are not a multiple of three.) Example 1: Input width: 16 Input height: 11 Shape: *** *** *** *** *** *** *** *** *** *** *** * *** *** * *** *** * *** *** *** *** *** *** *** *** *** *** *** * *** *** * Example 2: Input width: 27 Input height: 27 Shape: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

Box problem:

#include <iostream>

using namespace std;

int main(){

int width;
int height;

cout << "Input width: ";
cin >> width;

cout << "Input height: ";
cin >> height;

cout << endl;

cout << "Shape:" << endl;

for (int i=0; i<height; i++){
for(int j=0; j<width; j++){
cout << "*";
}
cout << endl;
}

}...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

50% discount

Hours
Minutes
Seconds
$30.00 $15.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats