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).
Input width: 7
Input height: 4
Shape:
*******
*******
*******
*******
width
times followed by end-of-line).height
times (using a loop).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).
Input width: 11
Input height: 6
Shape:
* * * * * *
* * * * *
* * * * * *
* * * * *
* * * * * *
* * * * *
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
.
Write a program cross.cpp
that asks the user to input the shape size
, and prints a diagonal cross of that dimension.
Input size: 8
Shape:
* *
* *
* *
**
**
* *
* *
* *
Write a program lower.cpp
that prints the bottom-left half of a square, given the side length
.
Input side length: 6
Shape:
*
**
***
****
*****
******
Write a program upper.cpp
that prints the top-right half of a square, given the side length
.
Input side length: 5
Shape:
*****
****
***
**
*
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!
Input width: 12
Input height: 5
Shape:
************
**********
********
******
****
Input width: 12
Input height: 7
Impossible shape!
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;
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.)
Input width: 16
Input height: 11
Shape:
*** *** ***
*** *** ***
*** *** ***
*** *** *
*** *** *
*** *** *
*** *** ***
*** *** ***
*** *** ***
*** *** *
*** *** *
Input width: 27
Input height: 27
Shape:
*** *** *** *** ***
*** *** *** *** ***
*** *** *** *** ***
*** *** *** ***
*** *** *** ***
*** *** *** ***
*** *** *** *** ***
*** *** *** *** ***
*** *** *** *** ***
*** *** *** ***
*** *** *** ***
*** *** *** ***
*** *** *** *** ***
*** *** *** *** ***
*** *** *** *** ***
*** *** *** ***
*** *** *** ***
*** *** *** ***
*** *** *** *** ***
*** *** *** *** ***
*** *** *** *** ***
*** *** *** ***
*** *** *** ***
*** *** *** ***
*** *** *** *** ***
*** *** *** *** ***
*** *** *** *** ***
Write separate programs for each part of the assignment.
Submit only the source code (.cpp) files, not the compiled executables.
Each program should start with a comment that contains your name and a short program description, for example:
/*
Author: your name
Course: CSCI-136
Instructor: their name
Assignment: title, e.g., Lab1A
Here, briefly, at least in one or a few sentences
describe what the program does.
*/