60-140
Introduction to Algorithms and Programming I
Dr. Christie Ezeife
Lab. Exercises #10 (Lab Date: Week 12 of Classes)
Lab
Examination --- Nov 23-24, 2009 (sample lab exam)
There are two programming questions. Answer both questions.
Objective:
1. To test the students’
ability to write, edit, compile and run programs for solving simple problems
without using functions, but using only necessary read, print, assignment and
decision instructions.
2. To test students’
ability to write, edit, compile and run programs for solving problems with
functions, repetitions and arrays.
Instructions
a.
For
each question, hand in a script file showing your source program file,
compilation and running of the program as well as program input and output
data.
b.
Use
of email or web browser is not allowed during this lab exam.
c.
Print
formatted output as shown for full marks.
Que. 1.
Write a C program that determines the average points earned by each of two
basket ball teams (say, Teams North and South) in three games given the location
of the games and the number of points earned by each team during each
game. It is noted that when a game
is played at home, the away team gets additional bonus points of 10. Write a program that will read the
integer location (e.g., 1 for North or 2 for South) for each game, the number
of points for each team, and compute the average points earned by each team.
………………………. [50
marks]
If Sample Input data is:
Type
Game location
Team North points and Team South Points
Game
1 : 1
90
100
Type
Game location
Team North points and Team South Points
Game
2 : 2
78
69
Type
Game location
Team North points and Team South Points
Game
3 : 2 85 80
Sample Output data is:
Average
points for team North is:
91.00
Average
points for team South is:
86.33
Suggested
Marking Scheme:
Correct program structure in a
source file with correct input and output data declarations. (20
marks)
Correct program structure in a
source file with correct logic. (20
marks)
Correct logic and correct
input/output data assignments. (10
marks)
Que. 2. Write a C program that uses at least an
additional function called by main to calculate and print the product of
corresponding elements of two integer arrays with 5 elements each. For example,
if the sample input below is typed in, the output produced by the program is
the sample output below. You must
use a function, array data structure and repetition logic to solve this
problem. You should also print the input and output data with the lines to look
like the table below.
………………… [50
marks]
Sample
input data: Sample
output data:
Array1 Array2 Product_Array
15
10 150
13 9 117
80
100 8000
5 6 30
16
15 240
Suggested
Marking Scheme:
Correct program structure in a
source file with correct input and output data declarations. (10
marks)
Correct program structure in a
source file with correct function prototypes. (10
marks)
Correct program structure in a
source file with correct logic having function call(s) with correct actual
parameters. (10
marks)
Correct program structure in a
source file with correct logic having correct function definitions with correct
formal parameters. (10
marks)
Correct logic and input/output data assignments. (10 marks)
Other Alternative Work this Lab:
Que.1. Revision for final examination may start.
Que 2. Fastloan, a
financial company that grants loan to hardworking college students wants you to
develop a program, which reads a data file of applicant records and produces an
output file containing only records of approved applicants. Loan is granted
based on the policy that the total of student’s annual living expenses
excluding tuition minus the student’s yearly work income must not exceed
the student's annual tuition. The input file has records on each student
applicant specifying student id, name, rent cost, feeding cost, clothing cost,
transportation costs, tuition, and annual work income.