0% found this document useful (0 votes)
20 views11 pages

CSharp - Revision Past Paper - 2019 - With Answers

The document is a final examination marking guide for the course ABC104 - Introduction to Programming with C#.NET, detailing the exam structure, instructions, and a variety of questions covering programming concepts, exception handling, software development stages, and flowcharting. It includes specific questions with marking criteria and sample answers related to programming logic, data persistence, and the use of comments in code. The exam is scheduled for May 22, 2019, with a total of 100 marks allocated over various sections.

Uploaded by

Larry Thebenala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views11 pages

CSharp - Revision Past Paper - 2019 - With Answers

The document is a final examination marking guide for the course ABC104 - Introduction to Programming with C#.NET, detailing the exam structure, instructions, and a variety of questions covering programming concepts, exception handling, software development stages, and flowcharting. It includes specific questions with marking criteria and sample answers related to programming logic, data persistence, and the use of comments in code. The exam is scheduled for May 22, 2019, with a total of 100 marks allocated over various sections.

Uploaded by

Larry Thebenala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

School of Computing and Information Systems

PROGRAMMES :

BSC APPLIED BUSINESS COMPUTING (BSC ABC)

BSC INFORMATION AND COMMUNICATION TECHNOLOGY (BSC ICT)

ABC104 – INTRODUCTION TO PROGRAMMING WITH C#.NET Year 1


Semester 2

Final Examination Marking Guide

Date : 22 May 2019


Time: 08:00
Total Marks: 100 Duration
: 2 Hours

Instructions to candidates

1. Candidates must attempt any four (4) questions.


2. Candidates attempting to gain unfair advantage or colluding in any way
whatsoever are liable to be disqualified.
3. Do NOT open the question paper until you are told to do so.
4. Candidates are not allowed to bring any material that may be used to copy,
collude or plagiarize the examinations
5. Students are not allowed to write on the question paper

This paper consists of 10 printed pages


Candidates must answer any four questions

Question 1

a) Study the following program code and answer the questions that follow.

private void button2_Click(object sender, EventArgs e) {


//declare variables
String AgeGroup = "";
//Read age
int age = Convert.ToInt32(txtAge.Text );
//Evaluate AgeGroup
AgeGroup = (age <= 5) ? "Infant" :
(age <= 12) ? "Child" :
(age <= 19) ? "Teenager" :
(age <= 35) ? "Youth" :
(age <= 55) ? "Adult" : "Senior Citizen";
//display
txtAgeGroup.Text = AgeGroup;
}

i. Rewrite the above program using if .. else if conditional structure [10 Marks] Answer:

private void button2_Click(object sender, EventArgs e) {


//declare variables
String AgeGroup = "";
//Read age
int age = Convert.ToInt32(txtAge.Text );
//Evaluate AgeGroup if(age<= 5)
{
AgeGroup = "Infant";
} else if(age <= 12) {
AgeGroup = "Child";
} else if(age <= 19) {
AgeGroup = "Teenager";
} else if(age <= 35) {
AgeGroup = "Youth";
} else if(age <= 55) {
AgeGroup = "Adult";
} else {
AgeGroup = "Senior Citizen";
}
txtTest2.Text = AgeGroup;
}
- 1mark for each correct condition, max 5
- 1 mark for each correct label, max 5
b) Exception handling helps to save time and increase productivity.
i. Define the term Exception. [1 Marks]
- An exception is an error that may occur within a program - 1 mark for the correct
answer

ii. Explain the term Exception Handling. [2 Marks]


- Exception handling is the process of catching and gracefully managing errors to
avoid sudden program termination or unexpectedly breaking into code.
- 2 marks for the correct answer

ii. How is Exception Handling implemented in C#.Net, demonstrate with a clear


example. [3 Marks]
- Exception handling is done through the use of Try and Catch structures e.g. try{
---
---
} catch(Exception ex){
MessageBox.Show(ex.Message);
}
- 3 marks for the correct answer

c) Text Files are sometimes used to persist program data.


