CS253: Software Development with C++

Spring 2022

HW 3

CS253 HW3: Arguments, reading from files                

CS253 HW3: More Censorship                

Changes                

Updates to the assignment will be noted here. None yet!                 

Description                

For this assignment, you will write a C++ program called hw3 that improve on your HW1 work. Instead of always just censoring those Greek letter words, it will censor a given list of words. In addition, it will read from given files, or standard input if no files are given.                 

Arguments                

The arguments to hw3 must be, in this order:

Words                

Only replace a complete word. We define a word as a sequence of letters, a…zA…Z, delimited (bordered) by non-letters, or the start/end of the line. If we’re censoring the word “foo”, then input such as “fooYMP” must not be changed, but “foo3145727” must be.                 

This is the Colorado State University CS253 web page https://www.cs.colostate.edu/~cs253/Spring22/HW3 fetched by unknown <unknown> with Linux UID 65535 at 2024-06-18T06:41:50 from IP address 3.135.206.96. Registered CSU students are permitted to copy this web page for personal use, but it is forbidden to repost the information from this web page to the internet. Doing so is a violation of the rules in the CS253 syllabus, will be considered cheating, and will get you an F in CS253.

Sample Run                

Here is a sample run, where % is my prompt.                 

% cat CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
project(hw3)

# Are we in the wrong directory?
if (CMAKE_SOURCE_DIR MATCHES "[Hh][Ww]([0-9])$"
   AND NOT PROJECT_NAME MATCHES "${CMAKE_MATCH_1}$")
    message(FATAL_ERROR "Building ${PROJECT_NAME} in ${CMAKE_SOURCE_DIR}")
endif()

# Using -Wall is required:
add_compile_options(-Wall)

# These compile flags are highly recommended, but not required:
add_compile_options(-Wextra -Wpedantic)

# Optional super-strict mode:
add_compile_options(-fmessage-length=80 -fno-diagnostics-show-option
    -fstack-protector-all -g -O3 -std=c++17 -Walloc-zero -Walloca
    -Wconversion -Wctor-dtor-privacy -Wduplicated-cond
    -Wduplicated-branches -Werror -Wextra-semi -Wfatal-errors
    -Winit-self -Wlogical-op -Wold-style-cast -Wshadow
    -Wunused-const-variable=1 -Wzero-as-null-pointer-constant)

# add_compile_options must be BEFORE add_executable.

# Create the executable from the source file main.cc:
add_executable(${PROJECT_NAME} main.cc)

# Create a tar file every time:
add_custom_target(${PROJECT_NAME}.tar ALL COMMAND
    tar -cf ${PROJECT_NAME}.tar *.cc CMakeLists.txt)
% cmake . && make
… cmake output appears here …
… make output appears here …
% cat poem
Roses are red
Violets are 177777
This poem is too short
% ./hw3 - poem
Roses are red
Violets are 177777
This poem is too short
% ./hw3 Violets foo short - poem /etc/hostname
Roses are red
CENSORED are 177777
This poem is too CENSORED
greybull
% echo 'if (a*a+b*b == c*c) {' | ./hw3 a c -
if (CENSORED*CENSORED+b*b == CENSORED*CENSORED) {
% echo "Ignore this" | ./hw3 hello - /dev/null

Standard Input                

If run without any filename arguments or redirection via < or |, then what should hw3 do? It should read from standard input. In this case, since standard input has not been changed with < or |, standard input remains connected to the keyboard. The program will appear to stop, but it is simply reading from the keyboard.                 

When that happens, the user has two options:

Debugging                

If you encounter “STACK FRAME LINK OVERFLOW”, then try this:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements                

If you have any questions about the requirements, ask. In the real world, your programming tasks will almost always be vague and incompletely specified. Same here.                 

Tar file                

    cmake . && make

Remember how HW0 went on & on about testing your tar file? It applies here, too, and also to all other assignments.                 

How to submit your work:                

In Canvas, check in the file hw3.tar to the assignment “HW3”. It’s due 11:59ᴘᴍ MT Saturday, with a five-day late period.                 

How to receive negative points:                

Turn in someone else’s work.