Exam 1 excercies

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Assume that a pseudocode program contains the following module: Module display(Integer arg1, Real arg2, String arg3) Display "Here are the values:" Display arg1, " ", arg2, " ", arg3 End Module Assume that the same program has a main module with the following variable declarations: Declare Integer age Declare Real income Declare String name Write a statement that calls the display module and passes these variables to it

Call display(age, income, name)

Examine the following pseudocode module header, and then write a statement that calls the module, passing 12 as an argument. Module showValue(Integer quantity)

Call showValue(12)

Design a module named getNumber, which uses a reference parameter variable to accept an Integer argument. The module should prompt the user to enter a number and then store the input in the reference parameter variable.

Module getNumber(Integer &number) Display "Enter a number." Input number End Module

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.

Module timesTen(Integer number) Declare Integer result result = number * 10 Display result End Module

Write a pseudocode statement that assigns the value 27 to the variable count.

Set count = 27

Write a pseudocode statement that subtracts the variable downPayment from the variable total and assigns the result to the variable due.

Set due = downPayment - total

Write a pseudocode statement that assigns the sum of 10 and 14 to the variable total

Set total = 10 + 14

Write a pseudocode statement that multiplies the variable subtotal by 0.15 and assigns the result to the variable totalFee.

Set totalFee = subtotal * 0.15

Assume the variables result, x, y, and z are all integers, and that x = 4, y = 8, and z = 2. What value will be stored in result in each of the following statements? a. Set result = x + y b. Set result = z * 2 c. Set result = y / x d. Set result = y - z

a) 12 b) 4 c) 2 d) 6

Write assignment statements that perform the following operations with the variables a and b. a. Adds 2 to a and stores the result in b b. Multiplies b times 4 and stores the result in a c. Divides a by 3.14 and stores the result in b d. Subtracts 8 from b and stores the result in a

a) Set b = a + 2 b) Set a = b * 4 c) Set b = a / 3.14 d) Set a = b - 8

Appendix D shows how to convert a decimal number to binary. Use the technique shown in Appendix D to convert the following decimal numbers to binary: 11 65 100 255

1011 1000001 1100100 1111111

If the following pseudocode were an actual program, what would it display? Declare Integer a = 5 Declare Integer b = 2 Declare Integer c = 3 Declare Integer result Set result = a + b * c Display result

11

Use what you've learned about the binary numbering system in this chapter to convert the following binary numbers to decimal: 1101 1000 101011

13 8 43

What will the following pseudocode program display? Module main() Declare Integer x = 1 Declare Real y = 3.4 Display x, " ", y Call changeUs(x, y) Display x, " ", y End Module Module changeUs(Integer Ref a, Real Ref b) Set a =0 Set b = 0.0 Display a, " ", b End Module

13.4 00 00

What will the following pseudocode program display? Module main() Declare Integer x = 1 Declare Real y = 3.4 Display x, " ", y Call changeUs(x, y) Display x, " ", y End Module Module changeUs(Integer a, Real b) Set a =0 Set b = 0 Display a, " ", b End Module

13.4 00 13.4

Look at the following pseudocode module header: Module myModule(Integer a, Integer b, Integer c) Now look at the following call to myModule: Call myModule(3, 2, 1) When this call executes, what value will be stored in a? What value will be stored in b? What value will be stored in c?

3 will be stored in a, 2 will be stored in b, and 1 will be stored in c.

If the following pseudocode were an actual program, what would it display? Declare Integer num = 99 Set num = 5 Display num

5

Look at the ASCII chart in Appendix A and determine the codes for each letter of your first name

68 101 114 101 107

Write a pseudocode statement that declares the variable cost so it can hold real numbers.

Declare Real cost

Design an algorithm that prompts the user to enter his or her favorite color and stores the user's input in a variable named color.

Display "Enter your favorite color." Input color

Design an algorithm that prompts the user to enter his or her height and stores the user's input in a variable named height.

Display "Enter your height." Input height

Write a pseudocode statement that declares the variable total so it can hold inte- gers. Initialize the variable with the value 0.

Declare Integer total = 0


Set pelajaran terkait

Individual Chapter Review Questions Ch. 6

View Set

Abnormal Psych. 341 Ch.10: Somatic Symptom & Related Disorders

View Set

Java Concepts Chapter 13: Inheritance

View Set