APPLIED PROGRAMMING (APR520S) ASSIGNMENT 1

Problem Solving Tools Total Marks: 50 Marks Due: Friday 22 August 2014

Suppose we want to construct a C/C++ program that can be used to calculate the area or the volume for a range of 2-D and 3-D shapes respectively. Consider only the following shapes.
(a) 2-dimensional shapes: triangle, square, rectangle, circle, and trapezium

(b) 3-dimensional shapes: cuboid, cylinder, cone, and sphere

Suppose that we want our program to firstly ask the user whether to calculate the area (2-D) or volume (3-D), then secondly ask for the type of the shape, then thirdly ask for inputs of all required dimensions, then fourthly calculate the required area or volume, and then finally display the required result to the user.

Required:

1. Construct a flowchart for this C/C++ program. [15]
2. Develop a pseudocode for this C/C++ program. [15]
3. Construct a hierarchy (structure) chart for this C/C++ program. [10]
4. Construct an IPO chart for this C/C++ program. [10]

Technically you do not need to ask for a 2D or 3D calculation because there is no overlap of the shape names.

You will need a string of if-else-elseif-endif statements, or more conveniently a switch statement. Use the "default:" option in case the user feeds a wrong shape.

Evidently the input and calculations are all different for all cases, but the output can be done in two cases, 2D or 3D (which can be determined according to the shape).

Post your proposition (pseudocode) and comments will be offered.

1. Construct a flowchart for this C/C++ program:

To construct a flowchart for this program, we need to break down the steps and decisions involved in calculating the area or volume for different shapes.

- Start
- Ask the user whether to calculate the area or volume
- If area, go to 2-D shapes
- Ask for the type of 2-D shape (triangle, square, rectangle, circle, or trapezium)
- Ask for inputs of required dimensions (base, height, side length, etc.)
- Calculate the area using the specific formula for the chosen shape
- Display the calculated area
- If volume, go to 3-D shapes
- Ask for the type of 3-D shape (cuboid, cylinder, cone, or sphere)
- Ask for inputs of required dimensions (length, width, height, radius, etc.)
- Calculate the volume using the specific formula for the chosen shape
- Display the calculated volume
- End

2. Develop a pseudocode for this C/C++ program:

To develop pseudocode for this program, we can follow the steps outlined in the flowchart.

```
start
ask user whether to calculate area or volume
if area
go to 2D shapes section
else if volume
go to 3D shapes section

2D shapes section:
ask user for the shape type (triangle, square, rectangle, circle, or trapezium)
ask user for the required dimensions based on the shape type
calculate the area using the specific formula for the chosen shape
display the calculated area

3D shapes section:
ask user for the shape type (cuboid, cylinder, cone, or sphere)
ask user for the required dimensions based on the shape type
calculate the volume using the specific formula for the chosen shape
display the calculated volume

end
```

3. Construct a hierarchy (structure) chart for this C/C++ program:

The hierarchy chart shows the structure of the program and how the different modules or functions are connected to each other.

```
Main Program
- Ask User
- Calculate 2D Area
- Calculate Triangle Area
- Calculate Square Area
- Calculate Rectangle Area
- Calculate Circle Area
- Calculate Trapezium Area
- Calculate 3D Volume
- Calculate Cuboid Volume
- Calculate Cylinder Volume
- Calculate Cone Volume
- Calculate Sphere Volume
- Display Result
```

4. Construct an IPO chart for this C/C++ program:

The IPO chart shows the inputs, processing, and outputs for each module or function in the program.

```
Calculate 2D Area
Inputs: 2D Shape Type (string), Dimensions (varies based on shape type)
Processing: Calculate Area using specific formula for the chosen shape
Output: Area (float)

Calculate 3D Volume
Inputs: 3D Shape Type (string), Dimensions (varies based on shape type)
Processing: Calculate Volume using specific formula for the chosen shape
Output: Volume (float)
```