CSC10 – Introduction to Programming Logic Fall 2016 Homework Assignment 3 Name: Plz don't share :( Due Date: 10/5/2016 (handed in or uploaded to SacCT by start of class) 1. Fill in the blanks: You can pass in information as arguments (s) when calling a module. This information is received by parameter variable(s) within the module. 2. A variable that is restricted to the current module is a local variable. 3. A __________ is the part of a program in which a variable can be accessed. A. Declaration Space C. Area of Visibility B. Scope D. Transcendent Accessor Region of Doom 4. A variable that is visible to every module in a program is a _________ variable. A. Local C. Global B. Macro D. Universal 5. When a module ends/returns, where does the program resume execution? At the line immediately after the Call statement that invoked the module. 6. Given a module with the header PrintGreeting(String name), write a single line of pseudocode to invoke the module with your preferred name as the argument. PrintGreeting(“Cthulhu, Destroyer of Donuts”) 7. If you declare a variable within a module, can that variable be accessed in another module? Why/why not? No, local variables are restricted in scope to the current module only. 8. Why will this pseudocode not work? (Not a trick question. It really won't work.) Module getName() Declare String name Input name End Module Module Main() Call getName() Display “You entered: “ & name End Module << Name is not in Main's scope. 9. Write a module that accepts a total price and a discount. The module should display the original price, the amount saved, and the final price. Expect the discount to be a real number (e.g., 20% = 0.20) Module calc(Real price, Real discount) Declare Real amtSaved, finalPrice Set amtSaved = price * discount Set finalPrice = price - amtSaved Display “You saved “ & amtSaved & “ on your purchase of “ & finalPrice End Module 10. Write a Main module that asks the user for a total price and discount, then calls the module you wrote for Question 9 using the information given by the user. Module Main() Declare Real totalPrice, discount Input totalPrice Input discount Call calc(totalPrice, discount) End module 11. Complete the desk check. I finished the first line for you. Assume the user enters 200 at the first Input statement and 300 at the second Input statement. Remember: in real life, never use floating-point (Real) numbers for financial information! This is just an exercise. Program Line # balance amount Declare Real balance 1 ? ? Declare Real amount 2 ? ? Set balance = 2000.0 3 2000 ? Display “How much would you like to withdraw?” 4 2000 ? Input amount 5 2000 200 Set balance = balance – amount 6 1800 200 Display “How much would you like to deposit?” 7 1800 200 Input amount 8 1800 300 Set balance = balance + amount 9 2100 300
© Copyright 2026 Paperzz