CS253: Software Development with C++

Fall 2020

HW 0

CS253 HW0: Light Bulb Joke

Changes

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

Purpose

This assignment ensures that you can follow instructions, login to a Linux system, compile a C++ program, and check in homework, before homework #1. This assignment is not optional.                 

Description

You will write a program called hw0. It will answer the question, “How many CU students does it take to change a light bulb?”                 

Where’s the GUI?

In this class, we build software using cmake and make. We turn in a tar file. You don’t really need to know much about any of those programs—we supply a file CMakeLists.txt that is the data file for cmake, which produces a a file Makefile, the data file for make. All that you need to do is type cmake . once, and make every time afterwards. make will compile your code (if it can) and create an hw0.tar file for you to turn in when you’re finished.                 

“Yeah, but where’s the GUI? How do I edit my code?” Edit it any way you want. Use of a GUI is not required in this class. If you know how to use one, feel free. I use vim. If you need help using a text editor, come to me for help.                 

Sample Build

In the following example, what you type looks like this. The percent sign, “%”, is my shell prompt (yours might be “hostname:directory$”). My CMakeLists.txt is shown as an example. You may copy it verbatim or create your own, as long as it meets the requirements below.                 

    % cat CMakeLists.txt
    cmake_minimum_required(VERSION 3.14)
    project(hw0)

    # Are we in the wrong directory?
    if(CMAKE_SOURCE_DIR MATCHES "[Hh][Ww]([0-9])$")
       if(PROJECT_NAME MATCHES "[^${CMAKE_MATCH_1}]$")
          message(FATAL_ERROR "Building ${PROJECT_NAME} in ${CMAKE_SOURCE_DIR}")
       endif()
    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:
    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 main.cc CMakeLists.txt)
    % cmake . && make
    … build output appears here …
    % ./hw0
    Three—one to hold the light bulb and two to debate
    whether an LED or a CFL bulb harms the environment more!

Testing

It is essential that you test what you’ve turned in (the hw0.tar file). Here’s an easy way, where % is my prompt:                 

    % rm -rf testdir
    % mkdir testdir
    % cd testdir
    % tar -xvf ../hw0.tar
    % rm -f hw0
    % cmake . && make
    % ./hw0
    % cd ..

That’s how the TA will test your program (though they will use a different directory name & location). This must work!                 

CMakeLists.txt

Programming assignments in this course use cmake. You will need to modify your CMakeLists.txt slightly for each assignment (at the very least, to change project(hw0) to project(hw1) for HW1). Unlike other aspects of your work, it is not possible to cheat concerning CMakeLists.txt. You may show your CMakeLists.txt to others, share it freely, post it to Teams, copy a different CMakeLists.txt from a message board, etc.                 

Debugging

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

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements

How to submit your work:

In Canvas, check in the file hw0.tar to the assignment “HW0”.                 

How to receive negative points:

Turn in someone else’s work.