ModuleTest1 2018
ModuleTest1 2018
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:
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.
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.
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.