Essay on Jameswesthw4 Copy

Submitted By KevinMalone11
Words: 780
Pages: 4

Homework 4

CMIS 102
June 28, 2015

Program Description

This program will calculate the area and perimeter of the rectangle. It will prompt the user to input the length and width of the rectangle and calculate the area and perimeter from those values.

Analysis

The program will use sequential, repetition, and selection statements and functions for the area and perimeter calculations.
I will define another as an integer
I will define length, width, area, and perimeter as floats
I will set ‘another’ equal to 1. This variable will be used in a while loop as shown below
While (another ==1) {do code}
Because I set it to one at the beginning, the loop will automatically run the first time through, then after the first rectangle’s area and perimeter have been calculated, the program will prompt the user whether they would like to enter another rectangles length and width to calculate. This will ensure that any number of rectangles can be calculated, as the user will determine when the loop/program ends by their input.
The variables length and width will be used to store the float value input by the user; area and perimeter will be used to hold the calculations made by the programs functions.
The area function will take two floats as input and return one float as the output. The area function calculation is, area = length * width.
Likewise the perimeter function will take the same two floats as input and return one float as the output. The calculations within the perimeter function as follows. length = length * 2 width = width * 2 perimeter = length + width
Both functions are call by value, therefore within the functions any change to the value of the variables called will not affect the actual value of those variables.
Because the functions are calling by value, in the print statements after the functions the program is still able to use the original user input values as the variables values don’t change.

Test Plan

Test Case Number
Input
Expected Output
1
Length = 9
Width = 17
Area = 153
Perimeter = 52
2
Length = 6
Width = 3
Area = 18
Perimeter = 18
3

Length = 4.5
Width = 8.75
Area = 39.38
Perimeter = 26.50

Pseudocode

//Starting the program

Start

//Declare variables

Declare length, width, area, and perimeter as float

Declare another as Integer

//Setting another equal to 1

Set another = 1

//While loop so any number of rectangles can be calculated.

While (another == 1)

//Prompting user for ‘length’ input

Print “Enter the length of the rectangle.”

//Placing the user input into the variable ‘length’

Input ‘length’

//Prompting user for ‘width’ input

Print “Enter the width of the rectangle.”

//Placing the user input into the variable ‘width’

Input ‘width’

//Calling the area function and placing the result in the variable ‘area’.

Set area = areaFun(length, width)

//Printing the area onto the screen for output.

Print “The area of a rectangle with a length of ‘length’ and a width of ‘width’ is ‘area’.

//Calling the perimeter function and placing the result in the variable ‘perimeter’.

Set perimeter = perimeterFun(length, width)

//Printing the perimeter onto the screen for output.

Print “The perimeter of a rectangle with a length of ‘length’ and a width of ‘width’ is ‘perimeter’.

//Prompting the user to determine whether another rectangle will be calculated.