AdditionalExamination 2017
AdditionalExamination 2017
BLOEMFONTEIN/QWAQWA CAMPUS
CSIS/CSIQ1624
DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS
DEPARTEMENT REKENAARWETENSKAP EN INFORMATIKA
CONTACT NUMBER/KONTAKNOMMER: 072 967 7092
PAPER/VRAESTEL 1
Instructions:
Answer the following questions by developing the solutions in C#.
Make sure that you enter your name, student number and question number for every
class in a comment block at the top of the code window. You will not get marks if you
do it, but you will lose 2 marks for every question if you don’t do it.
Make sure that you give appropriate names to all controls and variables.
Create the following folder on the T-drive in the format Studentnumber_Surname, e.g.
2001123456_Gert
1
SECTION A (19)
Instructions
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 section (Section A).
2. Consider the following two-dimensional integer array, named A, and answer the
questions that follow:
1 2 3 4
5 6 7 8
𝐴= [ ]
9 9 7 1
6 1 3 0
2.2 Write code that declares A and instantiates it with the provided values. (3)
2.3 Write a C# code snippet that would print the values of A to a console window in
the same formation as above (without the square brackets), with spaces between
values on the same line. (5)
[19]
NB. You must submit Section A before you may switch on the computer to do
Section B.
2
SECTION B (117)
Instructions
This is an open-book section (Section B). You may use the text book “Be Sharp with C#”
but no other sources, written or electronic, will be allowed.
1. Develop a Windows Forms application and name your project Question 1. This
application should allow the user to enter a sentence in the textbox and then display
the extracted vowel/s as well as the number of vowels in a message box. Note that the
vowels are “a”, “A”, “e”, “E”, “i”, “I”, “o”, “O”, “u”, “U”, “y”, “Y”.
(13)
2. Develop a console application and name your project Question 2. This application
should do a compile-time initialisation and put the following integers in ascending
order in a one-dimensional array, Numbers: 2, 17, 11, 20, 12, 3, 6, 9, 4, 7. Create and
call two methods. The first method should take the array, Numbers, as parameter and
return the square of the numbers as another array. The second method should return
void and take both the original numbers and their squares as parameters and display
them as in the screen print below.
(21)
3. Develop a Windows Forms application and name your project Question 3. The
application should assist a stock manager to keep track of his stock. There are two
types of stock: Capital and Consumables. All stock items have a stock code and
3
description. Capital items also have an asset number while the quantity of
consumables on hand should be saved.
Allow the user to enter several stock items one after the other in any order. When the
user clicks on New, all data fields should be cleared to prepare input for a new item.
For capital items the asset number field must be visible and for consumables the
quantity on hand property must be available. A list of items in stock should be available
at any time. A possible interface is shown below.
3.1 Develop the class CStock. It must not be possible to instantiate objects of CStock.
Declare auto-implemented properties for the stock code and description. Besides
the basic constructor, make also provision for a constructor that will have
parameters with which the stock code and description can be initialised. (11)
3.2 Develop the class CConsumable that must inherit from CStock. Declare an auto-
implemented property for the quantity on hand. The basic constructor must assign
a 0 to this property and a second constructor must use a parameter to initialise the
property. (8)
3.3 Develop the class for CCapitalItem that must inherit from CStock. Declare an
auto-implemented property for the asset number. The basic constructor must
assign an empty string to this property and a second constructor must use
parameters to initialise all properties in the sub-class and base class. (6)
3.4 Develop the form as in the example above. Note that there is another button
Accept underneath New. Only one of these two buttons, New and Accept, is
visible at a time. (2)
3.5 Write the code for the click event handler of the Close button. (1)
3.6 Write code for the CheckedChanged event handler of one of the two radio buttons
that will set visibility of the labels and text boxes for asset number and quantity
on hand as necessary. Note that the same event handler should be executed when
either one of the radio buttons is checked. (5)
3.7 Declare a list, lstStock, on form level and instantiate the list in the form’s Load
event handler. This list will be used to store individual instances of either
CConsumable or CCapitalItem. (2)
4
3.8 Write a method, ClearControls(), to clear all text boxes and put the focus in the
text box for stock code. (2)
3.9 Write the code for the click event handler of the New button. Clear the controls, set
the visibility of the New and Accept buttons to false and true respectively and
disable the buttons for List and Remove All. (3)
3.10 Write the code for the click event handler of the Accept button.
(i) Declare a local object, Item, of type CStock. (1)
(ii) Depending on which radio button is checked, instantiate Item to be either a
CCapitalItem or CConsumable. If it is a CCapitalItem, use the constructor
to assign values for the stock code, description and asset number. If it is a
CConsumable, use the basic constructor and then assign values to the stock
code, description and quantity on hand afterward. (8)
(iii) Add the item to the list of stock items. (2)
(iv) Set the visibility of the New and Accept buttons to true and false respectively.
(1)
(v) Enable the buttons for List and Remove All. (1)
3.11 Write the code for the click event handler of the Remove all button. If the user
confirms, all items must be removed from the list and all textboxes should cleared.
(5)
3.12 Write the code for the click event handler of the List button. Use a foreach to step
through the list and then display the stock in a message box as in the example.
(8)
5
4. Develop a Windows Forms application and name your project Question 4. This
application should allow the user to enter an Italian word in the text box as in the
example and then display the English equivalent. Display an appropriate message if the
Italian word does not appear in the dictionary.
NB) Download the Dictionary text file (Dictionary.txt) from the Assessment Archive
/ Additional Examination link on Blackboard. The dictionary text file has entries in two
fields that are separated by a tab. The first field contains an Italian word and the second
field contains the equivalent English word.
(20)
[117]
Submission Procedure
When you are ready to submit, add all your project folders to a single folder and rename that
folder to your student number. Submit a .zip archive of that folder under the Assessment
Archive / Additional Examination link on Blackboard.