close

Вход

Забыли?

вход по аккаунту

код для вставкиСкачать
1. Provide your analysis for the following problem statement: You need to write a program that
calculates the area and perimeter of a rectangle whose dimensions (Length and width) are
provided by a user.
SOLUTION:
Analysis: User will be asked to provide length and width of the rectangle through keyboard. The
program will consist of three modules. These include
-
-
-
Main module: This module will be the main starting module. It is responsible to get user input
and call other modules to calculate and display rectangle area and perimeter.
calcArea module: This module will take rectangle length and width as input and return rectangle
area as output. Area will be calculated as:
Area = length x width
calcPerimeter module: This module will take rectangle length and width as input and return
rectangle perimeter as output. The parameter will be calculated as:
Perimeter = 2 x width + 2 x length
displayResults module: This module will take Area and Perimeter of the triangle as input
arguments and display results to the user.
2. Provide your program design for the problem you analyzed for calculating and displaying the
area and perimeter of a rectangle. Always work for modular design where possible. Be sure to
use separate functions for calculating the area and perimeter of the rectangle. Other
subprograms for Input and Output should be included as needed. Be sure to describe the
fundamental tasks (i.e., things your program must do) needed to solve the problem so you can
use a modular design. Provide pseudocode of your overall design that includes the Main module
and the order of the module calls, and a Hierarchy chart for the program. Finally, display the
flow charts (using Raptor, or your favorite graphics editor) for each module.
SOLUTION:
Program Design: Here is the design strategy of the program.
At program startup, main module will be executed which will carry out the following steps:
o
o
o
o
o
Declare variables.
Get user input for length and width.
Call calcArea module to calculate area of the rectangle.
Call calcPerimeter module to calculate perimeter of the rectangle.
Call dispResults module to display results to the user.
Psuedocode:
Module Main()
Declare width, height, area, perimeter as float
Display “Enter rectangle height: “
Input height
Display “Enter rectangle width: “
Input width
area = calcArea(width, height)
perimeter = calcPerimeter( width, height)
dispResults(area, perimeter)
End Main
Module calcArea(width, height)
Return with width x height
End calcArea
Module calcPerimeter(width, height)
Return with (2 x width + 2 x height)
End calcPerimeter
Module dispResults(area, perimeter)
Display area
Display perimeter
End dispResults
Hierarchy Chart:
Main
calcArea
Flow Charts:
Main module:
calcPerimeter
dispResults
calcArea Module:
calcPerimeter Module:
dispResults Module:
3. Test Data
S.No
1
2
3
4
Input
Length Width
6
4
2
7
4
3
8
6
Expected Output
Area
Perimeter
24
20
14
18
12
14
48
28
Actual Output
Area
Perimeter
24
20
14
18
12
14
48
28
Result
Pass
Pass
Pass
Pass
1/--страниц
Пожаловаться на содержимое документа