Вы находитесь на странице: 1из 13

Answers

Answers
Section 2: Problem-solving and Program Design
End-of-topic questions 1
1. List the main stages you should go through when trying to solve a general
problem.
2. Variables and constants are both identifiers. Explain the difference between
them.
3. What is the difference between an integer and a floating point number
End-of-topic questions 2
1. What is an algorithm
2. List four characteristics of a good algorithm.
3. What are the three main steps involved in creating an algorithm
!. What is meant by assignment
End-of-topic questions 3
1. "ame three types of control structures that are commonly used in
programming languages.
2. #tate the difference between bounded iteration and unbounded iteration.
3. $ive one example of a statement used in the following control structures%
a. #election
b. &ounded iteration
c. 'nbounded iteration
End-of-topic questions 4
1. (or each of the following problem statements%
a. identify the input) output and processing steps.
b. write the algorithm.
- Write an algorithm to read three numbers and find their product.
- Write an algorithm that displays the area of a rectangle by accepting
length and width from the user.
3. Write an algorithm that will read the radius of a circle and calculate and
display its perimeter.
End-of-topic questions 5
1. Write a narrative algorithm that will accept the radius of a circle and
calculate and display its area.
2. Write a pseudocode algorithm that will accept three numbers and calculate
and display the largest of the three.
3. Write a pseudocode algorithm that will accept the mar*s in a test for a group
of 2+ students then calculate and display the average mar*.
!. ,dd steps to the previous algorithm so it also displays the highest mar*.
!ec" #our progress 1
1. -raw flowcharts for the following programs%
a. .rogram to accept the price of an item and calculate its V,/ at 1+0.
b. .rogram to accept money in '# dollars and convert it to its e1uivalent
local currency.
c. .rogram to accept the length and width of a rectangle and calculate its
area.
End-of-topic questions $
1. -raw flowcharts for the following%
a. , program that accepts 22 numbers and finds their product.
b. , program that accepts !+ numbers and finds the number of 3eroes and
non43eroes in them.
c. , program that accepts a set of integers and finds the number of positive
and negative numbers. /he program stops when the user enters 2 for the
integer value.
d. , program that accepts a set of numbers and finds the smallest among
them. /he program stops when the user enters 555 as the number.
!ec" #our progress 2
1. 6reate a trace table to determine the output of the following algorithm%
#tep 1% set x +
#tep 2% set y 12
#tep 3% set 3 3
#tep !% set x x7y
#tep +% set y x 73
#tep 8% set 3 x7y73
#tep 9% display x) y)3
!ec" #our progress 3
6reate a trace table to determine the output of the following algorithm%
#tep 1% set a 12
#tep 2% set b 12
#tep 3% set c 23
#tep !% set a a7b7c
#tep +% set b a4b
#tep 8% set c b4c
#tep 9% if a:b then
set m a
set n b
set p c
else
set m c
set n a
set p b
endif
#tep ;% display m)n)p
!ec" #our progress 4
1. 6reate a trace table to determine the output of the following algorithm%
#tep 1% set a 9
#tep 2% set x 1
#tep 3% While a<:2
set x x 7 a
set a a 1
#tep !% endwhile
#tep +% write x
End-of-topic questions %
1. 6reate a trace table to determine the output of the following algorithms%
#tep 1% x +
#tep 2% for i 1 to 12
set x = x 7 +
endfor
#tep 3% write x
!ec" #our progress 5
1. What is meant by stepwise refinement or top4down design
2. List three advantages of using top4down design to solve a problem.
End-of-topic questions &
1. Explain why a top4down design approach is sometimes used to solve
problems.
2.
2. , hotel wants to have a room boo*ing system. When a guest arrives the
receptionist would be able to see which rooms are free and allocate one to the
guest. When the guest leaves) the room would be mar*ed as free again. Each
day the cleaners would be given a list of the rooms that are in use. ,t any time
the receptionist would be able to use the room number to find the name and
home address of a guest) or could search the room system for a named
guest. -raw a top4down design diagram to show how the room boo*ing
system could be developed.
End-of-section questions
'ultiple-c!oice questions
1. /he following are problem4solving stages
>. analyse the problem
>>. suggest possible solutions
>>>. implement and review
>V. define the problem
V. select the best solution
/he correct order of stages is%
, >) >V) >>) >>>) V
& >V) >) >>) V) >>>
6 >V) >>) >) V) >>>
- >) >>) >V) >>>) V
2. Which one of the following is a variable
, x
& ?x@
6 +
- ?+@
3. /o store fractional values) use the data type%
, integer
& floating point
6 character
- string
A. B
!. Which of the following is not a characteristic of a good algorithm
, precise
& finite number of steps
6 ambiguous
- logical flow of control
+. -iagrammatic representation of an algorithm is%
, flowchart
& data flow diagram
6 algorithm design
8. Which of the following isAare control structures
, selection
& se1uencing
6 repetition
- all of the above
9. ,n example of a bounded iteration statement used in algorithm is%
, whileBendwhile
& whileBwend
6 forBendfor
- repeatBuntil
;. Which one of the following is a selection construct used in algorithms
, while Bendwhile
& if B then 4 else
6 for Bendfor
- repeat4until
5. Which one of the following involves a logical operation
, x:y
& x:=y
6 x:y and x=y
- x< :y
12. 6onsider the following algorithm segment%
x = x7y
y = x y
write y) x
#uppose x = 12 and y = 1+) after the completion of the above statements) the
values of x and y will be%
, 2+ and 12
& 12 and 2+
6 12 and 4+
- 4+ and 12
Structured questions
1 a. List the main stages of problem4solving process for computer4based
problem4solving.
b. (or each of the stages identified in 1a above) briefly describe the activities
that are involved in it.
2. >.C diagrams can be used to brea* down a problem into its components.
a. #tate what is meant by ?>.C diagrams@
b. 6reate an >.C chart for the following problem statement% ?,ccept the
values of length and width of a rectangle and calculate its area@
3. a. #tate the difference between%
i. constants and variables
ii. integer data type and floating point data type
iii. character data type and string data type
b. -efine the following terms%
i. identifier
ii. literal
. ?6onstants are fixed values while variables identify a memory location
that is capable of storing values that can be changed.@
ii.
.
!. 6reate a narrative algorithm that will prompt the user to enter two numbers
and find their difference.
+. Write a pseudocode that prompts the user to enter a value and display its
s1uare and cube values.
8. -raw a flowchart and write a pseudocode that will prompt the user to enter
two numbers and display their product.
9. Dou need to calculate the area of rectangle using its length and width.
-raw a flowchart and write a pseudocode that will accept the length and
width and calculate and print the area of the rectangle. Earea = length F
widthG
;. Write a pseudocode that will accept 2+ integers and displays the number
of positive and negative numbers.
5. a. -raw a trace table for the following algorithm%
b. What is printed by the algorithm
x = 12
y = 22
3 = +
x = x7y
y = x4y
3 = 37x
x =y
y =3
3=x
print x) y) 3
12. a. -raw a trace table for the following algorithm.
b. What is the output of this algorithm
x = 12
y = 1+
3 = 22
x= x7y
y = x73
3 = x7y73
if x :y then
x = x 7+
else
x = x B 3
endif
if y <3 then
y = y712
else
y = y B 12
endif
print x) y) 3

Вам также может понравиться