Free Essay

Write a Program, Using Functions, That Calculates the Area and Perimeter of a Rectangle Whose Dimensions (Length and Width) Are Provided by a User

In:

Submitted By loilam2007
Words 676
Pages 3
Problem Statement: It is clearly that the rectangular has either the length is longer than the width, or the width is longer than the length. It depends on the rectangular is in horizontal or vertical position. In this assignment the rectangular is in the horizontal position that means the length is longer than the width. This rectangular has length 4m for each side and width 3m for each side. Now, the program will be written by using functions that calculates the area and perimeter of a rectangular.

Analysis: For the space problem, we need to output the area of the following variables: + Name of the area is calculated, GetArea (as string) + The length of rectangular, LenRec (as float) + The width of rectangular, WidRec (as float) + The total length of rectangle, Total2L (as float) + The total width of rectangle, Total2W (as float) + The perimeter of rectangle. PerRec (as string) The necessary input to the program: + In order to output the rectangle’s area (GetArea), the program must know what it is, so the string Area must be input by the user. + To compute the usable area of rectangular, the program must know how many sides in the rectangle. We have LenRec and WidRec are float variable and are also input data. + To compute the rectangle’s perimeter (PerRec), the program must know what it is, so the string perimeter must be input by the user.

Obtaining the Necessary Formulas: The rectangular has length 25m and width 18m. So we have GetArea = 4m x 3m = 12m Generalize these computations by using variables instead of numbers: therefor, the suggestion formula for calculating the area and perimeter of rectangular is: GetArea = LenRec x WidRec GetArea is neither an input nor output variable, but it used solely in processing the data. This variable is type of float. Thus the rectangular has perimeter: PerRec = 2(4m) + 2(3m) = 14m Then, PerRec = 2 (LenRec) + 2 (WidRec)
Design:
Mail module Declare GetArea As String Declare LenRec As Float Declare WidRec As Float Declare PerRec As Float Set LenRec = 0 Set WidRec = 0 Set GetArea = 0 Set PerRec = 0 Write “Enter the length of rectangle” Input the measurement of length Write “Enter the width of rectangle” Input the measurement of width While LenRec > WidRec Write “Enter the area of rectangle: Input Number For [GetArea = 1; LenRec > WidRec; LenRec++] Set GetArea = 0 Write “Enter length of rectangle” + WidRec Input Number Set PerRec = 2 (LenRec) * 2 (WidRec) End for Set GetArea = [LenRec, WidRec] Write “LenRec: “+ WidRec Set GetArea = LenRec + WidRec End while Set PerRec = [2LenRec, 2WidRec] Write “The perimeter of rectangle” * 2LenRec + 2WidRec + “is” + Write PerRec End program Function GetArea [LenRec, WidRec] As Float Set GetArea = LenRec + WidRec Return value
End function
Function PerRec [2LenRec, 2WidRec] As Float Set PerRec = 2LenRec + 2WidRec Return value
End Function

Hierarchy Chart for the Program:
Main
Module
Main
Module

Area/Perimeter of Rectangle
Area/Perimeter of Rectangle
Get are of rectangle
Get are of rectangle
Calculate perimeter of rectangle
Calculate perimeter of rectangle
Create function
Create function

Flow Chart of the Program
Enter
Enter

Declare LenRec, WidRec, as integer
Declare LenRec, WidRec, as integer

Write “Enter the length of rectangle: “ Input measurement of length

Write “Enter the length of rectangle: “ Input measurement of length

Clear Screen
Clear Screen

Set PerRec = 0
Set PerRec = 0

Input Number
Input Number

Write “Enter the perimeter of rectangle”
Write “Enter the perimeter of rectangle”

Set PerRec
Set PerRec

No Yes

Write “Return value”
Write “Return value”
Write “Function”
Write “Function”

End Program
End Program

// Calculating the area and perimeter of rectangle // Programmers” H. Bao, University of Maryland University College // This program Calculates area and perimeter of rectangle, including // Lengths and Widths // positive numbers used: // LenRec calculated // WidRec calculated
… and so on

