Title: Programming 1 First Exam Oct 21 2004
1Programming 1 First Exam Oct 21 2004
Juhani Välimäki
No material allowed One task per one paper
Name on every paper Return every paper
- Task 1 Look at the flowchart below. Draw two
pictures showing the contents of the memory in
that program. That is, draw the variables and
data structures and the values inside them - Right after the START (picture1)
- Just before the END (picture2)
- Also put undefined if the variable does not
have a value yet.
Do not guess or assume any values! Follow the
values of the variables step by step. This
program might do wrong things too! (Actually,
this program has errors. It works, but not like
wanted). Your task is not to correct them,
but to see which will be the values of
the variables. Definitions and the drawing and
writing style used in this flowchart are correct
and can be used as a model for your own
flowcharts.
DEFINITIONS table 5 N1 4,-5,7,-2,5 i
N1 average N3,2 sum
N2 0 temp N1
START
The first picture here
table 3 table 2
temp table 3
table 2 temp
i 1
FALSE
i lt 5
TRUE
DISPLAY The sum is sum
sum table i
average sum / 5
i i 1
DISPLAY The average is average
The second picture here
END
2Juhani Välimäki
Task 2 Design with a flowchart a simple program
that asks the user to input centimeter values.
While the value is not 0, the corresponding inch
value will be shown. Calculation formula
inches centimeters / 2.54. The program will
ask for new values until the user gives 0. Then
the program will just quit. Example test case
(just an example, do not use constant values in
your program) user inputs
displayed 254 254.00 cm is 100.00
inches. 10 10.00 cm is 3.94 inches. 111 111.00
cm is 43.70 inches. 0
ltprogram just terminatesgt
Task 3 Design with a flowchart a program that
asks the user to input names (AN16) and points
(N3) for 30 players. The names and the points
will be saved on two different arrays names and
points that you have to define by using the
information given above. Using same index youll
get the player name corresponding the points
given to the same player. Like names( 2 ) and
points( 2 ). Example test case (just an
example, do not use fixed names or points in your
program) displayed user inputs Give the name
for player 1 John Give the points
for player 1 11 Give the name for player 2
Ann Give the points for player
2 37 ... lt3-29 would be heregt ...
... Give the name for player 30 Larry Give
the points for player 30 2 When the names and
the points are saved to the arrays, the program
should then find the player with the maximum
points and display the corresponding name. (In
this game only one player can have the maximum).
Also program will calculate the average of the
points of all players. Example output
displayed Ann was the best with 37 points.
The average was 23.17 .