Free Essay

Cmis 102 Hw 4

In: Computers and Technology

Submitted By cblack21
Words 1160
Pages 5
Homework Assignment 4

Charles Black

CMIS102-4015

Professor Dale Goode

27Sep15

Problem definition: Write a program, using functions, that calculates the area and perimeter of a rectangle whose dimensions (length and width) are provided by a user.

A. Problem Analysis – Following the directions in the assignment, clearly write up your problem analysis in this section.

In this problem, we have to calculate and display the area and perimeter for set of input values, entered by user. We will take input from user for length and width. And then calculate the area and perimeter for rectangle for the numbers input.

Desired Output:

The desired output is area and perimeter of rectangle.

Required Input:

The required input consists of the length and width of the rectangle. The program asks user to input length and width of rectangle.

Calculations: Variables used: length: (float) to store value of length of rectangle entered by user width: (float) to store value of width of rectangle entered by user Area: (float) to store area of rectangle Perimeter: (float) to store perimeter of rectangle
Formula for Calculating Area of Rectangle
Area = length * width
Formula for Calculating Perimeter of Rectangle
Perimeter = 2 *( length + width )

Sample Calculation
Suppose we have following user input:

Length =4.0

Width=8.0

Subprogram Calculate_Area (length,width,Area) Calculate_Area (4.0,8.0 ) Area = length * width = 4 * 8 = 32
Subprogram Calculate_Perimeter (length,width, Perimeter) Calculate_ Perimeter (4.0,8.0 )

Perimeter = 2 *( length + width ) = 2 *( 4 + 8 ) = 24

B. Program Design – Following the directions in the assignment, clearly write up your problem design in this section and comment your pseudocode. (Let’s include our Raptor/flowchart and a hierarchy structure chart here for Homework 3 and 4 and for our Final Project.)

We will use modular design for this program that consists of a main module and four submodules, displayed as follows:

// In this program we will use four functions

Main Module Call Input_Data module Call Calculate_Area module Call Calculate_Perimeter module Call Output_Data module
Input_Data module Input the length, length Input the width, width
Calculate_Area module Set Area = length * width
Calculate_Perimeter module Set Perimeter = 2 * (length + width)
Output_Data module Write Area Write Perimeter

In Area and Perimeter Computation program: • Input_Data module inputs data, length and width, from the user. • In Calculate_Area module, Area is calculated from the value of length and width. Calculate_Area module is passed the values of length and width from the main module. The value of Area is calculated here and set in this module. • In Calculate_Perimeter module, Perimeter is calculated from the value of length and width. Calculate_ Perimeter module is passed the values of length and width from the main module. The value of Perimeter is calculated here and set in this module. • Output_Data module displays the value of Area and Perimeter, so values are passed in this module from main module.

Pseudo code

/****************************************************

* Area and perimeter Computation *
* *
* program calculates and display area and *
* Perimeter of rectangle *
* *
*****************************************************/

// Variables used:
// length: to store value of length of rectangle entered by user
// width: to store value of width of rectangle entered by user
// Area: to store area of rectangle calculated by program
// Perimeter: to store perimeter of rectangle calculated by program

/* In this program, we will use four functions to calculate and display area and perimeter of rectangle. */
Main Module //Declare variables Declare length, width, Area, Perimeter as Float /* Here we are calling function Input_Data with length and width as input parameter */ Call Input_Data(length, width) /* Here we are calling function Calculate_Area with length, width and Area as input parameter */ Call Calculate_Area(length, width, Area) /* Here we are calling function Calculate_Perimeter with length, width and Perimeter as input parameter */ Call Calculate_Perimeter(length, width, Perimeter) /* Here we are calling function Output_Data with Area and Perimeter as input parameter */ Call Output_Data(Area, Perimeter)
End Program

// Subprogram Input_Data

/* In this function we will take input from user for length and width of rectangle. Length and width are passed by reference to the function. Hence the value of length and width set in this function can be used throughout the program. */

Subprogram Input_Data(Number1 As Ref, Number2 As Ref) // Display the message to user Write “Input the length: ” // Get the value from user Input Number1 // Display the message to user Write “Input the width: ” // Get the value from user Input Number2
End Subprogram

// Subprogram Calculate_Area
/* In this function, area of rectangle is calculated. Length and width are passed as first two parameters of function. They are passed by value to the function. Variable Area is passed as third parameter to function. It is passed by reference to the function. Hence, the value of Area set in this function will be used throughout the program */

Subprogram Calculate_Area (Number1, Number2, Number3 As Ref) //Declare variable Set Number3= Number1 * Number2
End Subprogram

// Subprogram Calculate_Perimeter
// Calculates Perimeter using formula 2 * ( length + width)
/* In this function, perimeter of rectangle is calculated. Length and width are passed as first two parameters of function. They are passed by value to the function. Variable Perimeter is passed as third parameter to function. It is passed by reference to the function. Hence, the value of Perimeter set in this function will be used throughout the program */

Subprogram Calculate_ Perimeter (Number1, Number2, Number3 As Ref) //Declare variable Set Number3= 2 * ( Number1 + Number2)
End Subprogram

// Subprogram Output_Data
// In this function we will display the output to user.

Subprogram Output_Data(Number1, Number2) Write “Area = ”, Number1 Write “Perimeter = ”, Number2
End Subprogram

Hierarchy chart

C. Program Comments and Test Data – Following the directions in the assignment, include your test data and expected results in this section. (The Comments section is for specifics about how you designed your program, any problems you had, how you solved them, lessons learned, and how you would improve the program if you had more time. This is normally used by programmers who may come back to the program later.)

Table 1. Include your test data table here. Show at least 3 examples sets of test data. Test data is normally designed before the program is written. It is used after the program is completed to test and ensure it works as it was designed to work.