i. What is meant by data persistence? [2 Marks]
- Data persistence is making data available beyond the closing of a program or
shutting down of a computer
- 2 marks for the correct answer

ii. State one disadvantage of using Text Files For data persistence. [2 Marks]
- Text Files have variable length fields making it difficult to mark where fields start and
end
- 2 marks for the correct answer

iii. How can the disadvantage stated in ii above be overcome? [2 Marks]


- Special characters may be used to mark the end of a field e.g. | or # or , etc
- 2 marks for the correct answer
iii. State any other two possible ways through which program data can be
persisted.
[2 Marks]
- MS Excel, Databases (MS Access, MS SQL Server, Oracle, MySQL
etc.) - 2 marks for the correct answer

iv. What does the acronym CSV stand for? [1 Marks]


- Comma Separated Values
- 1 mark for the correct answer
[Total Marks 25]

Question 2

a) Explain the following terms as used in software development.


i. Program [2 Marks] ii.
Algorithm [2 Marks] iii.
Comment [2 Marks] iv.
MSIL [2 Marks] v.
CLR [2 Marks]

Answers (2 marks each, max 10):


i. Program - is a set of instructions written in a programming language
directing a computer on what to do.
ii. Algorithm – Is a finite set of explicitly ordered steps describing a solution
to a problem.
iii. Comment – A statement found in a program, which is not part of the
executable program, but helps the programmer as documentation of
what the program does.
iv. MSIL – Stands for Microsoft Intermediate Language, it is the semi
compiled Visual Studio program code produced by the compiler.
v. CLR – Stands for Common Language Runtime, is a managed execution
environment that is part of Microsoft's . NET framework. CLR manages
the execution of programs written in different supported languages. CLR
transforms source code into a form of bytecode known as Common
Intermediate Language (CIL).
b) Visual Studio has several built-in programming languages.
i. State any 3 programming languages found in Visual Studio. [3 Marks]
ii.Visual studio C# uses which translator program? [2 Marks]

Answers :
i. C#, VB.Net, C, C++, F#, JavaScript - 1 mark each correct, max 3
ii. Compiler - 2 mark

c) System designers makes use of flow charts in the design process.


i. Draw any five (5) symbols of flow charts and clearly label each. [5 Marks]
ii. Draw a flow chart for a Do While Loop to display numbers from 1 to 10 in
ascending order. [5 Marks]

Answers :
i. Flowchart Symbols ( 1 mark for each correct answer – max 5)

ii. Flowchart for Do While Loop


- 1 mark initialisation, 1 mark display, 1 mark increment, 2 marks decision
[Total Marks 25]

Question 3

d) Software development is a complex process and is often done in stages.


i. State any five (5) stages or phases of software development; [5 Marks]

Answers (1 mark each, max 5):


vi. Requirements gathering
vii. Planning
viii. Implementation
ix. Testing
x. Deployment
xi. Support
xii. Documentation

ii. For each of the stages identified in i. above explain its purpose and name the
group of people who accomplishes it. [10 Marks]
Answers (1 mark each for purpose, 1 mark for the people working on it, max 2):
iii. Requirements gathering – gathering system specifications so that the system
may perform as required by users.
Personnel – System Analysts
iv. Planning/Design – preparing the system architecture and
designs
Personnel – Software architects
v. Implementation/Coding/Development – Translating the designs into
program instructions or coding.
Personnel – Programmers / Developers
vi. Testing – Checking the system to see if it satisfies user
requirements
Personnel – System Testers
vii. Deployment – Installing the system in the user’s environment
so that they may start using it.
Personnel - Developers viii.
Support – Making corrections for remaining errors, or new user
requirements to a system already in use, it is on-going.
Personnel – Maintenance team / developers / Support experts ix.
Documentation – Documenting each task in the project
Personnel – All team members document their respective tasks

e) Complete the following table [5 Marks]


Variable Name Valid (true/false) Reason
first name false Spaces not allowed
#tagline false Special symbols can’t start a variable name
capital_city true Underscores acceptable
1stBlock false Numbers can’t start in a variable name
4444 false Pure numbers not allowed as variable names

