Professional Documents
Culture Documents
AegrotatTest 2016
AegrotatTest 2016
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 (13)
Create a C# Console application using Visual Studio and name your project Question1.
The application should help the user to build a sandwich by requesting which toppings should
be added and by calculating the final price of the sandwich. See the screenshot below for an
example of what is expected.
1
Add a class named CSandwich.cs to your project. This class should contain the following:
A property named Toppings that returns all the toppings on the sandwich. It should be
impossible to change the value of this property from outside the class.
A read-only property named Price that returns the price of the sandwich. The base
price for a sandwich is R 10.00 and R 5.00 is added for every topping.
A constructor that takes no parameters. The constructor should initialise the data
structure of the Toppings property.
A public method named Details() that returns a string. This string should list the
toppings on the sandwich and display its price, as in the screenshot.
A public method named AddTopping() that accepts the topping to be added as a
parameter and adds it to the data structure of the Toppings property.
The Main() method is provided. You may either re-type the code below or download it from
Blackboard, where it is available from the Aegrotat Test link.
2
Question 2 (50)
Create a C# Windows Forms application using Visual Studio and name your project
Question2.
The application should allow the user to add batsmen, bowlers and wicketkeepers to a list of
cricketers, as shown in the screenshot below.
Add a class named CCricketer.cs to your project, of which no object can be instantiated. This
class should contain the following:
Properties for the player’s surname, batting average and caps. These properties must
be readable from anywhere, but one should only be able to write to them from the
CCricketer.cs class or any derived classes.
A read-only property named Details that returns the output of the GetDetails() method.
An abstract method named GetDetails() that returns a string.
Add three classes named CBatsmen.cs, CBowler.cs and CWicketKeeper.cs that inherit from
CCricketer.cs. These classes should contain the following:
The CBowler.cs class should contain a property for a bowler’s bowling average. It
should be impossible to write to this property from outside its class.
The CWicketKeeper.cs class should contain a property for the number of stumpings
that a wicket-keeper has performed. The access modifiers for this property should be
the same as for the property for a bowler’s bowling average.
Each of the three classes must contain a constructor that accepts parameters for all
the properties of an object of that class. The constructor should assign the values of
the parameters to the properties. If any of the numeric parameters are less than zero,
a value of zero should be assigned instead.
3
The GetDetails() method should be implemented to display the details of the player on
a single line, as in the list box on the right-hand side of the screenshot.
Hint
One way to update the display in the list box is by doing the following:
Set the DisplayMember property of the list box to “Details”.
Whenever another radio button is checked, change the DataSource property of the list
box to a list containing only the relevant players.
The lists mentioned in the previous step can be generated with the help of LINQ. The
following snippet of code might help: (i => i is CBatsman)
4
Question 3 (54)
Create a C# Windows Forms application using Visual Studio and name your project
Question3.
The application should allow the user to add music albums to a library and to load and save
such libraries. See the screenshot below for an example of what is expected.
Add a class named CAlbum.cs to your project. This class should contain the following:
Properties for the name of the album, the name of the artist, the year in which the
album was released and the number of tracks on the album. These properties should
be readable everywhere, but it should be impossible to write to them from outside the
class.
A constructor that accepts values for all the properties of the class as parameters and
assigns them to the properties.
Add a class named CLibrary.cs to your project. This class should contain the following:
A property named Albums that is a list of all the albums in the library. This property
should be readable everywhere, but one should not be able to write to it from outside
the class.
A constructor that accepts no parameters. The constructor should initialise the Albums
property.
A method named Display(). This method should return a string. The string that is
returned should display the details of all albums in the library. In the screenshot, all the
text displayed in the rich text box is a string that was returned by this method.
5
A method named Save(). This method accepts a string which denotes the path to a
library file and saves the library to that file after serializing the library.
A static method called Read(), that returns an object of type CLibrary. This method
accepts a string which denotes the path to a library file and then deserializes that file.
6
Hints
The following code will cause the date time picker to display the year only and to contain up-
down arrows:
dtpYear.Format = DateTimePickerFormat.Custom;
dtpYear.CustomFormat = "yyyy";
dtpYear.ShowUpDown = true;
Submission Procedure
When you are ready to submit, add all of your project folders to a single folder and rename
that folder to your student number. Submit a .zip archive of the folder on Blackboard.