You are on page 1of 2

CS111: Introduction to Computing Science

Lab 11 – Week 13

Objective of this lab exercise


1. Using functions
2. Using arrays
3. Using simple array
4. Using 2-D arrays

Before you begin:


  Review last week’s lab. 
 Also review last week’s lectures on arrays. 

Exercise 1 [1 mark]

The purpose of the remainder of this lab is to write a program that prints the following
table with the number of busses that pass USP.
Mon Tue Wed Thu Fri Sat Sun
Nasese 34 33 31 35 36 23 20
Raiwai 27 28 26 29 30 18 17
Raiwaqa 37 35 33 35 38 35 34
Vatuwaqa 22 24 23 25 27 26 26

In addition to just printing the table it should compute for each row the total, and
the total for the entire table.
As a first step you are asked to provide the following variable declarations (for the
main function):
• An array of length 4, containing the strings “Nasese”, “Raiwai”, “Raiwaqa”,
“Vatuwaqa”.
• A 2-D array with 4 rows and 7 columns, containing the number in the table above.
Exercise 2 [1 mark]
Write a function that prints the table. The output should look like this:

*******************************
USP bus count
*******************************

Mon Tue Wed Thu Fri Sat Sun


Nasese 34 33 31 35 36 23 20
Raiwai 27 28 26 29 30 18 17
Raiwaqa 37 35 33 35 38 35 34
Vatuwaqa 22 24 23 25 27 26 26

Press any key to continue . . .

It should use the arrays that you defined in exercise 1.

Exercise 3 [1 mark]
Provide the following two functions
• One function that given a (one dimensional) integer array and its size,
computes and returns the sum of all elements.
• A second function that given a 2-D array and the number of rows and
columns, computes and returns the sum of all elements.

Exercise 4 [1 mark]
Write a program that add the computation of totals to the table. The output should
look like this:
*******************************
USP bus count
*******************************

Mon Tue Wed Thu Fri Sat Sun Total


Nasese 34 33 31 35 36 23 20 212
Raiwai 27 28 26 29 30 18 17 175
Raiwaqa 37 35 33 35 38 35 34 247
Vatuwaqa 22 24 23 25 27 26 26 173

The weekly total for all routes is: 807

Press any key to continue . . .

It should use the functions that you defined in exercise 3 to compute the totals.

You might also like