- ½ mark each correct answer, max 5


f) Write down answers to the following questions; is int/double/float a class?
i. int num = 20 / 3; and int num = 18 / 3;
why does the above statements have the same answer? [2 Marks]
ii. Make the necessary corrections for the precise answer to be obtained for the
statements in i. above. [1 Marks]
iii. Distinguish between implicit and explicit conversion? [2 Marks]

Answers:
i. The decimal value is copied into an integer in the first statement, thereby discarding
the fractional component and taking the integral values only which are the same i.e.
6 - (2 marks for the correct answer)
ii. Double num = 20 / 3; - (1 mark for the correct answer)
iii. Implicit – performed by the compiler they is data loss
(1 mark)
Explicit – performed by the developer to avoid data loss. - (1 mark)

[Total Marks 25]

Question 4

a) Identify and explain any five (5) access modifiers supported in visual studio.
[10 Marks]
Answer:
- Private – Access is restricted to members of the current scope, method or class
- Public - Access is granted for all members in the same project
- Protected – Access is restricted to the members of the same Namespace
- Friend - Access is restricted to members of the same class
- Protected Friend – Combines features for protected and friend to determine member
access.
- 2 marks for each correct answer, max 10

b) Write down the answers to the following questions.


i. Describe a variable as used in programming. [1 marks]
ii. Declare and initialize a variable with a value of your full name. [2 marks]
iii. State any two (2) primitives data types in C# [2 marks]
iv. What is a default value for bool data type? [1 marks]
Answer:
- A variable is a temporary unit of storage in the memory of the computer - 1mark
- String fullname = “Oneille Masego”; - 2 marks
- String, int, double, bool, float, char - 1 mark for each answer, max 2
- False - 1 mark

c) Write three overloaded methods called CalculateArea to calculate the area of a Circle,
Rectangle, and Triangle. ( for Circle π=22/7 ) [9 Marks] Answer:
(3 marks for each correct method, max 9)
//area of rectangle
public
double CalculateArea(double L, double W)
{
return L * W;
}
//area of triangle
//add 3rd parameter isTriangle to differentiate from Rectangle
public
double CalculateArea(double B, double H, bool isTriangle)
{
return 1 / 2 * B * H;
}
//area of circle
public
double CalculateArea(double R)
{
return 22 / 7 * R * R;
}

[Total Marks 25]

Question 5

a) Discuss why the use of comments is important when writing programs.


Documentation
comments are used to document apps and improve their readability
b) Explain the two different ways to comment on a program in C#? [6 marks]
- // single line comment
- /* */multi-line comment

b) Identify and correct the errors in each of the following statements:


i. if (c < 7);
{
Console.WriteLine("c is less than 7");
}
Error: Semicolon after the right parenthesis of the condition (c < 7) in the if
statement.
Correction: Remove the semicolon after the right parenthesis. [Note: With the
semicolon, the output statement executes regardless of whether the condition in
the if is true.]
ii. if (c => 7)
{
Console.WriteLine("c is equal to or greater than 7");
}
Error: The relational operator => is incorrect. Correction: Change => to >=.

- 2marks for each correct answer – max 4


[4 marks]
c) Draw a flow diagram to illustrate if-else in C#. [5 marks]

d) Write a program that will allow a system user to enter a Net Income and computes the
amount of income tax as follows: No tax on income up to P15 000; 5 % on income over
P15 000. The program should also display the net income as well as the tax bill.
[10 marks]
double net_income;
double tax_bill;
Console.WriteLine(" Enter net income");
net_income =Convert.ToDouble(Console.ReadLine());
if (net_income <= 15000) { tax_bill = 0;
}
else
{
tax_bill = (0.05 * (net_income - 15000));
}
Console.WriteLine("Net Income"+ net_income);
Console.WriteLine("Tax Bill"+tax_bill);

- Mark allocation:
1 mark variable declaration
2 marks user input
1 mark for calculation of the tax bill
2 displaying Net Income and Tax Bill
5 marks for the if statement construct

Total Marks [25]

You might also like