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, test your tar file, and check
in homework, before homework #1. This assignment is not
optional.
                
Description                
You will write a program called hw0
(not 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 $
”).
Ignore the indentation.
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 main.cc
#include <iostream>
using namespace std;
int main() {
// How many CU students does it take to change a light bulb?
cout << "Three—one to hold the light bulb and two to debate\n"
"whether or not an LED or a CFL bulb harms the environment more!\n";
return 0;
}
% cat CMakeLists.txt
cmake_minimum_required(VERSION 3.11)
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 *.cc CMakeLists.txt)
% cmake . && make
… cmake output appears here …
… make output appears here …
% ./hw0
Three—one to hold the light bulb and two to debate
whether or not 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!
If it doesn’t you won’t get any points—none.
                
Seriously: if your code works perfectly when you build it, but
the hw0.tar
file you turn in fails to unpack or fails to build,
then you will not receive any points. We will not allow you a second
try after the due date. Even if it’s just a tiny thing that you forgot.
Even if it’s just one line that you changed but didn’t need testing.
Even if it’s totally not your fault. Even if you worked really hard on
the homework.
                
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.
If two students have byte-for-byte identical CMakeLists.txt
files,
that’s just fine with me.
                
Debugging                
If you encounter “STACK FRAME LINK OVERFLOW”, then try this:
export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a
Requirements                
- You may not use any external programs. You many not use
system(), fork(), popen(), execl(), execvp(), etc.
- You may not use C-style I/O facilities:
printf(), puts(), putc(), etc.
- You may not use dynamic memory via new, delete,
malloc(), calloc(), realloc(), free(), strdup(), etc.
- It’s ok to implicitly use dynamic memory via containers
such as string or vector.
- No global variables.
- Except for an optional single global string called
program_name
containing argv[0]
.
- Your output must go to standard output, not standard error.
- The output must end with a newline.
- Newlines do not separate lines—newlines terminate lines.
That means that the last line ends with a newline, as all lines do.
- We will compile your program like this:
cmake . && make
- If that generates warnings, you will lose a point.
- OK, just half a point, since this is a one-point assignment.
- If that generates errors, you will lose all points.
- cmake errors & warnings count, too.
- There is no automated testing/pre-grading/re-grading.
- Test your code yourself. It’s your job.
- Yes, even if you only change it a little bit.
- Yes, even if all you do is add a comment.
- Test with the CSU compilers, not just your laptop’s compiler.
- You will not be graded on the quality of your humor.
- However, if you duplicate my example joke, you will lose points.
- Plagiarism is bad.
- You can’t copy, even if you do give credit—I require original work.
- Turn in a tar file called
hw0.tar
containing
CMakeLists.txt
and a single C++ source file, main.cc
.
- Yes,
.cc
, not .cp
, .cxx
, .cpp
, .CPP
, .c++
,
or .C
.
- Your
CMakeLists.txt
must use at least -Wall
every time g++ runs.
How to submit your work:                
In Canvas, check in the
file
hw0.tar
to the assignment “HW0”.
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.