0% found this document useful (0 votes)
50 views34 pages

DONE INF164 2021 Semester Test Memo v4 PDF

The document describes a semester test for the INFORMATICS 164 module. The test is scheduled for 11 October 2021 and will last 120 minutes. It will be invigilated by four examiners and one moderator. The test consists of 4 sections worth a total of 50 marks. Students are instructed to attempt all questions, which are based on the module outcomes in the study guide. Code written for the test must use strict typing.

Uploaded by

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

DONE INF164 2021 Semester Test Memo v4 PDF

The document describes a semester test for the INFORMATICS 164 module. The test is scheduled for 11 October 2021 and will last 120 minutes. It will be invigilated by four examiners and one moderator. The test consists of 4 sections worth a total of 50 marks. Students are instructed to attempt all questions, which are based on the module outcomes in the study guide. Code written for the test must use strict typing.

Uploaded by

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

DEPARTMENT OF INFORMATICS

INFORMATICS 164
SEMESTER TEST DATE: 11 October 2021

Examiners : Dr Mawela
: Dr Mennega
Mr Mazima Time : 120 min
Mr Mthethwa

Moderator / External Examiner : Dr Phil van Deventer Marks : 50

Student Number Surname Initials

Module outcomes (as in Study Guide)


Question / Section Marks allocated Maximum mark

Section A M01-M08 7
Section B M01-M08 18

INF164 – 2021 © UP: Semester Test 1 / 34


Section C M01-M08 7
Section D M01-M08 18

Total 50

Instructions
1. This paper consists of 4 sections.
2. Answer all the questions – there are no optional questions.
3. This is an open book test.
4. Type your answers in the online format presented.
5. Note: Assume implicit conversion is deactivated and all code makes use of strict typing.

"The University of Pretoria commits itself to produce academic work of integrity. I affirm that I am aware of and have read the Rules and Policies of the
University, more specifically the Disciplinary Procedure and the Tests and Examinations Rules, which prohibit any unethical, dishonest or improper conduct
during tests, assignments, examinations and/or any other forms of assessment. I am aware that no student or any other person may assist or attempt to
assist another student, or obtain help, or attempt to obtain help from another student or any other person during tests, assessments, assignments,
examinations and/or any other forms of assessment."

INF164 – 2021 © UP: Semester Test 2 / 34


SECTION A – (7 marks)

Question 1 (2 Marks)
Question Answer
Consider the figure below which represents an array that may store the sales double[ , ] salesPerYear = new double[4,3]
figures (in rands) of a toy store per year.

Provide the code that will declare this array named: salesPerYear

Review the figure below which represents an array that may store the rainfall double[ , ] rainfallPerYear = new double[3,2]
figures (in millimeters) for Pretoria per year.

Provide the code that will declare this array named rainfallPerYear:

Consider the figure below which represents an array that may store the monthly double[ , ] costsPerMonth = new double[5,4]
expenses (in rands) of a household.

Provide the code that will declare this array named costsPerMonth

INF164 – 2021 © UP: Semester Test 3 / 34


Question 2 (2 Marks)

Question Answer
Provide the 2 lines of code that will find the number of rows in a DataGridView dgvBooks.Rows.Count;
named dgvBooks AND change the colour of the text of the cell that is in the first dgvBooks.Rows[0].Cells[0].Style.ForeColor = Color.Yellow;
row/first column of the DataGridView to yellow

Give the code to find the number of columns in a DataGridView named dgvToys dgvToys.Columns.Count;
AND change the colour of the cell that is in the first row/first column of the dgvToys.Rows[0].Cells[0].Style.BackColor = Color.Blue;
DataGridView to blue.

Write the code to find the number of columns in a DataGridView named dgvCars dgvCars.Columns.Count;
AND change the colour of the text of the cell that is in the first row/first column of dgvCars.Rows[0].Cells[0].Style.ForeColor = Color.Red;
the DataGridView to red

Question 3 (2 Marks)
Question Answer
a)Explain how the following line of code can cause an exception. (2 If the users do not enter anything or enter a letter instead of a number. √
marks) , an exception will occur since the conversion will not be able to take place. √
int memberCode = Convert.ToInt32(txtMemberCode.Text);

a)Explain how the following line of code can cause an exception. (2 If the users do not enter anything or enter a letter instead of a number. √
marks) , an exception will occur since the conversion will not be able to take place. √
int districtID = Convert.ToInt32(txtDistrictIdentifier.Text);
a)Explain how the following line of code can cause an exception. (2 If the users do not enter anything or enter a letter instead of a number. √
marks) , an exception will occur since the conversion will not be able to take place. √
int studentNumber = Convert.ToInt32(txtStudentNum.Text);

