100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

COS3711 Assignment 2 2023

Rating
1,7
(3)
Sold
19
Pages
20
Grade
A+
Uploaded on
07-07-2023
Written in
2022/2023

COS assignment 2 solutions with source code and link to the zipped file. Use the document as a reference do not submit it as it is. All the code is running with no errors. 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.

Show more Read less










Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
July 7, 2023
File latest updated on
July 10, 2023
Number of pages
20
Written in
2022/2023
Type
Exam (elaborations)
Contains
Questions & answers

Content preview

For Assistance with other modules
Call or Whatsapp +27682021794
www.myassignments.co.za




COS3711
Assignment 02
2023

Due date
20 July 2023 ,
11:00 PM
Unique Number:732808


There is a link to download the zipped file at the end of the
document.Please DO NOT submit that zipped file as it is, use
it as reference to correct your code and see what needs to be
done. All programs are running correctly with the instruction
on the questions, no errors when building the code, check the
images.

,QUESTION 1
// COUNT.H
#ifndef COUNT_H
#define COUNT_H

#include <QStringList>

class Count
{
public:
Count();
Count(QStringList args);
QString doCount();
private:
bool aFlag, bFlag, cFlag, dFlag;
QStringList filenames;
QString processFile(QString f);
QString process(char flag, QString contents);
};

#endif // COUNT_H


// COUNT.CPP
#include "count.h"
#include <QRegularExpression>
#include <QFile>
#include <QTextStream>

Count::Count()
{
aFlag = false;
bFlag = false;
cFlag = false;
dFlag = false;
}

Count::Count(QStringList args)
{
aFlag = false;
bFlag = false;
cFlag = false;
dFlag = false;

foreach (QString s, args)
{
if (s.at(0) == '-')
{
s.remove(0, 1); //remove -
while (s.length()>0)
{
switch (s.at(0).toLatin1())
{
case 'a': aFlag = true; break;
case 'b': bFlag = true; break;
case 'c': cFlag = true; break;
case 'd': dFlag = true;
}
s.remove(0, 1);
}

, }
else
filenames.append(s);
}

if (!aFlag && !bFlag && !cFlag && !dFlag) // no flags passed
{
aFlag = true;
bFlag = true;
cFlag = true;
dFlag = true;
}
}

QString Count::doCount()
{
QString result;
if (filenames.size() > 0)
{
foreach (QString filename, filenames)
{
result.append(processFile(filename));
result.append("\n");
}
}
else
result = QString("No files to process");
return result;
}

QString Count::processFile(QString f)
{
QString result;

QFile file(f);
if (!file.open(QIODevice::ReadOnly))
{
result = QString("%1 did not open sucessfully").arg(f);
}
else
{
QTextStream in(&file);
QString contents = in.readAll();
file.close();

result.append(QString("***" + f + "***\n"));
QString str = contents.trimmed();
QRegExp rem("[.,?!;:]");
str.remove(rem);

if (aFlag) result.append(process('a', str));
if (bFlag) result.append(process('b', str));
if (cFlag) result.append(process('c', str));
if (dFlag) result.append(process('d', str));
}

return result;
}

QString Count::process(char flag, QString contents)
{
R200,00
Get access to the full document:
Purchased by 19 students

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Reviews from verified buyers

Showing all 3 reviews
2 year ago

Q2 GUI different from assignment.

2 year ago

Buggy Code !!

2 year ago

the CMAKE links dont actually contain CMAKE code but just identical code to the QMake link. This code is very outdated and now wrong, cos3711 has not used QRegExp for several years and qt6 (which is what cos3711 has used for 3 years) no longer supports it, this is definetly not a 2023 assignment but just an older assignment. Very unsatisfied.

2 year ago

Good day, CMake link has been updated. The code is not wrong just using Qt5 that's why at the end of the document it clearly states that it's for educational purposes. The other link is now showing the CMake file sorry about that. Please next time at least notify us on our contact details if you have any other issues with the link.

2 year ago

I did try to phone first and it went straight to voicemail :/ thank you for fixing it though.

1,7

3 reviews

5
0
4
0
3
1
2
0
1
2
Trustworthy reviews on Stuvia

All reviews are made by real Stuvia users after verified purchases.

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.
MyAssignments My Assignments
View profile
Follow You need to be logged in order to follow users or courses
Sold
171
Member since
4 year
Number of followers
144
Documents
38
Last sold
4 months ago
My Assignments

3,8

21 reviews

5
11
4
3
3
2
2
1
1
4

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 exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card or EFT 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