Professional Documents
Culture Documents
Diploma-Programming 3B Special Exam Memo Fr QA
Diploma-Programming 3B Special Exam Memo Fr QA
REQUIREMENTS:
ALL questions are COMPULSORY. It is in your own interest to write legibly and to present your work
neatly.
Learners are warned that contravening any of the examination rules or disobeying the instructions of an
invigilator could result in the examination being declared invalid. Disciplinary measures will be taken
which may result in the students’ expulsion from Damelin.
Please ensure that you have read and fully understand the following assessment rules and regulations
prior to commencing with your assessment:
1. To be permitted access to the examination, a learner must arrive with:
- an Identity Document or other official proof of identity (for example,
- a student card, passport or driver's licence card with photo); and
- the required exam stationery.
2. No learner may enter the examination room more than 30 minutes after the examination sitting has
commenced and no candidate may leave the room less than one hour after the examination sitting
has commenced.
3. No extra time will be allowed should a student arrive late.
4. All learners must sign the Attendance Register for the examination on arrival.
5. It is the responsibility of learners to familiarise themselves with the examination rules prior to sitting
for the examination.
6. All examinations are to be written on the date and time officially stipulated by the College.
7. It is the responsibility of learners to ensure that they are writing the correct paper and that the
question paper is complete
8. Cell phones must be switched off prior to entering the exam venue. Cell phones and wallets may
be placed under candidates' chairs rather than at the front of the room.
9. Learners may not handle cell phones or wallets during the exam.
10. No weapon of any description may be taken into the assessment room.
11. All personal belongings are to be placed at the front of the examination room. Personal belongings
brought to the examination are at the owner's risk.
12. Smoking is not permitted, and learners will not be allowed to leave the examination room in order
to smoke
13. Once the examination has commenced, all conversation of any form between candidates must
cease until after candidates have left the room, after the examination.
14. Only the official College examination book, as supplied by the College, may be used.
15. Learners must ensure that their student number is written on the answer book.
16. Learners are responsible for ensuring that they follow the instructions in the examination for
submitting their answers.
17. Please read the instruction appearing on the examination paper carefully
18. The number of every question must be clearly indicated at the top of every answer.
19. No pages may be torn out of the answer book. All question papers and scrap paper must be
handed to the invigilator after the examination.
20. Learners finishing earlier are to leave the examination room as quietly as possible on the
instruction of the invigilator and may not talk until outside the building where the examination is
being written.
21. Only under exceptional circumstances will a learner be permitted to leave the examination room
during the examination, and if the invigilator gives permission. An invigilator must accompany the
learner. Only one learner at a time may be absent from the examination room.
22. Candidates may not act dishonestly in any respect.
Outcomes:
• Create objects
• Create properties, including auto-implemented properties
1.1 Explain the difference between ref parameters and out parameters (4)
ANS:
ref parameters do not contain the values associated with the parameters, but
they contain the memory addresses where the values are stored. This allows
the method to alter the original variables. √√
Out parameters, like ref parameters, contain memory addresses that are
passed to a method, allowing them to alter the original variables. The big
difference between ref and out parameters is that ref parameters need to
contain a value before calling the method, while out parameters do not. √√
1.2 Discuss object, property, constructor and default constructor (4)
ANS:
Object - is a variable that is used to access the private and public members of its class, its
data type is its class name. √
Property - is a class field used to set and get values of class’ private members√
Constructor – is a method with the same name as its class used for initialisation of class’
private members. √
Default constructor – one that initialise numeric private members to 0 and string private
members to empty string. It exist even when is not visibly declared. √
1.3 Discuss ancestor, derived class, virtual method, and concrete class (4)
ANS:
Ancestor – is a group of parent classes from which a certain class is derived from. √
Derived class- is a child class, one built by inheriting from parent class√
Virtual method - is one whose behaviour is determined by the implementation
in a child class. √
Concrete class - is a non-abstract class from which objects can be
instantiated. √
1.4 Discuss exception and robustness. (4)
The Dock property attaches a Control to the side of a container so that the
Control stretches when the container’s size is adjusted. √√
Outcomes:
2. Correct the code below so that it will produce expected output specified below. (10
1 using System; )
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpSTudyUnit1
{
class Program
{
static void Main(string[] args)
{
int x = 3, y = 4;
Console.WriteLine("Arguments before calling the Display() "
Console.WriteLine(Ov1(2));
Console.WriteLine(Ov1(2,2,2));
Console.WriteLine(Ov1(2,2,"Hello"));
Console.ReadKey();
}
//overloaded method
public static int Ov1(int a)
{ return a; }
public static int Ov1(int a,int b, String x)
{Console.WriteLine(x);
return a + b;
}
public static int Ov1(int a, int b, int c)
{ return a + b+c; }
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharpSTudyUnit1
{
class Program
{
static void Main(string[] args)
{
}
}
Outcomes:
• Create objects
• Create properties, including auto-implemented properties
A property is a member of a class that provides access to a field of a class. It defines how
fields will be set and retrieved. Properties have accessors, set accessors for setting an
object’s fields called setter, get accessors for retrieving the stored values called getter.
Read-only property has only a get accessor. Write only property has a set accessor.
For read/write there must be both get accessor and set assessor.
3.1 Create a class named Pizza. Data fields include a string for toppings (such as pepperoni), an (20)
integer for diameter in inches (such as 12), and a double for price (such as 13.99). Include
properties to get and set values for each of these fields. Create a class named TestPizza.cs
Expected typical output:
ANS:
Note: Markers are advised to use own discretion for allocating ticks since code may
differ.
namespace PissaStore
{
class Program
{
static void Main(string[] args)
{
//creation of pissa class object given a name p
Pissa p = new Pissa();//instatiation of Pissa class
Console.WriteLine("welcome to Pizza Store:");
Console.WriteLine("Enter pizza diameter:");
p.Diameter = Convert.ToInt32(Console.ReadLine()) ;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PissaStore
{
class Pissa
{
private string topping;
private int diameter;
Outcomes:
• Extend classes
4.1 Write a program in which you declare classes namely Animal.cs and Lion.cs. Declare (20)
abstract method called Speak() within Animal class.
Implement the Speak() method to return string “roooaaar”, do this inside Lion class.
Create an interface called Ilion.cs which declares method Run(), implement the Run
method to return string “I am a Lion and I can’t run fast!”.
Display the resutls of Run() and Speak() method inside Program.cs.
Program.cs class to show output. Name your program Inheritance.
Note that Program.cs is auto-created.
Expected output:
namespace Inheritance
{
class Program
{
static void Main(string[] args)
{
Lion l = new Lion();
Console.WriteLine(l.Run());
Console.WriteLine(l.Speak());
Console.ReadLine();
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Inheritance
{
abstract class Animal
{
public abstract String Speak();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Inheritance
{
class Lion:Animal,ILion
{
public override string Speak()
{
return "roooaaar";
}
public string Run()
{
return "I am a Lion and I can’t run fast!";
}
}
}
namespace Inheritance
{
public interface ILion
{
string Run();
}
}
An exception is an unexpected or error condition. The programs you write can generate many
types of potential exceptions, such as when you do the following:
• You issue a command to read a file from a disk, but the file does not exist there.
• You attempt to write data to a disk, but the disk is full or unformatted.
• Your program asks for user input, but the user enters invalid data.
• The program attempts to divide a value by 0.
• The program tries to access an array with a subscript that is too large or too small.
5.1 Write a program in which you declare an integer array named “arr” of five integers and store (10)
values: 2,4,5,6,7.
Write a try block in which you place a loop that attempts to access each element of the array,
incrementing a subscript from 0 to 10. Create a catch block that catches the eventual
INdexOutOfRangeException; within which the block, display “Now you’ve gone too far” on the
screen. Your program should display “Exception Handling” regardless of exception been
caught or not. Name the file as GoTooFar.cs
Note: Markers are advised to use own discretion for allocating ticks since code may
differ.
ANS:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GoTooFar
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 2,4,5,6,7};
int index = 0;
try
5.2 In the Visual Studio IDE, design a form that allows a user to select options for the background (20)
color and size and to give to the form a title. The form should look like the one shown below.
After the user clicks the “Save Settings” button, save the color, width, height and title to a file
“CustomiseAForm.txt” which you are to create and save in your application root folder. When
you click the button “Apply Settings” the settings should be applied accordingly to your form,
use below screen shorts as test case and guideline.
Note: Markers are advised to use own discretion for allocating ticks since code may
differ.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace CustomiseAForm
{
public partial class Form1 : Form
{
int width,height;
string path,color;
MessageBox.Show(ex.Message);
}
}
public Form1()
{
InitializeComponent();
}
path = "CustomiseAForm.txt";
if (File.Exists(path))
{
StreamWriter sw = new StreamWriter(path);
if (rbBlue.Checked == true) sw.WriteLine(color);
if (rbRed.Checked == true) sw.WriteLine(color);
if (rbYellow.Checked == true) sw.WriteLine(color);
sw.WriteLine(width);
sw.WriteLine(height);
sw.WriteLine(txtTitle.Text);
sw.Dispose();
MessageBox.Show("settings written successfully!");
}
else { MessageBox.Show("Error 404! File not found!");}
} catch(Exception ex) {
MessageBox.Show(ex.Message);
}
}
}