You are on page 1of 2

SCHOOL OF MATHEMATICS, STATISTICS &

COMPUTER SCIENCE

UNIVERSITY OF KWAZULU NATAL

WESTIVILLE CAMPUS

Practical II

COURSE CODE: COMP201 Data Structures

Examiner: Mr E. Jembere
Duration: 0pen
Marks : 100

Instructions

1. Attempt all questions.


2. Your solutions will be marked/assessed during the practical session on Tuesday, 01 August 2017.
Please note that no marking will be done before or after the practical session.
3. Assessment will be done NOT only on your code, but also on your ability to explain your code.
Inability to explain your code will cost you all your marks for that question.
4. You are advised to come for the practical session almost done with all questions on this paper.
5. The stars against the questions indicate the level of difficulty of a question. The level of difficulty
is rated easy (no star), moderate (*), hard (**), or challenging (***).

1. *Write a java program to read in a Java source code file and count the occurrence of each keyword in
the file, but don’t count the keyword if it is in a comment or in a string literal.
[20 marks]
2. **Write a program that reads words from a text file, counts the occurrence of each word in the file, and
stores words and their frequencies in a map and displays the words and their corresponding frequencies
in the order of their frequency. In the storage of the word occurrences, the words should remain the keys
and the frequencies should remain the values. Please note that you are not expected to create the class
“WordOccurence” as was expected in Practical I.
[30 marks]
3. *Write a program that reads the data in the file marks.csv provided on Moodle and store the data in a
data structure that enables efficient retrieval of all the modules that a given student has attempted and

1|Page
their corresponding marks (see Figure 1). The program should read the file once, through a single pass
through the file. Thereafter all queries for student marks should be done on the data structure. The
program should have GUI such as the one shown in Figure 1 that allows the user to pass a student
number as query for the student’s marks.

Figure 1: GUI for displaying student marks

[20 marks]
4. **(Postfix notation) Postfix notation is a way of writing expressions without using parentheses. For
example, the expression (1 + 2) * 3 would be written as 1 2 + 3 *. A postfix expression is evaluated
using a stack. Scan a postfix expression from left to right. A variable or constant is pushed into the
stack. When an operator is encountered, apply the operator with the top two operands in the stack and
replace the two operands with the result. The following diagram shows how to evaluate 1 2 + 3 *.

Write a program to evaluate postfix expressions. Pass the expression as a commandline argument in
one string.

[30 marks]

----------------------------------------------------------------------------------------------------------------

WISHING YOU ALL THE BEST

2|Page

You might also like