INF164 – 2021 © UP: Semester Test 4 / 34


Question 4 (1 Marks)
Question Answer
A DataGridView can have the following as its datasource: e)All of the above
a. An array of objects
b. A list class
c. A binding list
d. A 2D array
e. All of the above
Which of the following will enable you to add an extra row to a DataGridView c)dgvSalary.Rows.Add();
named dgvSalary ?
a. dgvSalary.Rows.Value();
b. dgvSalary.Add.Rows();
c. dgvSalary.Rows.Add();
d. dgvSalary.Value. Rows();
e. None of the above

Which of the following statements gives the number of rows in a DataGridView c) dgvSalary.Rows.Count – 1
called dgvSalary (ignoring the * row)?

a. dgvSalary.CurrentCell.Count
b. dgvSalary.CurrentCell.Count – 1
c. dgvSalary.Rows.Count – 1
d. dgvSalary.Rows.Count
e. dgvSalary.Rows.Count – 2

INF164 – 2021 © UP: Semester Test 5 / 34


SECTION B – (18 marks)

Question 1 (3 Marks)

Question Answer
The block of code below calls a method that does a simple division calculation. In Solution
this case, the programmer forgot that the divisor is zero, hence the program will
crash due to a math exception error. try (1)
{
Alter the code below using the appropriate exception handling concept to ensure
that it does not crash. You should also display a message box in the instance of a }
possible error.
catch (DivideByZeroException) (1)
{
MessageBox.Show("Error caused by dividing by zero."); (1)
}

OR
catch (Exception GeneralException) (1)
{
MessageBox.Show(“General Exception” + GeneralException.Message); (1)
}

The block of code below lets the user select any song of their choice to play using try (1)
the windows media player control. In this case, the last line of the code causes the {
program to crash due to a general exception error.

INF164 – 2021 © UP: Semester Test 6 / 34


Alter the code below using the appropriate exception handling concept to ensure }
that it does not crash. You should also display a message box in the instance of a catch (Exception GeneralException) (1)
possible error. {
MessageBox.Show(“General Exception” + GeneralException.Message); (1)
}

The block of code below uses the Load File Method to read a “note.rtf” file in the Solution
debug folder. In this case the INF154 student typed in the wrong file name, hence
the program will crash due to a file not found exception. try (1)
{
Alter the code below using the file not found exception handling concept to ensure
that it does not crash. You should also display a message box in the instance of a }
possible error. catch (FileNotFoundException Exception) (1)
{
MessageBox.Show(“FileNotFoundException Exception” + Exception.Message); (1)
}

Question 2 (3 Marks)

Question Answer
Consider the following screenshot of an event handler with an array called Solution
gradesArr and complete the code. When btnSaveGrades is clicked, save the list of
module codes along with the grades in a text file called ‘grades.txt’ on three StreamWriter outputFile = new StreamWriter("grades.txt"); (1)
separate lines. for (int i = 0; i < gradesArr.Length; i++)
{
outputFile.WriteLine(gradesArr[i]); (1)
}

INF164 – 2021 © UP: Semester Test 7 / 34


outputFile.Close(); (1)

Consider the following screenshot of a form and event handler. Solution


