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

Exam (elaborations) COS3711 Assignment 1 (COMPLETE GUIDELINE) 2025

Rating
-
Sold
-
Pages
13
Grade
A+
Uploaded on
15-04-2025
Written in
2024/2025

Exam (elaborations) COS3711 Assignment 1 (COMPLETE GUIDELINE) 2025

Institution
Course









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

Connected book

Written for

Institution
Course

Document information

Uploaded on
April 15, 2025
Number of pages
13
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

COS3711 Assignment 1 (COMPLETE GUIDELINE) 2025 Course

· Advanced Programming (COS3711)

Question 1 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.
Downloaded by Polar magnats () lOMoARcPSD| COS3711/Assignment 1/2025 3
See the screenshot below for an example of the output for the arguments
that were used above.

C++ console application that implements the requirements of your assignment
step-by-step, with support for multiple files and flags using regular expressions.

✅ Features Implemented: Parses flags (-a, -b, -c, -d)

Supports multiple files

Applies regex to:

, Remove punctuation

Split text into words

Counts according to:

-a: Words >4 letters starting with a capital

-b: Hyphenated words (not starting or ending with -)

-c: Words that start and end with the same letter

-d: Words that do not start with a vowel

If no flags provided → all checks performed

If no arguments → usage instructions

📌 Full Code (C++): cpp Copy Edit #include #include #include #include #include
#include

using namespace std;

// Helper function to read file content into a string string readFile(const string&
filename) { ifstream file(filename); if (!file) { cerr << "Error opening file: " <<
filename << endl; return ""; } return string((istreambuf_iterator(file)),
istreambuf_iterator()); }

// Function to clean punctuation using regex string cleanText(const string& text)
{ // Remove punctuation and trim whitespace string cleaned = regex_replace(text,
regex(R"([.,?!:;])"), ""); cleaned = regex_replace(cleaned, regex(R"(^\s+|\s+$)"), "");
return cleaned; }

// Function to split text into words (assumes one space between words) vector
splitWords(const string& text) { vector words; regex wordRegex(R"(\s+)");
sregex_token_iterator it(text.begin(), text.end(), wordRegex, -1);
sregex_token_iterator end; for (; it != end; ++it) { if (!it->str().empty())
words.push_back(it->str()); } return words; }

// Count functions bool isCapitalLongWord(const string& word) { return
word.length() > 4 && isupper(word[0]); }

bool isHyphenatedWord(const string& word) { return word.find('-') != string::npos
&& word[0] != '-' && word.back() != '-'; }

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.
ivymwendwa47820 University of South Africa (Unisa)
Follow You need to be logged in order to follow users or courses
Sold
357
Member since
1 year
Number of followers
156
Documents
883
Last sold
1 month ago

3.6

71 reviews

5
29
4
13
3
13
2
5
1
11

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