Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

UNIVERSITY OF THE FREE STATE

DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS

CSIQ1624 & CSIS1624

DATE: 16 October 2017 MARKS: 103


ASSESSORS: Mr. M.B. Mase & Mr. D.J. Wium TIME: 180 minutes
MODERATOR: Prof. P.J. Blignaut

SECTION A (13)

 Answer the following questions on the answer sheet that is provided.


 The computer must be switched off while you are completing Section A.
 You may use the textbook (Be Sharp with C#) while completing Section B. Section A
is closed-book.

1. In each case, state whether the following statement is true or false.

1.1. In C#, classes may inherit from two or more base classes.
1.2. Protected methods can be accessed from the class in which they are located as well as
any derived classes.
1.3. One has to indicate the number of arrays that a jagged array can contain when
instantiating the jagged array.
1.4. The default constructor of a class is always available, regardless of which other
constructors the class contains.
1.5. One can add any type of object to a generic list of type object.
[5]

2. You are writing a Windows Forms application using the C# programming language. A user
entered a string that has been assigned to a string variable named sText. Write a code
snippet that will find the first lowercase letter “a” in sText. If sText contains the letter,
display a message to the user that reports the position of the first occurrence in human terms
(the first letter is in position 1). If sText does not contain the letter, display a message that
communicates this to the user.
[8]

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

1
SECTION B (90)

 Add a comment block containing your name and student number to every class that you
code in. Marks will be deducted for failure to do so.
 Adhere to all programming principles as taught. Marks will be deducted for neglect of
naming conventions, non-aligned code and inefficient code.

1. Develop a console application and name your project Question 1. This application allows
the user to add characters to a 10 × 10 two-dimensional grid named Board. Download the
provided code from the Assessment Archive / Module Test 2 link on Blackboard and use
it as is. Follow the instructions below to complete the application.

1.1. GetIndex should return an integer from 1 to 10 representing either the row or column
where the next character is to be added. Examine the calls to this method from the
Main method to determine the signature of GetIndex. Use defensive programming to
avoid run-time errors and repeat the prompt if the user enters an integer outside the
allowed range. (10)
1.2. GetChar should return the next character to be added to Board. Examine the call to
this method from the Main method to determine its signature. (4)
1.3. Display should display Board in the console window as illustrated in the screen print.
Note the display of the row and column numbers along the top and left edges and that
spaces are added between consecutive characters in the same row. (8)

[22]

2
2. Develop a Windows Forms application and name your project Question 2. This application
will allow the user to add two types of aircraft to a list, namely airplanes and helicopters.
The details of the selected aircraft should be displayed.

2.1. Design your form to resemble the screen prints below. Change the DisplayMember
property of the list box to Name. (3)

3
2.2. Add a class named CAircraft to your project of which objects cannot be instantiated.
This class should contain the following: (12)
 A property named Name for the name of the aircraft.
 A property for the maximum speed of the aircraft.
 A property for the number of passengers that the aircraft can carry. The set accessor
of this property should ensure that negative values are not allowed and are instead
changed to zero.
 A method named Details that returns a string with the details of the aircraft. This
string should contain all the information stored in the three properties of the class.
It must be possible to override this method in classes that are derived from
CAircraft.
2.3. Add a class named CAirplane to your project. This class should inherit from CAircraft.
Additionally, it should contain the following: (10)
 A property for the number of engines that the airplane has.
 A constructor that accepts all property values of the airplane as parameters and
assigns them to the properties.
 The Details method should be overridden. It should call the base version and
append the additional information contained in CAirplane.
2.4. Add a class named CHelicopter to your project. This class should inherit from
CAircraft. Additionally, it should contain the following: (6)
 A property for the type of rotor blades that the helicopter has.
 A constructor that accepts all property values of the helicopter as parameters and
assigns them to the properties.
 The Details method should be overridden. It should call the base version and
append the additional information contained in CHelicopter.
2.5. Add the following to your form class:
 When the user clicks the Add button, the correct type of aircraft should be
instantiated with the values entered in the text boxes. This aircraft should be
assigned to an object of type CAircraft that must be declared on form level. Add
the object to the items of the list box and display a message informing the user
that the aircraft has been added. Add a try-catch block to prevent run-time errors
and notify the user if an error occurs. Finally, clear all the text boxes and return
focus to the Name text box. (16)
 When the selected radio button changes, the text of the label above the last text
box should change between “Number of engines” and “Type of rotors”, depending
on the type of aircraft that is selected. (2)
 Whenever there is a change in the selection of aircraft in the list box, the label in
the Details group box should display the details of the selected aircraft by calling
its Details method. If no aircraft is selected, the display should be cleared. (4)

[53]

4
3. Develop a Windows Forms application and name your project Question 3. This application
saves a message from a text box to a text file or loads a message from a text file into the
same text box.
3.1. Design your form as in the screen print below. (2)

3.2. When the user clicks the Save button, the message must be saved to a file that the user
gets to select using an appropriate dialog. If the Append check box is checked, the
message must be appended to the content of the file. Otherwise, it must overwrite the
content. (7)
3.3. When the user clicks the Load button, he must be able to choose a text file using an
appropriate dialog. The text in this file should be read and it should replace the text
displayed in the text box. (6)
[15]

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 / Module Test 2 link on Blackboard.

You might also like