Provide code that will save the employee's wage details in a text file called
‘employeeWages’ on three separate lines when btnSaveInfo is clicked. StreamWriter outputFile new StreamWriter ("employeeWages.txt”); (1)
The names of the controls are txtName, txtJobPosition, and txtWages respectively. outputFile.Write(txtName.Text);
outputFile.Write(txtJob.Text);
outputFile.Write(txtWages.Text); (1)
outputFile.Close();(1)

INF164 – 2021 © UP: Semester Test 8 / 34


Consider the following screenshot of a text file, form and event handler. Solution
Provide code that will load in a dairy entry on the rich text box from the txt file
(called: dairyEntry.txt) when btnLoad is clicked. string input;
StreamReader inputFile = new StreamReader("dairyEntry.txt"); (1)
input = inputFile.ReadToEnd();
rtbDiaryEntry.Text = input; (1)
inputFile.Close(); (1)

INF164 – 2021 © UP: Semester Test 9 / 34


Question 3 (6 Marks)
Question Answer
Draw what the Data Grid View dgvFigure will look like after the code below has
been executed. Leave out the column and row headers.
Solution

2 marks for correct dimension (3 columns by 5rows)


4 mark for correct values

Additional Instructions

Note: use the table option that is available in ClickUP to draw your
datagridview answer. See below:

INF164 – 2021 © UP: Semester Test 10 / 34


Or you can draw it, take picture of your drawing and upload it as part
of your answer.

Draw what the Data Grid View dgvDiagram will look like after the code below has Solution
been executed. Leave out the column and row headers.
2 marks for correct dimension (4columns by 4rows)
4 marks for correct values X’s and O’s

INF164 – 2021 © UP: Semester Test 11 / 34


Additional Instructions

Note: use the table option that is available in ClickUP to draw your
datagridview answer. See below:

Or you can draw it, take picture of your drawing and upload it as part
of your answer.

Draw what the Data Grid View dgvTable will look like after the code below has
been executed. Leave out the column and row headers. Solution

2 marks for correct dimension (4columns by 3rows)


4 marks for correct values

INF164 – 2021 © UP: Semester Test 12 / 34


Additional Instructions

Note: use the table option that is available in ClickUP to draw your
datagridview answer. See below:

Or you can draw it, take picture of your drawing and upload it as part
of your answer.

Question 4 (6 Marks)
Question Answer
Complete the class below that will enable the C# windows form to print the
following information in a dataGridView (Item, Quantity, Price, Total) when the A
Add button is pressed. public Sales(string Item, int Quantity, double Price)
{
Consider the following screenshots of a Sales class and point of sale screen and mItem = Item;
provide code for the following mQuantity = Quantity;
mPrice = Price;
A. the overload constructor which takes in 3 parameters only as shown in the mTotal = CalculateTotal();
POS screen. }
B. method that will calculate the total of a new sale captured called 2 marks for a parameter constructor with correct data types
CalculateTotal. 1 mark for correct assigning of variables
1 mark for method calling statement

B
public double CalculateTotal()
{

INF164 – 2021 © UP: Semester Test 13 / 34


return mTotal = mQuantity * mPrice;
}
1 mark for return type method
1 mark for correct formula

INF164 – 2021 © UP: Semester Test 14 / 34


When the user clicks on the Add button, the new sales record will be added to a Solution
binding list and shown in dataGridView.
A
Consider the following screenshots of frmPOS.cs and the point-of-sale screen. BindingList<Sales> salesList = new BindingList<Sales> ();
Provide code for the following 2 marks for correct solution

A. a binding list which will store objects of the Sales class called salesList. B
(2) Sales newSale = new Sales
(
txtItem.Text,

INF164 – 2021 © UP: Semester Test 15 / 34


B. functionality which adds a new sales entry using an overload constructor Convert.ToInt32(txtQuantity.Text),
in the sales class which takes in 3 parameters only as shown in the POS Convert.ToDouble(txtPrice.Text)
screen. (4) );
salesList.Add(newSale);
1 mark for creating object eg. newSale or sale
2 marks for passing controls in sales constructor
1 mark for adding new sale in list

B – Alternative
Sales newSale = new Sales();
newSale.Item = txtItem.Text;
newSale.Price = Convert.ToDouble(txtPrice.Text);
newSale.Quantity = Convert.ToInt32(txtQuantity.Text);
newSale.Total = newSale.CalculateTotal();
salesList.Add(newSale);
1 mark for creating object eg. newSale or sale
2 marks for assigning controls and using method
1 mark for adding new sale to list

INF164 – 2021 © UP: Semester Test 16 / 34


INF164 – 2021 © UP: Semester Test 17 / 34
SECTION C – (7 Marks)

Question 1 (2 Marks)
Question Answer
Why will the code not work? Answer:
The third parameter of the method GetHMS should be a ref parameter

Why will the code not work? Answer:


The signature of the method GetHMS and the calling statement do not
match

INF164 – 2021 © UP: Semester Test 18 / 34


Why will the code not work? Answer:
The first and second parameters of the method GetHMS should be out
parameters

Question 2 (2 Marks)

Question Answer
Consider the following code, which shows the first few lines of a class “Pet” Answer:
being written: public Pet(string name, int age, string type)
{
mName = name;
mAge = age;
mType = type;
}

Complete the code needed for the constructor. (2 Marks)

Consider the following code, which shows the first few lines of a class “Pet” Answer:
being written:
public string Name
{
get { return mName; }
set { mName = value; }
}

INF164 – 2021 © UP: Semester Test 19 / 34


Complete the code needed for the Name property of the data member
mName. (2 Marks)

Consider the following code, which shows the first few lines of a class “Pet” Answer:
being written: public int Age
{
get { return mAge; }
set { mAge = value; }
}

Complete the code needed for the Age property of the data member mAge.
(2 Marks)

Question 3 (1 Mark)
Question Answer
The markup part of _____ structures the web page when it is opened in a Answer: HTML
browser such as Chrome.

The purpose of JavaScript is to add ___________________ to a web site. Answer: interactivity

Code running in the web browser is known as ______-side code Answer: client-side

Question 4 (1 Mark)
Question Answer
True or False Answer: True

Server-side website programming mostly involves choosing which content


is returned to the browser in response to requests.

True or False Answer: False

INF164 – 2021 © UP: Semester Test 20 / 34


A dynamic webpage is a webpage that displays the same content for all
users.

True or False Answer: True

In web development, 'client side' refers to everything in a web application


that is displayed or takes place on the client (end user device)

Question 5 (1 Mark)
Question Answer
Multiple Choice Answer: c

Most of the code to support dynamic web pages, run on the server.
a This is called "server-side programming"
b This is called "back-end scripting"
c Both of the above
d None of the above

Multiple Choice Answer: c


Choose the incorrect statement regarding JavaScript:
a JavaScript is a programming language that runs in a web browser
b JavaScript can be inserted into the HTML code
c JavaScript is only used for creating web pages
d JavaScript enables the interaction of websites with visitors

Multiple Choice Answer: a

Choose the incorrect statement regarding client-side code:


a Client-side code has complete access to the underlying operating system
b Client-side code is written using HTML, CSS, and JavaScript
c Many contemporary developers are including client-side processes in
their apps
d The client side is sometimes also known as the frontend

INF164 – 2021 © UP: Semester Test 21 / 34


SECTION D – (18 marks)

Question 1 (3 Marks)
Question Answer
Consider the method and button event handler below (i) calculatePrice(Cost, ref Markup, out Price);(2)
(i) Provide an appropriate calling statement. (ii) R87,04 (1)
(ii) Provide the answer for Price in Rands (what will the amount be when the code is
executed).

Consider the method and button event handler below (i) calculateCostPrice(out Cost, ref MarkupPercent, ref
(i) Provide an appropriate calling statement. Price);(2)
(ii) R86 (1)
(ii) Provide the answer for Cost in Rands (what will the amount be when the code is
executed).

INF164 – 2021 © UP: Semester Test 22 / 34


Consider the method and button event handler below (i) calculateMarkUpPrice(MarkupPercent, out MarkUpCost,
(i) Provide an appropriate calling statement. ref Price);
(ii) R21.5
(ii) Provide the answer for the MarkUp cost in Rands(what will the amount be when the
code is executed).

INF164 – 2021 © UP: Semester Test 23 / 34


Question 2 (3 Marks)
Question Answer
Consider the event handler below:
Provide the code for the calculateRevenue Method public double calculateRevenue(double Income, doubleExpenses)
{
Formula for Revenue: Revenue = Income - Expenses
return Income - Expenses;
}

1 Mark double
1 Mark (double Income, doubleExpenses)
1 Mark Correct return

Consider the event handler below: public void calculateweight(double mass, double gravity)
Provide the code for the calculateWeight Method {
weight = mass * gravity;
Formula for Weight: Weight = mass x gravity }

1 Mark void
1 Mark (double mass, double gravity)
1 Mark Correct use of global variable

Consider the event handler below: public int calculateArea(int length, int breadth)
Provide the code for the calculateArea Method {
return length * breadth;
}

1 Mark double
1 Mark (int length, int breadth)
1 Mark Correct return

INF164 – 2021 © UP: Semester Test 24 / 34


Formula for Area: Area = Length x Width

Question 3 (6 Marks)

Question Answer
Complete the class below: public Plants()
{
Consider the following screenshots of a Plant class and nursery database mName = "";
mSunExposure = "";
and provide code for the following mBloomingSeason ="";
A. Default Constructor for the class (3) mWater = 0;
B. The Nursery is running a promotion to sell plants that bloom in the price = 0 ;
summer. Create a method in the class that checks if the blooming season }
is Summer and returns true or false (3)
B. public bool Christmasgift()
{
if (mBloomingSeason == "Summer")
{
return true;
}
else
{
return false;
}
}

1 Mark correct constructor declaration

INF164 – 2021 © UP: Semester Test 25 / 34


2 Mark Correct assignment of default values

1 Mark correct bool method declaration


1 Mark Correct if Statement
1 Mark correct return variables

INF164 – 2021 © UP: Semester Test 26 / 34


Consider the following screenshots provide code for the following: A. ClientList.Add(addform.newClient);(2)

A. The code necessary to retrieve the “newClient” object from the dgvClients.DataSource = ClientList; (1)
AddClientForm, add it to the ClientList and make list the data
source of a DataGridView named “dgvClient” (3) B. newClient = new Client();(1)
B. The code necessary to initialize the newClient object with the newClient.Name = name;
variables and close the form (3) newClient.Age = Age;
newClient.Surname = surname;(1)
this.Close();(1)

INF164 – 2021 © UP: Semester Test 27 / 34


INF164 – 2021 © UP: Semester Test 28 / 34
Question 4 (6 Marks)

Question Answer

When the btnSaveCustomers event handler is clicked it should search through the for (int i = 0; i < 10; i++)
{
datagridview(dgvCustomers) and retrieve the first 10 customers, add them to a for (int j = 0; j <dgvCustomer.Columns.Count; j++)
binding list and write the list to a serialized file name “customers.ser”. {
currentcustomer = new customer();
currentcustomer.ID = Convert.ToInt32(dgvCustomer[j, i].Value);
Provide all the necessary code to make this possible. currentcustomer.Name = dgvCustomer[j, i].Value.ToString();
currentcustomer.Surname = dgvCustomer[j, i].Value.ToString();
currentcustomer.AccountType = dgvCustomer[j,i].Value.ToString();
Consider the Screen shot below:
myCustomersList.Add(currentcustomer);
}

}
FileStream outFile = new FileStream("Customers" + ".ser", FileMode.Create,
FileAccess.Write);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(outFile, myCustomersList);
outFile.Close();

1 Mark outer loop less than 10


2 Marks Assigning object properties correctly and adding to list
3 Marks Correct Serialization to “Customers.ser” file

INF164 – 2021 © UP: Semester Test 29 / 34


When the btnGoldCustomers event handler is clicked it should search through the {

datagridview(dgvCustomers) and retrieve the customers with Gold Account if (dgvCustomer[3, i].Value.ToString() == "Gold")
Types, add them to a binding list and write the list to a serialized file name {
for (int j = 0; j < dgvCustomer.Columns.Count; j++)
“GoldCustomers.ser”. {
goldcustomer = new customer();
goldcustomer.ID = Convert.ToInt32(dgvCustomer[j, i].Value);
Provide all the necessary code to make this possible.

INF164 – 2021 © UP: Semester Test 30 / 34


goldcustomer.Name = dgvCustomer[j, i].Value.ToString();
goldcustomer.Surname = dgvCustomer[j, i].Value.ToString();
goldcustomer.AccountType = dgvCustomer[j, i].Value.ToString();
Consider the Screen shot below: myCustomersList.Add(goldcustomer);
}
}

}
FileStream outFile = new FileStream("GoldCustomers" + ".ser", FileMode.Create,
FileAccess.Write);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(outFile, myCustomersList);
outFile.Close();

1 Mark if statement for gold customers


2 Marks Assigning object properties correctly and adding to list
3 Marks Correct Serialization to “Customers.ser” file

INF164 – 2021 © UP: Semester Test 31 / 34


When the btnEvenCustomers event handler is clicked it should search through the for (int i = 0; i < dgvCustomer.Rows.Count; i++)
{
datagridview(dgvCustomers) and retrieve the customers with Gold Account

INF164 – 2021 © UP: Semester Test 32 / 34


Types, add them to a binding list and write the list to a serialized file name if ((Convert.ToInt32(dgvCustomer[0, i].Value) % 2) == 0)
{
“EvenCustomers.ser”. for (int j = 0; j < dgvCustomer.Columns.Count; j++)
{
goldcustomer = new customer();
Provide all the necessary code to make this possible. goldcustomer.ID = Convert.ToInt32(dgvCustomer[j, i].Value);
goldcustomer.Name = dgvCustomer[j, i].Value.ToString();
goldcustomer.Surname = dgvCustomer[j, i].Value.ToString();
Consider the Screen shot below: goldcustomer.AccountType = dgvCustomer[j, i].Value.ToString();
myCustomersList.Add(goldcustomer);
}
}

}
FileStream outFile = new FileStream("EvenCustomers" + ".ser",
FileMode.Create, FileAccess.Write);
BinaryFormatter bFormatter = new BinaryFormatter();
bFormatter.Serialize(outFile, myCustomersList);
outFile.Close();

1 Mark if statement for even customers


2 Marks Assigning object properties correctly and adding to list
3 Marks Correct Serialization to “Customers.ser” file

INF164 – 2021 © UP: Semester Test 33 / 34


INF164 – 2021 © UP: Semester Test 34 / 34

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy