Tuesday, May 21, 2019

Real Number Essay

1. How do modules help you to reuse code in a program?It reduces the duplication of a code deep down a program by reusing the module that was written once.2. Name and describe the two parts that a module definition has in most languages. The Header and a BodyFirst the Header indicates a starting pointSecond the Body is a list of biddings3. When a module is executing, what happens when the end of the module is reached? Its executed and returned back to the point in the main program where it was sidetracked from4. What is a local unsettled? What statements ar able to access a local variable? A variable is declared inside a local module in which it is the only statement within a module5. In most languages, where does a local variables scope begin and end? It begins at the variables declaration within a module and it ends at the end of the module in which the variable is declared.6. What is the difference between passing an argument by value and passing it by reference? By the value only a copy of the arguments value is passed and by reference it is passed into a special modifications parameter.7. Why do global variables feed a program difficult to debug? It is because the global variables is used throughout all modules and plus they are hard to track.Algorithm Workbench1. Design a module named timesTen. The module should accept an integer argument. When the module is called, it should display the product of its argument multiplied times 10. faculty Main ()Call timesTen faculty timesTen (Integer Value) withstand integerValueSet result = value*10 divulge resultEnd module5. Design a module named getNumber, which uses a reference parameter variableto accept an Integer argument. The module should prompt the exploiter to enter a number and then store the input in the reference parameter variable.Module getNumber (Integer Ref value)Display Display a numberInput numberEnd ModuleModule main () book Integer number x = 1Declare veritable number y = 3.4Display (x, ,y)Call changeUS (x, y)Display (x, ,y)End module6. What will the following pseudocode program display?Declare Integer x = 1Declare Real y = 3.4Display x, , yCall changeUs( x, y)Display x, , yEnd ModuleModule changeUs( Integer a, Real b)Set a = 0Set b = 0Display a, , bEnd ModuleIt will not display anything since thither is nothing within the quotation marks7. What will the following pseudocode program display?Module main()Declare Integer x = 1Declare Real y = 3.4Display x, , yCall changeUs( x, y)Display x, , yEnd ModuleModule changeUs( Integer Ref a, Real Ref b)Set a = 0Set b = 0.0Display a, , bEnd ModuleAs far as the module you would think that the displays would show something. But in both strings within the quotations marks both are blank to display.Programming Exercises1. Kilometer Converter Design a modular program that asks the user to enter a distance in kilometers, and then converts that distance to miles. The conversion formula is as follows Miles = Kilometers 0.621 4 Module main ()Declare Real KilometersDisplay venture a distance in kilometersInput kilometersCall conversion (kilometers)End ModuleModule conversion (Realvalue)Declare RealmilesSet miles = value*0.6214Display miles2. gross sales Tax Program Refactoring Programming Exercise 6 in Chapter 2 was the Sales Tax program. For that exercise you were asked to design a program that calculates and displays the county and state sales tax on a purchase. If you have already designed that program, refactor it so the subtasks are in modules. If you have not already designed that program, create a modular design for it. Module main ()Declare RealpurchaseDisplay Enter the amount of purchaseInput purchaseCall Module totalState (purchase)Call Module totalCounty(purchase)Declare Real totalTaxDeclare Real totalSaleSet totalTax = totalState + totalCountySet totalSale = purchase + totalTaxDisplay Your total state tax is, totalStateDisplay Your total county tax is, totalCountyDisplay Your total tax is, totalTaxDisplay Your total of your sale is, totalSaleEnd ModuleModule totalState (real Ref purchase)Set totalState sales tax = purchase*0.04End ModuleModule totalCounty (real Ref purchase)Set totalCounty sales tax = purchase*0.02End Module

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.