0% found this document useful (0 votes)
18 views

ModuleTest1 2016

This document contains instructions for a computer science exam consisting of two questions. Question 1 involves creating a Windows Forms application to track football players' details. Students must create a Player class with properties for name, goals, assists, and age. The form should allow adding players to a list and display the list. Question 2 involves creating another Windows Forms application to select and display shape details. Students must create an abstract Shape class and subclasses for specific shapes, implementing properties and methods to calculate and display each shape's details.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

ModuleTest1 2016

This document contains instructions for a computer science exam consisting of two questions. Question 1 involves creating a Windows Forms application to track football players' details. Students must create a Player class with properties for name, goals, assists, and age. The form should allow adding players to a list and display the list. Question 2 involves creating another Windows Forms application to select and display shape details. Students must create an abstract Shape class and subclasses for specific shapes, implementing properties and methods to calculate and display each shape's details.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIVERSITY OF THE FREE STATE

DEPARTMENT OF COMPUTER SCIENCE AND INFORMATICS

CSIS1624

DATE: 29 August 2016 MARKS: 102


ASSESSOR: Mr. D.J. Wium TIME: 180 minutes
MODERATOR: Prof. P.J. Blignaut

SECTION A (21)
 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. Choose the correct option:


1.1. Classes are (value/reference) types. (1)
1.2. Read-only properties contain only (get/set) accessors. (1)
1.3. The (virtual/abstract) keyword indicates that a method may be overridden in
sub-classes. (1)
1.4. (Overloading/Inheritance) describes the process whereby derived classes
obtain the attributes and behaviour of their base classes. (1)

2. Write down the missing word(s):


2.1. Methods with the ___________ access modifier are only accessible in the class
where they are defined as well as any derived classes. (1)
2.2. One can use an _________________ to instantiate an object without
using a constructor. (1)
2.3. An ___________ class is one from which objects cannot be instantiated but
other classes can be derived. (1)
2.4. ___________ refers to the ability of objects belonging to different sub-classes to
respond to a method defined with the same name in the base class. (1)

Question 3 on back of page

1
3. Draw a UML Class diagram for the following scenario:
 Base class CVehicle, with the following:
o a private string data field for its registration number,
o a public string property for its registration number,
o a public int property for its age,
o a public abstract method named ShowInfo with return type string.
 Class CCar that is derived from CVehicle, with the following:
o a public int property for the number of cylinders it has. (13)

2
SECTION B (81)

 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 class. 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 (40)
Create a C# Windows Forms application using Visual Studio and name your project
Question1.
The application should allow the user to input the details of football players and should then
list all players that have been added, as in the screenshot below.

Add a class called CPlayer.cs to your project. This class should contain the following:
 Read-only auto-implemented properties for the name of the player, the number of goals
he has scored and the number of assists he contributed.
 A private data field for the player’s age, accompanied by a public property. The relevant
accessor of the property should ensure that a player’s age is no less than 15 and no more
than 45. If values outside this range are encountered, they should be replaced by the
closest acceptable value.

3
 A constructor that accepts the player’s name, age, goals and assists as parameters and
assigns them to the appropriate properties.
 A Description() method that returns a string summarising the player’s information in one
line for the purpose of displaying it in the listbox, as in the screenshot.

Your form class must be implemented in the following way:


 It must contain a private list or array of type CPlayer in which all players that the user
adds, will be stored.
 It must contain a method UpdateList() which is called to update the display of the
players in the listbox whenever a new player is added or when the program loads.
 It must contain a method ClearFields() that clears the Name textbox and sets the Age,
Goals and Assists numericupdown values to default values of 25, 0 and 0 resprectively.
This method should be called whenever a player is added and when the program
loads.
 When the user clicks the Add button, a player must be instantiated and added to the
list of players if his name is not an empty string and if another player with the same
name is not already present in the list. Appropriate messages must be shown for these
two conditions.

Question 2 (41)
Create a C# Windows Forms application using Visual Studio and name your project
Question2.
The application should let the user select a shape and then display relevant details, as in the
screenshots below.

4
Add an abstract class CShape.cs to your project that contains the following:
 Three auto-implemented properties for the name, number of sides and area of the
shape.
 A virtual method, Summary(), that returns a string which summarises the properties of
the shape as is displayed in the richtextbox in the screenshots.

Add three sub-classes of CShape.cs to your project and name them CCircle.cs, CTriangle.cs
and CSquare.cs. Each of these three classes must contain the following:
 Auto-implemented properties for the information used to calculate the area of the
shape. For a circle its radius is required, for a triangle its base and height is required,
and for a square its side length.
 A constructer that accepts parameters for the properties mentioned in the previous
bullet and assigns them to the appropriate properties. Any negative values for the
parameters should be changed to 0 and then assigned to the properties. The area of
the shape should be calculated and assigned here (use the formulas at the end of this
document). The remaining properties, of which the values should be self-evident, but
can be read from the screenshot otherwise, must also be assigned values here.
 The Summary() method of the base class must be overridden to add the information
that is unique to each shape.

The form class must be implemented according to the following:


 When the CheckedChanged event of the radiobuttons is activated, the display of the
groupbox on the right should:
o display the correct shape name,
o contain the correct number of textboxes (2 for triangle and 1 for circle and
square), which should be cleared,
o prompt the user for the information using the labels above the textboxes.
The textboxes can be hidden and be made to appear by toggling their Visible
properties.
 Additionally, the richtextbox should be cleared when the CheckedChanged event fires.
 When the user clicks the Update button, a suitable shape should be instantiated and
assigned to a variable of type CShape, which must be declared at form level. A call to
this variable’s Summary() method should be executed to display the shape’s
information in the richtextbox. Add defensive programming to prevent run-time errors.

5
Submission Procedure
When you are ready to submit, add both your project folders to a single folder and rename
that folder to your student number. Submit a .zip archive of the folder on Blackboard.

Formulas for the surface area of shapes


Circle: Area = Math.PI * Radius * Radius
Triangle: Area = 0.5 * Base * Height
Square: Area = SideLength * SideLength

You might also like