Testing: Input the measurement of length and width (positive numbers are used). | Expected output: The total of both side length, width, and the area of rectangle. | GetArea = LenRec x WidRec Then: GetArea = 4m x 3m PerRec = 2 (LenRec) + 2 (WidRec) Then: PerRec = 2 (4m) + 2 (3m) | 12m14m | Rectangle’s area = 12m | Rectangle’s Perimeter = 14m |

Similar Documents

Free Essay

Cmis 102 Hw 4

...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) ...

Words: 1160 - Pages: 5

Free Essay

Cmis 102

...Pseudocode for the program // Declaring variables Declare Integer InternetHits[10] Declare Integer i // Loop for inputting values For i = 0 to 9 Print 'Enter the value-'    Print i+1 Input InternetHits[i] End For // End of Program. 1. #include <stdio.h> 2. int main () { 3. int internetHits[10]; 4. int hits; 5. int counter; 6. for(counter=0;counter<10;counter++){ 7. printf("Enter number of hits: "); 8. scanf("%d",&internetHits[counter]); 9. } 10. //Display Values 11. printf("Entered values are: \n"); 12. for (counter = 0;counter<10;counter++){ 13. printf("%d\n",internetHits[counter]); 14. } 15. return 0; 16. } ************************************************************************* Question Design and write a program, using functions, that calculates the area and perimeter of a rectangle whose dimensions (length and width) are provided by a user. There are 4 components of your submission including: Program Description- A detailed, clear description of the program you are building. Analysis- Demonstrates your thought process and steps used to analyze the problem. Be sure to include the required...

Words: 790 - Pages: 4

Premium Essay

Write a Program, Using Functions, That Calculates the Area and Permieter of a Rectangle Whose Dimensions (Length and Width) Are Provided by a User

...this homework, you will design a program to perform the following task:Write a program, using functions, that calculates the area and perimeter of a rectangle whose dimensions (Length and width) are provided by a user. Assume the rooms are rectangular and that the user can enter from 1 to 10 rooms for the house. Also calculate and display the total area and total perimeter (i.e. the sum of the perimeters) of the house. Note: this is very similar to Assignment 1 and you can reuse any code there that is appropriate. Before attempting this exercise, be sure you have completed all of chapter 8 and course module readings, participated in the weekly conferences, and thoroughly understand the examples throughout the chapter.   There are 4 main components of your submission including the problem analysis, program design and documentation, and sample test data.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.Your analysis should be clearly written and demonstrate your thought process and steps used to analyze the problem. Be sure to include what is the required output? What is the necessary input and how you will obtain the required output from the given input? Also, include your variable names and definitions. Be sure to describe any necessary formulas and sample calculations.2. Provide your program design for the problem you analyzed...

Words: 471 - Pages: 2

Premium Essay

Analysis

...SEVENTH EDITION PROBLEM SOLVING AND PROGRAM DESIGN in C This page intentionally left blank SEVENTH EDITION PROBLEM SOLVING AND PROGRAM DESIGN in C Jeri R. Hanly, University of Wyoming Elliot B. Koffman, Temple University Boston Columbus Indianapolis New York San Francisco Upper Saddle River Amsterdam Cape Town Dubai London Madrid Milan Munich Paris Montreal Toronto Delhi Mexico City Sao Paulo Sydney Hong Kong Seoul Singapore Taipei Tokyo Editorial Director, ECS: Marcia Horton Editor-in-Chief: Michael Hirsch Senior Project Manager: Carole Snyder Director of Marketing: Patrice Jones Marketing Manager: Yezan Alayan Senior Marketing Coordinator: Kathryn Ferranti Director of Production: Vince O’Brien Managing Editor: Jeff Holcomb Associate Managing Editor: Robert Engelhardt Production Manager: Pat Brown Creative Director: Jayne Conte Designer: Suzanne Behnke Media Editor: Daniel Sandin Media Project Manager: John Cassar Cover Image: (c) michael Holcomb/Shutterstock.com Full-Service Project Management: Mohinder Singh/ Aptara®, Inc. Composition: Aptara®, Inc. Printer/Binder: Edwards Brothers Cover Printer: Lehigh-Phoenix Credits and acknowledgments borrowed from other sources and reproduced, with permission, in this textbook appear on appropriate page within text. Photo Credits: Page 4: Fig. 0.1: akg-images/Paul Almasy/Newscom. Page 11: Fig. 0.4: © 2008 IEEE/Journal of Microelectromechanical Systems (2006). Page 15:...

