CS253: Software Development with C++

Fall 2021

HW 5

CS253 HW5: Options!                

Changes                

Updated CMakeLists.txt to add *.h to hw5.tar, because my solution has a *.h files. Yours may or may not.                 

Description                

For this assignment, you will improve upon your previous work in HW3, adding command-line options. This is a complete program, not a library.                 

Arguments                

The first command-line arguments should be options:                 

-r integer-integer
Specify the acceptable input range of numbers. If this option is not given, assume 0–99, as in HW1.
-f
-s
If -f is given, display the first line of output (the one with the ‘x’ characters). If -s is given, display the second line of output (the one without the ‘x’ characters). If neither -f nor -s is given, act as if both were given.
-c string
When writing the second line, use string instead of a comma.
-v
Announce each filename to standard output, just before reading the integers inside it. Before reading standard input, announce that.

This is the Colorado State University CS253 web page https://cs.colostate.edu/~cs253/Fall21/HW5 fetched by unknown <unknown> with Linux UID 65535 at 2024-11-21T18:20:11 from IP address 3.138.32.53. 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 Runs                

Here are sample runs, where % is my prompt.                 

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

# 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
    -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:
# No, you don’t have to have a separate CountSort.cc file.
# Whatever .cc files you have that need to be compiled must be listed here:
add_executable(${PROJECT_NAME} main.cc CountSort.cc)

# Create a tar file every time:
add_custom_target(${PROJECT_NAME}.tar ALL COMMAND
    tar -cf ${PROJECT_NAME}.tar *.cc *.h CMakeLists.txt)
% cmake . && make
… cmake output appears here …
Scanning dependencies of target hw5
… make output appears here …
% head data data2
==> data <==

101 103 109         

105        103 103         


==> data2 <==
    199 100 199     

% ./hw5 -r 100-109 <data
101x1 103x3 105x1 109x1
101,103,103,103,105,109
% ./hw5 -sc ' & ' -r 100-400 data data2
100 & 101 & 103 & 103 & 103 & 105 & 109 & 199 & 199
% ./hw5 -vfc/ -sr 100-200 <data data2 data2
Reading from data2
Reading from data2
100x2 199x4
100/100/199/199/199/199
% ./hw5 -fr1000000-1000999 ~cs253/pub/million
1000001x500000 1000987x500000

Debugging                

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

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Hints                

Requirements                

All requirements from HW3 still apply, with these additions:

Tar file                

    cmake . && make

How to submit your work:                

In Canvas, check in the file hw5.tar to the assignment “HW5”. It’s due 10:00:00ᴘᴍ MT Saturday, with a 24-hour late period for a 25% penalty.                 

How to receive negative points:                

Turn in someone else’s work.