Assignment No.4 - Nestedloops
Assignment No.4 - Nestedloops
The following should appear on the screen when your program is executed:
(program should continue asking for the valid input if the input is other than 1 or 2)
Once user enters 1 or 2, user will be given further choice about the shape by giving the following
option to the user:
(Program should continue asking for the valid input if input is other than 1, 2, 3, 4, 5, 6, 7, or 8).
When the user selects his/her choice, the program should prompt the user for the dimension (note
that only one dimension will be required). e.g., the program should prompt as follows:
Page 1 of 5
Enter the dimension:
Finally, the program should ask about the character to be used to draw shapes. e.g., it should
prompt the user in the following manner:
* ? % + $ # ~ @ ( )
(program should continue asking for the valid input if input is other these characters)
Your program should then draw the shape(s) according to the user’s requirements. The program
should repeat itself unless user wishes to stop.
EXAMPLES
Example 1: If the user enters options in the sequence 1 1 5 + (solid, right triangle, five rows, +)
following shape will be drawn:
+
++
+++
++++
+++++
Example 2: If the user choices are 1 2 5 $ (solid, isosceles, 5 rows, $), the following shape will
be drawn:
$
$$$
$$$$$
$$$$$$$
$$$$$$$$$
Example 3: If the user choices are 1 6 8 ? (solid, parallelogram, 8 characters/line, ?) , the following
shape will be drawn:
????????
????????
????????
????????
????????
????????
Example 4: If the user choices are 2 4 7 # (hollow, square, 7 characters/line, #), the following
shape will be drawn:
#######
# #
# #
# #
# #
#######
Page 2 of 5
Example 5: If the user choices are 1 3 4 @ (solid, diamond, 4 rows, @), the following shape will
be drawn (Note, that the rows input by the user should be odd. If not, make them odd yourself by
adding 1. For example, if user enters 4 against rows, add 1 to make it 5):
@
@@@
@@@@@
@@@
@
Example 6: If the user choices are 3 8 5 @ (solid and hollow both, all shapes, size = 5, @), the
following 12 shapes will be drawn:
@
@@
@@@
@@@@
@@@@@
2. Hollow right triangle of 5 rows with @
@
@@
@@
@ @
@@@@@
3. Solid isosceles triangle of 5 rows with @
@
@@@
@@@@@
@@@@@@@
@@@@@@@@@
4. Hollow isosceles triangle of 5 rows with @
@
@ @
@ @
@ @
@@@@@@@@@
Page 3 of 5
5. Solid diamond of 5 rows with @
@
@@@
@@@@@
@@@
@
6. Hollow diamond of size 5 with @
@
@ @
@ @
@@
@
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
8. Hollow square of 5 rows with @
@@@@@
@ @
@ @
@ @
@@@@@
9. Solid rectangle of 5 characters per row with @ (in this case, no. of rows are fixed to 6)
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
10. Hollow rectangle of 5 characters per rows with @ (no. of rows are fixed to 6)
@@@@@
@ @
@ @
@ @
@ @
@@@@@
11. Solid parallelogram of 5 characters per row with @ (no. of rows are fixed to 6)
Page 4 of 5
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
@@@@@
12. Hollow parallelogram of 5 characters per row with @ (no. of rows are fixed to 6)
@@@@@
@ @
@ @
@ @
@ @
@@@@@
You need to write your code in a single cpp file. It should ask the user the shapes, the
user wishes to create. The program should only end on pressing E or e.
- Good Luck –
(Earlier you start sooner you finish)
Page 5 of 5