Find the error in the following pseudocode.

Module main()

Call raiseToPower(2, 1.5)

End Module

Module raiseToPower(Real value, Integer power)

Declare Real result

Set result = value^power

Display result

End Module

2. Find the error in the following pseudocode.

Module main()

Call getNames()

End Module

Module getNames()

Declare Sting name

Display "What is the name of the first student?"

Input name

Declare String name

Display "What is the name of the second student?"

Input name

End Module

Find the potential error in the following pseudocode.

Module main()

Call setDouble(10.5)

End Module

Module setDouble(Int Ref num)

Set num = num*2

Display num

End Module

Find the error in the following pseudocode.

Module main()

Declare Integer month

Call getMonth()

Display "Your birthday is in month ", month, "."

End Module

Module getMonth()

Display "Enter the month of your birthday"

Input birthMonth

End Module

Respuesta :

Answer:

1. The error can be identified in the real and integer values of the parameter variables of the calling of the raiseToPower Module of the program.

2. String is misspelt as Sting

3. setDouble Module returns a fractional number instead of an integer

4. local variables declared in the Main module can not be accessed outside the main module.

Explanation:

Answer 1:

The error can be identified in the real and integer values of the parameter variables of the calling of the raiseToPower Module of the program.

The raiseToPower Module has been defined with parameters (Real value, Integer power) but when it is called

"2" is given as the real value and "1.5" as the integer power. Meanwhile a real number is a number with fractional part

and an integer is a number without fractional part. 2 is an integer while 1.5 is a real value. There the contents of the parameters when calling raiseToPower Module of the program needs to be switched.

Therefore, it becomes Call raiseToPower(1.5, 2).

Answer 2:

The error can be identified in the line 5 of the pseudocode. It is supposed to be Declare String name and not Declare Sting name.

Answer 3:

The module named setDouble uses a reference parameter variable to accept an integer argument. Integers are whole numbers and not fractional numbers.

When Calling setDouble it returns 10.5 which is a fractional number. Therefore the potential error is in Line 2 of the pseudocode which is 10.5 that is not an integer.

Answer 4:

The variable "month" has been declared as a local variable in the main module and can cannot be accessed by statements that are outside the main module. Therefore trying to gain access through the "getMonth" module the variable "month" can not be accessed.

ACCESS MORE