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

COS3711 Assignment 1 (COMPLETE ANSWERS) 2025

Rating
-
Sold
2
Pages
22
Grade
A+
Uploaded on
25-03-2025
Written in
2024/2025

COS3711 Assignment 1 2025 ;100% TRUSTED workings with detailed Answers for A+ Grade. For assistance call or W.h.a.t.s.a.p.p us on +/ 2/ 5/ 4 /1 /1 /0/0 /3 /4 /3 /9 /9 .

Institution
Course










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

Written for

Institution
Course

Document information

Uploaded on
March 25, 2025
Number of pages
22
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

COS3711
ASSIGNMENT 1 2025

UNIQUE NO.
DUE DATE: 2025

,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.")

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.
EduScript Chamberlain College Of Nursing
Follow You need to be logged in order to follow users or courses
Sold
278
Member since
1 year
Number of followers
4
Documents
594
Last sold
1 month ago
EduScript

On this page, you find all documents, package deals, and flashcards offered by seller EduScript. Get Yourself 100 % TRUSTED workings, Expert Solved, Explanations and Solutions.

3.7

30 reviews

5
14
4
5
3
3
2
3
1
5

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