You are on page 1of 4

UNIVERSITY OF THE FREE STATE

DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS

CSIQ1624 & CSIS1624

DATE: 3 September 2018 MARKS: 95


ASSESSORS: Mr. M.B. Mase & Mr. D.J. Wium TIME: 180 minutes
MODERATOR: Prof. T.R. Stott

SECTION A (15)
 Answer the following questions on the answer sheet that is provided.
 The computer must be switched off while you are completing Section A.
 This is not an open-book test.

1. Consider the following integer jagged array, named A, and answer the questions that follow:

A = [ [3,7,2], [4,8], [1,5,9], [0] ]

1.1. Write down the indexes of the values 3, 8 and 0. (3)


1.2. Write a line of C# code that would declare and instantiate A, without populating
it. (2)
1.3. Write a C# code snippet that would instantiate the array [1,5,9] (name it B), and
would place it into A at the index it occupies in the example. (4)
1.4. Write a C# code snippet that will step through any integer jagged array, say C,
calculate the total number of elements in C (in other words, the total number of
elements in all the arrays in C), and then print this value to the console. (6)

NB. You must submit Section A before you may switch on the computer to do Section B.

1
SECTION B (80)
 Remember to add a comment block containing your student number, name and surname,
today's date and the name of the question at the top of every file. Marks will be deducted
for each file where the comment block is missing.
 Adhere to all programming and naming conventions as taught and ensure that your code is
aligned properly.
 This is not an open-book test.

Question 1 (30)
Create a console application using Visual Studio and name it Question1.This application
serves as a membership database for Daniël’s Chess Club. The name and age of each player
are stored. Download the ProvidedCode.txt file from Blackboard and copy its contents into
your application’s Program class.
Add the missing code by following the instructions below.

 Ensure that you have access to all namespaces that are typically required when
writing to files or reading from files. (1)
 Write the method named SaveMember. It saves the name and age of a new member
to the binary file, the filename of which is saved to the FILENAME variable. Ensure
that new members are appended to the file. (8)
 Write the method named ReadAllMembers, which reads all members’ data from the
binary file and returns it in the form of a jagged array. Employ defensive programming
to prevent run-time errors from occurring. See the screen prints below and the
implementation in Main for guidance in this regard. (17)
 Write the method named ListAllMembers, which prints a summary of all members of
the club, as in the screen print below. In the screen print, 20 characters are allowed
for the members’ names before their ages are printed. (4)
The four screen prints below illustrate the main menu, the addition of a member, the list of all
members and an error message that is displayed when a list is requested without adding any
members, respectively.

2
Question 2 (16)
Design a console application using Visual Studio that will read any sentence, count the number
of words in that sentence and then reverse the order of the words in the sentence. Name it
Question2. See the screen print below for an example of what is expected.

Construct your application according to the following guidelines:

 Write a method named CountWords that accepts a string parameter and returns the
number of words in that string. You may not call any methods to count the words.
Write your own algorithm to do so. Hint: What is the relation between the number of
words and the number of spaces in a sentence? (6)
 Next, write another method named ReverseSentence that accepts a string
parameter. The method should return a string that contains the words in that string in
reversed order. For example, “Learning programming is funny” will become “funny is
programming Learning”. You may leave uppercase letters as is and punctuation
marks may remain attached to the nearest word. Hint: You may want to use the Split
method. (7)
 Finally, add code to Main to prompt the user for a sentence and call CountWords
and ReverseSentence from Main to produce the desired output. Ensure that your
output matches the screen prints. (3)

3
Question 3 (34)
Develop a console application using Visual Studio that generates a two-dimensional integer
array with a user-specified size, prompts the user for the value of each of the elements, and
then calculates and displays the sum of each row in the array as well as the sum of all the
elements. Name it Question3. See the screen prints below for an example of what is expected.

Construct your application according to the following guidelines:


 Write a method named PopulateArray, which receives the integer array to be
populated as a parameter and then prompts the user for the elements and assigns
them to the array. See the screen print on the left. (6)
 Write a method named GetRowTotals, which receives the two-dimensional array as
a parameter and returns a one-dimensional array containing the sums of the rows of
the two-dimensional array. (8)
 Next, write a method named PrintArray, which receives the two-dimensional array
and the array containing the row totals as parameters. This method first clears the
console window and then prints headings for each column and for the “Total” column
under which the row totals will be printed. Next, it prints the elements of the two-
dimensional array to the console along with the total of each row. Finally, it prints the
sum of all elements in the two-dimensional array. Each column has a width of 7
characters and its content is right-aligned. Hint: Use the PadLeft method to achieve
this. (12)
 Finally, add the necessary code to Main to prompt the user for the size of the two-
dimensional array, instantiate that array and call the three methods that you wrote to
produce the desired output, as illustrated in the two screen prints.
(8)

Submission Procedure
1. Create a folder and rename it to your student number.
2. Move all your project folders to the folder you created in step 1.
3. Create a zip file of the folder you created in step 1 (right-click on the folder, then select send
to  Compressed (zipped) folder).
4. Submit the zip file you created in step 4 under the Assessment Archive  Module Test 1
link on Blackboard.

You might also like