Words: 158087 - Pages: 633

Free Essay

Computer Vision

...Learning OpenCV Gary Bradski and Adrian Kaehler Beijing · Cambridge · Farnham · Köln · Sebastopol · Taipei · Tokyo Learning OpenCV by Gary Bradski and Adrian Kaehler Copyright © 2008 Gary Bradski and Adrian Kaehler. All rights reserved. Printed in the United States of America. Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472. O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (safari.oreilly.com). For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com. Editor: Mike Loukides Production Editor: Rachel Monaghan Production Services: Newgen Publishing and Data Services Cover Designer: Karen Montgomery Interior Designer: David Futato Illustrator: Robert Romano Printing History: September 2008: First Edition. Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of O’Reilly Media, Inc. Learning OpenCV, the image of a giant peacock moth, and related trade dress are trademarks of O’Reilly Media, Inc. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a trademark claim, the designations have been printed in caps or initial caps. While every precaution has been taken in the preparation of this...

Words: 150684 - Pages: 603

Premium Essay

Ggfyutiop Huu

...Nitro Pro 9 User Guide Nitro Pro 9 - User Guide In this User Guide Welcome to Nitro Pro 9 How to use this guide Quickly find the right information To Search For Keywords: Participate and Contribute Online Getting started with Nitro Pro 9 Explore the Nitro Pro 9 user interface A Tour of Nitro Pro 9 1 File Menu 2 Quick Access Toolbar 3 Ribbon Tabs 4 Information Bar 5 Document Pane 6 Zoom Controls and Page View 7 Paging Controls 8 Find Bar 9 Lower Navigation Panes 10 Sidebar Navigation Panes Ribbon shortcuts To view and use shortcut keys: Software Activation Common terms To purchase a Nitro Pro 9 license: To activate Nitro Pro 9: Automatic, or online, activation: Manual, or offline, activation: Compatibility with other applications Tasks and tools View and navigate a PDF file Open a PDF file Open a PDF file The File Menu Drag-and-drop Double-click or right-click Change the page view To change the page display options: To resize the page view: To rotate the page view: Adjust the zoom level To use the Zoom tool: To adjust the zoom level with Page Controls: Page through the document Step through the pages To scroll smoothly between pages: Navigation Panes The Pages Pane 1 1 1 1 1 2 3 3 3 3 4 4 4 4 4 4 4 4 6 6 7 7 7 7 7 7 9 10 11 12 12 12 12 12 13 13 13 14 15 15 15 16 16 16 17 17 i ©Nitro Nitro Pro 9 - User Guide The Bookmarks Pane The Signatures Pane The Layers Pane The Layers Pane To view the Layers pane: To show or hide an OCG layer: To reset a layer to its default...

Words: 39212 - Pages: 157

Premium Essay

Cd Key

