0% found this document useful (0 votes)
117 views

Assignment No.4 - Nestedloops

The document provides instructions for a C++ programming assignment to create a menu-driven program that allows a user to select solid or hollow shapes of different types and dimensions. The program must prompt the user to select solid or hollow, then a shape, dimension, and character. Based on the user's input, the program will print the corresponding shape. It provides examples of various shape outputs. The program should repeat until the user exits. The student must write the code in a single C++ file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views

Assignment No.4 - Nestedloops

The document provides instructions for a C++ programming assignment to create a menu-driven program that allows a user to select solid or hollow shapes of different types and dimensions. The program must prompt the user to select solid or hollow, then a shape, dimension, and character. Based on the user's input, the program will print the corresponding shape. It provides examples of various shape outputs. The program should repeat until the user exits. The student must write the code in a single C++ file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Introduction to Computing

[Assignment No.4 – Nested Loops]


Due date: 4th January 2021
READ THE COMPLETE QUESTION BEFORE STARTING THE ASSIGNMENT.
Write a user-interactive menu-driven C++ program to print different solid and hollow
shapes according to the user’s choice.

The following should appear on the screen when your program is executed:

Enter 1 for solid, 2 for hollow:

(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:

Enter your option for the shape type (1 to 8 or E to exit):


1) Right Triangle
2) Isosceles Triangle
3) Diamond
4) Square
5) Rectangle (with number of rows fixed to 8)
6) Parallelogram (with number of rows fixed to 8)
7) Equilateral Triangle
8) All shapes
E) Exit

(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:

Enter the character type:

Only following characters will be assumed as valid characters:

* ? % + $ # ~ @ ( )
(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:

1. Solid right triangle of 5 rows with @

@
@@
@@@
@@@@
@@@@@
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 @

@
@ @
@ @
@@
@

7. Solid square of 5 rows 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

You might also like