| | | |
|Test Case # |Input |Expected output |
|1 |Length =4.0, Width=8.0 |Area = 32 |
| | |Perimeter = 24 |
|2 |Length = 5.0, Width= 9.0 |Area = 45 |
| | |Perimeter =28 |
|3 |Length = 7.0, Width = 3.0 |Area = 21 |
| | |Perimeter = 20 |

-----------------------
Main Module

Calculate_ Area

Output_Data

Input_ Data

Calculate _Perimeter

Flowchart : Main Program

Enter

Input_Data

Calculate_Area

Calculate_Perimeter

Output_Data

Exit

Flowchart: Subprogram Input_Data

Write “Average =”, Average

Write “Input Length:”

Input Number 1

Input_Data(Number1 As Ref,Number2 As Ref)

Exit

Write “Input width:”

Input Number 2

Flowchart :Subprogram Calculate_Area

Write “Average =”, Average

Calculate_Area(Number1,Number2,Number3 As Ref)

Set Number3= Number1 * Number2

Exit

Flowchart :Subprogram Calculate_Perimeter

Write “Average =”, Average

Write “The monthly payment for loan is $”, Num

Exit

Calculate_Perimeter(Number1,Number2,Number3 As Ref)

Set Number3= 2 * (Number1 + Number2)

Exit

Flowchart : Subprogram Output_Data

Output_Data(Number1,Number2)

Write “Area = ”, Number1

Write “Perimeter = ”, Number2

Exit

Similar Documents

Free Essay

Umuc-Cmis 102 Hw 4

...Joe Metz Professor James Huskins CMIS 102 6385 February 22nd 2015 Program Description – This program will calculate the area and perimeter of a rectangle with the provided user input. Analysis – First the user needs to provide the values for both the length and the width of the rectangle they want to determine the area and perimeter from. From there calculations need to be made. For this example we will use a rectangle with the length of 3 and a width of 9. The formula for determining the perimeter of a rectangle is P=2(l+w) where l and w stand for length and width and P is perimeter. While the formula for determining the area of a rectangle is A=lw. Where A is area and l and w are length and width. By using the values stated previously we can plug in the numbers for that formula and get 2(3+9). Simplified that's 2x12=24. To determine the area we can plug the numbers in and get A=3x9 or A=27. By writing the formulas into a function and calling that function we can have the program use any variety of input by the user to determine what the area and perimeter of a rectangle is with any values. Test Case - Test Case # | Input | Expected Output | 1 | length(l) = 3, width(w) = 9 | Perimeter (P) =24 Area (A) =27 | 2 | l = 5, w = 10 | P =30 A= 50 | 3 | l = 9, w = 36 | P=90 A= 324 | Pseudocode - //Declare Variables L, W, P, A //Float Variables P, A Write “Please Enter the Length of the Rectangle” Input...

Words: 339 - Pages: 2

Free Essay

Concrete

...AS 3600—2009 AS 3600—2009 Australian Standard® Concrete structures Accessed by NEWCREST MINING LIMITED on 14 Jul 2010 This Australian Standard® was prepared by Committee BD-002, Concrete Structures. It was approved on behalf of the Council of Standards Australia on 8 October 2009. This Standard was published on 23 December 2009. The following are represented on Committee BD-002: • • • • • • • • • • • • • • • • AUSTROADS Association of Consulting Engineers Australia Australian Building Codes Board Bureau of Steel Manufacturers of Australia Cement Concrete & Aggregates Australia—Cement Cement Concrete & Aggregates Australia—Concrete Concrete Institute of Australia Engineers Australia La Trobe University Master Builders Australia National Precast Concrete Association Australia Steel Reinforcement Institute of Australia University of Adelaide University of Melbourne University of New South Wales University of Western Sydney This Standard was issued in draft form for comment as DR 05252. Standards Australia wishes to acknowledge the participation of the expert individuals that contributed to the development of this Standard through their representation on the Committee and through the public comment period. Keeping Standards up-to-date Accessed by NEWCREST MINING LIMITED on 14 Jul 2010 Australian Standards® are living documents that reflect progress in science, technology and systems. To maintain their currency, all Standards are periodically reviewed, and...

Words: 70634 - Pages: 283

Premium Essay

Work, Culture and Identity in Mozambique and Southafrica 1860-1910

...Acknowledgments ix Acknowledgments This book owes a great deal to the mental energy of several generations of scholars. As an undergraduate at the University of Cape Town, Francis Wilson made me aware of the importance of migrant labour and Robin Hallett inspired me, and a generation of students, to study the African past. At the School of Oriental and African Studies in London I was fortunate enough to have David Birmingham as a thesis supervisor. I hope that some of his knowledge and understanding of Lusophone Africa has found its way into this book. I owe an equal debt to Shula Marks who, over the years, has provided me with criticism and inspiration. In the United States I learnt a great deal from ]eanne Penvenne, Marcia Wright and, especially, Leroy Vail. In Switzerland I benefitted from the friendship and assistance of Laurent Monier of the IUED in Geneva, Francois Iecquier of the University of Lausanne and Mariette Ouwerhand of the dépurtement évangélrlyue (the former Swiss Mission). In South Africa, Patricia Davison of the South African Museum introduced me to material culture and made me aware of the richness of difference; the late Monica Wilson taught me the fundamentals of anthropology and Andrew Spiegel and Robert Thornton struggled to keep me abreast of changes in the discipline; Sue Newton-King and Nigel Penn brought shafts of light from the eighteenthcentury to bear on early industrialism. Charles van Onselen laid a major part of the intellectual foundations on...

Words: 178350 - Pages: 714