• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 3 fuera de 21 páginas
Examen

COS3711 Assignment 1 2025

Document preview thumbnail
Vista previa 3 fuera de 21 páginas

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

Vista previa del contenido

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

Información del documento

Subido en
9 de abril de 2025
Número de páginas
21
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas
$2.60

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
StudyAidPro
3.9
(23)
Vendido
194
Seguidores
2
Artículos
560
Última venta
6 meses hace



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes