• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Document preview thumbnail
Preview 3 out of 21 pages
Exam (elaborations)

COS3711 Assignment 1 2025

Document preview thumbnail
Preview 3 out of 21 pages

COS3711 Assignment 1 2025 .... 100% TRUSTED workings with detailed answers.

Content preview

lOMoARcPSD|21997160




Assignment 1

1. Introduction

Please note that Qt Designer should not be used, and you are expected to manually set up GUIs
to ensure that you properly handle memory using Qt’s parent-child functionality.

Marks will also be awarded for following good programming practice, for example, naming
conventions, code layout, using forward class declarations and initialiser lists in constructors, and
GUI handling like setting focus, tabbing and clearing input widgets (like text input fields being
cleared and spin boxes being returned to some default value), and providing appropriate user
feedback. Your code should build and run without any warnings.

2. 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.
• 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.

,Answer for Question 1 (COS3711 Assignment 1 - 2025)

Requirements Recap:

1. Command-line Usage:
o count → No arguments: Print usage instructions.
o count file1.txt → Process a single file.
o count file1.txt fileTwo.txt → Process multiple files.
o count –a –b file1.txt fileTwo.txt → Apply specific flags.
o count –ab –c file1.txt → Alternative flag syntax.
2. Flags and Their Functions:
o -a: Count words longer than 4 characters that start with a capital letter.
o -b: Count hyphenated words (not starting or ending with a hyphen).
o -c: Count words that start and end with the same character.
o -d: Count words that do not start with a vowel.
3. Text Processing:
o Remove whitespace at the start and end of the document.
o Remove punctuation (.,?!:; etc.) using regular expressions.
o Assume only one space between words.




Implementation Approach

1. Use Python or C++ (since Qt is mentioned, C++ with Qt might be preferred).
2. Process input files and extract words.
3. Apply regex-based counting for each flag condition.
4. Handle command-line arguments properly.

, Sample Python Implementation

python
import sys
import re

def process_file(filename, flags):
try:
with open(filename, 'r', encoding='utf-8') as file:
text = file.read().strip()

# Remove punctuation
text = re.sub(r'[.,?!:;]', '', text)

words = text.split()

results = {"-a": 0, "-b": 0, "-c": 0, "-d": 0}

for word in words:
# -a: Words longer than 4 chars starting with a capital letter
if "-a" in flags and len(word) > 4 and word[0].isupper():
results["-a"] += 1

# -b: Hyphenated words (not starting/ending with a hyphen)
if "-b" in flags and re.search(r'\b\w+-\w+\b', word):
results["-b"] += 1

# -c: Words that start and end with the same letter
if "-c" in flags and len(word) > 1 and word[0].lower() == word[-
1].lower():
results["-c"] += 1

# -d: Words not starting with a vowel
if "-d" in flags and not re.match(r'^[aeiouAEIOU]', word):
results["-d"] += 1

print(f"\nResults for {filename}:")
for key, value in results.items():
if key in flags:
print(f"{key}: {value}")

except FileNotFoundError:
print(f"Error: File '{filename}' not found.")

def main():
args = sys.argv[1:]

if not args:
print("Usage: count [-a -b -c -d] <file1> <file2> ...")
return

flags = {arg for arg in args if arg.startswith('-')}
files = [arg for arg in args if not arg.startswith('-')]

if not files:
print("Error: No files specified.")

Document information

Uploaded on
April 9, 2025
Number of pages
21
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$2.60

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

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.
StudyAidPro
3.9
(23)
Sold
194
Followers
2
Items
560
Last sold
6 months ago



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

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions