Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Other

COS3711 Assignment 1 solution 2025

Rating
-
Sold
2
Pages
12
Uploaded on
10-05-2025
Written in
2024/2025

COS3711 Assignment 1 solution 2025 Write a console application that can be run from the command line using the following forms: count // run without any parameters count // pass one file name count fileT // pass more than one file name count –a –b fileT // pass flags to change behaviour count –ab –c // 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. • 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. COS3711/Assignment 1/2025 3 See the screenshot below for an example of the output for the arguments that were used above. Question 2 Create a graphical user interface that allows a user to deposit or withdraw an amount. Display the current date on the interface. Below is an example of such an interface. Create a Transaction class that stores the date, time, amount, and type of transaction (deposit or withdrawal, implemented as an enum). Transactions should be handled as pointers. COS3711/Assignment 1/2025 4 Create a TransactionList class that keeps a single list of transactions. There should be only one instance of this list allowed, so implement it using the Singleton design pattern. When the user clicks the Deposit or Withdrawal button, the transaction should be written to the transaction list. Display the transaction in a console window as well (this is as a check that the transaction is actually being created. When the user clicks on the To file button, the list of transactions should be written to a human-readable text file. Ensure that your graphical user interface class handles only the interface, and does not contain code that is used to manage the transaction list; create a separate class for this purpose. Question 3 In this exercise, you will design a simple calculator with four basic operations, namely addition, subtraction, multiplication, and division. Implementation of this simple calculator should separate the code for user interface and mathematical operations. The code for performing mathematical operations should be designed using the following class hierarchy: COS3711/Assignment 1/2025 5 The Operation class hierarchy contains the logic for performing various mathematical operations. A concrete class in this hierarchy represents one mathematical operation, which is performed in its compute() function that returns the result of an operation. Implement the Factory method design pattern using one factory class named OperationFactory so that an instance of a class in the Operation class hierarchy can be created based on the requested operation (+, -, *, /). Additionally, OperationFactory should also be an implementation of Singleton. The user interface for the calculator should make use of five QPushbuttons, two QDoubleSpinBoxes and one QLCDNumber as shown below: QDoubleSpinBoxes allow user to enter numbers and QLCDNumber is for displaying the result of the calculation. To use the calculator, the user should first enter two numbers and then select one of the four (+, -, *, /) buttons. The result of the operation is displayed in QLCDNumber. The button clear is used to clear QDoubleSpinBoxes and QLCDNumber. Note the following: • The signals emitted by the four buttons (+, -, *, /) should be handled in a single slot. • The user interface code should make use of the Operation class hierarchy to get the result of the requested operation. • Handle overflow in QLCDNumber display appropriately. • Handle division by 0 appropriately.

Show more Read less
Institution
Course

Content preview

COS3711 ASSIGNMENT 1 2025
SOLUTION




NOTE: Change what you need to change and remember to submit what is specified in the
submission instructions.
THE LINK TO THE PROJECT IS IN THIS FILE.

,OUTPUTS FOR ALL QUESTIONS

QUESTION 1 output
BEFORE running anything, ensure that the file you want to analyze is in the same folder as your
executable, question1.exe. You can see where your executable is from here:

,Depending on where your project is, below is where my project is:




Output
Helper before setting the flags:




The instructions to set the flags are in your assignment questions. Play around with the
flags to see if it runs the way you want

After setting flags but can not open files:




After setting the flags and can open files:




This output is different from the one in the question because in the question they gave us
an example of how it can be, you can change to the one you want.

,QUESTION 2 OUTPUT:




You can follow the path to where the file was saved

,QUESTION 3 OUTPUT




SOURCE CODE:


Question 1
fileprocessor.h
#ifndef FILEPROCESSOR_H

, #define FILEPROCESSOR_H


#include <QString>
#include <QRegularExpression>


class FileProcessor {
public:
FileProcessor() = default;
QString readFile(const QString& fileName) const;
int countCapitalWords(const QString& text) const;
int countHyphenatedWords(const QString& text) const;
int countSameLetterWords(const QString& text) const;
int countNonVowelWords(const QString& text) const;
};


#endif // FILEPROCESSOR_H


fileprocessor.cpp
#include "fileprocessor.h"
#include <QFile>
#include <QTextStream>
#include <QDebug>


QString FileProcessor::readFile(const QString& fileName) const
{
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug().noquote() << QString("Error: Unable to open
'%1'").arg(fileName);
qDebug().noquote() << QString("MAKE sure txt file is where your
executable is. e.g
path\\to\\build\\Desktop_Qt_6_9_0_MinGW_64_bit-Debug\\question1.exe");


return QString();
}


QTextStream stream(&file);
QString content = stream.readAll();
file.close();
return content;

Written for

Institution
Course

Document information

Uploaded on
May 10, 2025
Number of pages
12
Written in
2024/2025
Type
OTHER
Person
Unknown

Subjects

$10.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
CrystalIndigo University of South Africa (Unisa)
Follow You need to be logged in order to follow users or courses
Sold
486
Member since
5 year
Number of followers
226
Documents
73
Last sold
5 months ago
CrystalIndigo Solutions

providing all solutions to all computer science modules

4.1

51 reviews

5
27
4
13
3
6
2
1
1
4

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions