0% found this document useful (0 votes)
14 views7 pages

COS3711 2023 Assignment 2

This assignment asks students to write programs that process text files and work with stock data. It provides details on setting up projects, following best practices, and implementing classes and patterns like singleton, factory method and XML parsing to manage stock lists.

Uploaded by

Caitlin Mudely
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)
14 views7 pages

COS3711 2023 Assignment 2

This assignment asks students to write programs that process text files and work with stock data. It provides details on setting up projects, following best practices, and implementing classes and patterns like singleton, factory method and XML parsing to manage stock lists.

Uploaded by

Caitlin Mudely
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/ 7

COS3711/Assignment 2/2023

Assignment Tutorial Letter 2023

Advanced Programming
COS3711

Year module

Computer Science Department

Assignment 2 Questions

BARCODE

1
COS3711/Assignment 2/2023
Assignment 2

1. Introduction

There are two parts to this assignment.


 Part A is to be submitted for marking.
 Part B is for extra practice of examinable concepts and should not be submitted.

Note:
 Please use CMake (and not qmake) when setting up your assignment projects.
 Qt Designer should not be used to design user interfaces, and you are expected to manually
set up GUIs to ensure that you properly handle memory using Qt’s parent-child functionality.
 You should use QMainWindow as the base class for your GUIs (where console applications
are not being used) and use its functionality to provide menus and status updates.

Good programming practices should be followed.


 Follow standard naming conventions: class names start with a capital letter, variable and
function names start with a lowercase letter, using camelCase for names made up of multiple
words.
 Ensure consistent code layout and use of blank lines.
 Use forward class declarations in header files.
 Use initialiser lists in constructors.
 Have proper GUI management: setting cursor focus, sequential tabbing, clearing input widgets
(like text input fields being cleared and spin boxes being returned to some default value), and
enabling and disabling buttons as appropriate.
 Provide appropriate user feedback.
 Your code should build and run without any warnings.

2. Part A (To be submitted)

Question 1

Write a console application that can be run from the command line using the following forms:
count // run without any parameters
count file1.txt // pass one file name
count file1.txt fileTwo.txt // pass more than one file name
count –a –b file1.txt fileTwo.txt // pass flags to change
behaviour
count –ab –c file1.txt // pass flags in an alternative way

If no arguments are provided, then print a message describing what arguments should be
included.

The application should, using regular expressions, count the number of occurrences of each of
the following in the text files given.

2
COS3711/Assignment 2/2023
 If the –a flag is set, count the number of words longer than 4 characters that start with a capital
letter. There may be further capital letters in the word.
 If the –b flag is set, count the number of words that are hyphenated. This hyphen should not
be at the start or end of a word.
 If the –c flag is set, count the number of words that start and end on the same character.
 If the –d flag is set, count the number of words that do not start with a vowel. Note that these
words can start with any character, and do not just have to start with alphabetic characters.
If no flags are provided, it is assumed that all counts should be performed.

It is suggested that you remove all whitespace at the start and end of the document, as well are
removing all punctuation (.,?!:; and so on) – try doing this using a regular expression. Assume
that there is only 1 space between words.

Remember that to set command line arguments in Qt Creator, click on Projects in the left menu,
click on the Run menu and enter the arguments in the Command line arguments field. You can
also click the Run in terminal check box.

See the screenshot below for an example of the output for the arguments that were used above.

3
COS3711/Assignment 2/2023
Question 2

Write a GUI application that implements the classes that will be used to keep stock for a small
corner store that sells only confectionery and reading material. For each item you will track two
things: what it is, and how many items you have in stock. The derived classes will add one
appropriate data member of their own. Use the UML class diagram below to assist you. Note that
you should not be able to instantiate the Stock class; that is, you should not be able to create an
object/instance of the Stock class.

Stock
# item: QString
# quantity: int
+ Stock()
+ Stock(i: QString, q: int)
+ getItem() : QString
+ getQuantity() : int
+ setItem(i: QString)
+ setQuantity(q: int)
+ toString() : QString

Confectionery ReadingMaterial

- weight: int - frequency: QString

+ Confectionery() + ReadingMaterial ()
+ Confectionery (i:QString, q: int, w: int) + ReadingMaterial (i:QString, q: int , f:QString)
+ getWeight() : int + getFrequency() : QString
+ setWeight(w: int) + setFrequency(f: QString)
+ toString() : QString + toString() : QString

When a user chooses to add an item from the menu, use the Factory Method design pattern to
return a pointer to either a Confectionery or ReadingMaterial object from the data entered
by the user. The factory method should take a QString as an argument indicating what type of
item is required, as well as the data used to construct the specific object. Note that the factory
method should have only one createStock() function; however, the objects that it has to
create, although they both have three arguments, are made up of different data types. Solve this
problem in the simplest possible way.

4
COS3711/Assignment 2/2023
You should then be able to do something similar to the following, although this is not entirely
correct as the two signatures of the createStock() function differ – they should be the same.

StockFactory sf;
Stock* c1 = sf.createStock("Confectionery", "Kit Kat", 12, 65);
Stock* rm1 = sf.createStock("ReadingMaterial", "The Star", 100,
"Daily");

When items are created, display these objects’ data on the GUI.

Implement a stock list based on a Singleton design pattern. The only instance of the stock list
should have two lists: one for confectionery, and one for reading material. There should only be
one addStock() function (which would need to check what is being added so that it knows which
list to add the item to – achieve this using QMetaObject).

The user must be able to select which list (confectionery or reading material) to display on the
GUI, and all items of that particular type held in the list should be displayed. This should be
implemented via a single function in the list.

5
COS3711/Assignment 2/2023

Question 3

Use QXMLStreamWriter to write the stock list implemented in Question 2 to an XML file. Use a
single file to write both the lists managed by the stock list.

The XML should be written in the following format.


<stockList>
<stockItem type="Confectionery">
<item>Kit Kat</item>
<quantity>12</quantity>
<weight>65</weight>
</stockItem>
<stockItem type="ReadingMaterial">
<item>The Star</item>
<quantity>100</quantity>
<frequency>Daily</frequency>
</stockItem>
</stockList>

3. PART B (For self-assessment; not to be submitted)

Question 4

Write an application that uses regular expressions to check for problems in a text file provided by
a user. The following functionality should be included.
 The user should be able to select the file to check using a standard file open dialog box
(from a file menu item).
 There should be some way of indicating that the file has been loaded.
 Problematic words should be displayed, giving the line number and the word number in
the line as well.
The following problematic words should be flagged (using regular expressions to identify such
words):
 Words with a number anywhere in the word
 Words with a capital letter in any position apart from at the start of the word.

6
COS3711/Assignment 2/2023
 Words that have any special characters (like #, *, /, @, ^, and so on) as part of the word,
unless it is at the start or end of a word. Note that a – is acceptable.

The screenshot below gives examples of words that should be flagged.

Question 5

Extend Question 3 to allow an XML file to be read in using DOM. Use the same file that was
output from Question 3 as the input to Question 5. You can assume that it is in the same place
as where the file was written and are not expected to get the user to select the file. You are also
not expected to check whether the stock items are already in the list and can append items read
from the XM L to what is currently in the list.

This program should parse the file and add all stock items read in to the Singleton stock list. You
can test that the data has been read in correctly by displaying both confectionery and reading
material lists to the GUI.

Question 6

Extend Question 5 by allowing the user to choose to backup the stock list at some point, and then
to restore it again later. Use the memento pattern to implement this functionality.

© Unisa
2023

You might also like