...Java Quick Reference Console Input Scanner input = new Scanner(System.in); int intValue = input.nextInt(); long longValue = input.nextLong(); double doubleValue = input.nextDouble(); float floatValue = input.nextFloat(); String string = input.next(); Console Output System.out.println(anyValue); JOptionPane.showMessageDialog(null, "Enter input"); GUI Input Dialog String string = JOptionPane.showInputDialog( "Enter input"); int intValue = Integer.parseInt(string); double doubleValue = Double.parseDouble(string); Message Dialog Primitive Data Types byte short int long float double char boolean 8 bits 16 bits 32 bits 64 bits 32 bits 64 bits 16 bits true/false Arithmetic Operators + * / % ++var --var var++ var-addition subtraction multiplication division remainder preincrement predecrement postincrement postdecrement Assignment Operators = += -= *= /= %= assignment addition assignment subtraction assignment multiplication assignment division assignment remainder assignment Relational Operators < >= == != less than less than or equal to greater than greater than or equal to equal to not equal Logical Operators && || ! ^ short circuit AND short circuit OR NOT exclusive OR if Statements if (condition) { statements; } if (condition) { statements; } else { statements; } if (condition1) { statements; } else if (condition2) { statements; } else { statements; } switch Statements switch (intExpression) { case value1: statements; break; ... case valuen: statements; break;...

Words: 73366 - Pages: 294

Premium Essay

Databasse Management

..............................................................12 Contents of This Edition.....................................................................................................................13 Guidelines for Using This Book.........................................................................................................14 Acknowledgments ..............................................................................................................................15 Contents of This Edition.........................................................................................................................17 Guidelines for Using This Book.............................................................................................................19 Acknowledgments ..................................................................................................................................21 About the Authors ..................................................................................................................................22 Part 1: Basic Concepts............................................................................................................................23 Chapter 1: Databases and Database Users..........................................................................................23 1.1 Introduction ....................................................................................................................

Words: 229471 - Pages: 918

Free Essay

Fundamentals of Heat and Mass Transfer 7th Edition

...understanding for more than 200 years, helping people around the world meet their needs and fulfill their aspirations. Our company is built on a foundation of principles that include responsibility to the communities we serve and where we live and work. In 2008, we launched a Corporate Citizenship Initiative, a global effort to address the environmental, social, economic, and ethical challenges we face in our business. Among the issues we are addressing are carbon impact, paper specifications and procurement, ethical conduct within our business and among our vendors, and community and charitable support. For more information, please visit our website: www.wiley.com/go/citizenship. The paper in this book was manufactured by a mill whose forest management programs include sustained yield harvesting of its timberlands. Sustained...

Words: 55208 - Pages: 221

Premium Essay

Hiiiiiiiiiiiiii

...POWER 1024 1021 1018 1015 1012 109 106 103 102 101 100 1021 1022 1023 1026 1029 10212 10215 10218 10221 10224 THE GREEK ALPHABET PREFIX yotta zetta exa peta tera giga mega kilo hecto deca — deci centi milli micro nano pico femto atto zepto yocto SYMBOL Y Z E P T G M k h da — d c m μ n p f a z y Alpha Beta Gamma Delta Epsilon Zeta Eta Theta Iota Kappa Lambda Mu Nu Xi Omicron Pi Rho Sigma Tau Upsilon Phi Chi Psi Omega UPPERCASE A B G D E Z H U I K L M N J O P R S T Y F X C V LOWERCASE a b g d P z h u i k l m n j o p r s t y f x c v Conversion Factors (more conversion factors in Appendix C) Length 1 in 5 2.54...

Words: 201181 - Pages: 805

Free Essay

Gmat

...distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher. 0-07-151120-2 The material in this eBook also appears in the print version of this title: 0-07-149340-9. All trademarks are trademarks of their respective owners. Rather than put a trademark symbol after every occurrence of a trademarked name, we use names in an editorial fashion only, and to the benefit of the trademark owner, with no intention of infringement of the trademark. Where such designations appear in this book, they have been printed with initial caps. McGraw-Hill eBooks are available at special quantity discounts to use as premiums and sales promotions, or for use in corporate training programs. For more information, please contact George Hoare, Special Sales, at george_hoare@mcgraw-hill.com or (212) 904-4069. TERMS OF USE This is a copyrighted work and The McGraw-Hill Companies, Inc. (“McGraw-Hill”) and its licensors reserve all rights in and to the work. Use of this work is subject to these terms. Except as permitted under the Copyright Act of 1976 and the right to store and retrieve one copy of the work, you may not decompile, disassemble, reverse engineer, reproduce, modify, create derivative works based upon, transmit, distribute, disseminate, sell, publish or sublicense the work or any part of it without McGraw-Hill’s...

Words: 234594 - Pages: 939

Premium Essay

Exel 2010 Formulas

...Excel 2010 Microsoft ® ® ® Formulas John Walkenbach BONUS CD-ROM! Includes all Excel workbook files used in the book, plus the complete book in a searchable PDF file Excel® 2010 Formulas by John Walkenbach Excel® 2010 Formulas Published by Wiley Publishing, Inc. 111 River Street Hoboken, NJ 07030-5774 www.wiley.com Copyright © 2010 by Wiley Publishing, Inc., Indianapolis, Indiana Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 7486011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, Making Everything Easier, and related trade dress are trademarks...

Words: 49651 - Pages: 199

Free Essay

Management

...Manual for the GMAT*Exam version 8.0 All rights reserved. No part of this manual may be reproduced for distribution to a third party in any form or by any means, electronic or mechanical, including photocopying, recording, or any information retrieval system, without the prior consent of the publisher, The Princeton Review. This Manual is for the exclusive use of Princeton Review course students and is not legal for resale. GMAT is a registered trademark of the Graduate Management Admission Council. The Princeton Review is not affiliated with Princeton University or the Graduate Management Admission Council. Permission to reprint this material does not constitute review or endorsement by the Educational Testing Service or the Graduate Management Admission Council of this publication as a whole or of any other sample questions or testing information it may contain. Copyright © 2003 by Princeton Review Management, L.L.C. All Rights Reserved. 800.2Review/ www.princetonreview.com ACKNOWLEDGMENTS Thanks to the following for their many contributions to this course manual: Tariq Ahmed, Kristen Azzara, Shon Bayer, John Bergdahl, Marie Dente, Russ Dombrow, Tricia Dublin, Dan Edmonds, Julian Fleisher, Paul Foglino, Alex Freer, John Fulmer, Joel Haber, Effie Hadjiioannou, Sarah Kruchko, Mary Juliano, Jeff Leistner, Sue Lim, Michael Lopez, Stephanie Martin, Chas Mastin, Elizabeth Miller, Colin Mysliwiec, Magda Pecsenye, Dave Ragsdale, “GMAT” Jack Schieffer...

Words: 53639 - Pages: 215

Free Essay

Physics

...particular teaching its Physics 141/142, 151/152, or 161/162 series (Introductory Physics for life science majors, engineers, or potential physics majors, respectively). It is freely available in its entirety in a downloadable PDF form or to be read online at: http://www.phy.duke.edu/∼rgb/Class/intro physics 1.php It is also available in an inexpensive (really!) print version via Lulu press here: http://www.lulu.com/shop/product-21186588.html where readers/users can voluntarily help support or reward the author by purchasing either this paper copy or one of the even more inexpensive electronic copies. By making the book available in these various media at a cost ranging from free to cheap, I enable the text can be used by students all over the world where each student can pay (or not) according to their means. Nevertheless, I am hoping that students who truly find this work useful will purchase a copy through Lulu or a bookseller (when the latter option becomes available), if only to help subsidize me while I continue to write inexpensive textbooks in physics or other subjects. This textbook is organized for ease of presentation and ease of learning. In particular, they are hierarchically organized in a way that directly supports efficient learning. They are also remarkably complete in their presentation and contain moderately detailed derivations of many of the important equations and relations from first principles while not skimping on simpler heuristic or conceptual explanations...

Words: 224073 - Pages: 897

Free Essay

Business

...Starting an Online Business FOR DUMmIES ‰ 4TH EDITION by Greg Holden TEAM LinG - Live, Informative, Non-cost and Genuine ! Starting an Online Business For Dummies®, 4th Edition Published by Wiley Publishing, Inc. 111 River Street Hoboken, NJ 07030-5774 www.wiley.com Copyright © 2005 by Wiley Publishing, Inc., Indianapolis, Indiana Published by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Legal Department, Wiley Publishing, Inc., 10475 Crosspoint Blvd., Indianapolis, IN 46256, (317) 572-3447, fax (317) 572-4355, e-mail: brandreview@wiley.com. Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates...

Words: 155013 - Pages: 621