CS202 Lecture notes -- Programming Assignments In Lab
Video Accompaniment
I have made a video to accompany this lecture, which is in the following link:
https://youtu.be/3TKkOKhPCf8.
Introduction
In your labs, I will give you one to three problems to solve.
I used to rely on the web site topcoder.com to provide the problems and the programming
environment, but unfortunately time has been unkind to their software suite, and I don't do
it any more. I may have some dangling links to topcoder, though, so if I do, that is why.
When I give you a problem to solve in lab, I will give you a link to a web page. Often
that pages points to a Topcoder or Leetcode writeup of the problem, but will typically
be a section entitled "In Case Topcoder's Servers are Down" or
"In Case Leetcode's Servers are Down". In this section, I give you a precise definition of
the problem, so that you don't have to use the servers.
Skeleton.cpp and main.cpp
Next, I give you a "skeleton" program, named Skeleton.cpp or xxx.cpp, where
xxx is the name of the class that you are supposed to implement.
.
What happens next is one of two things:
- You can copy Skeleton.cpp to your machine just download it using your web browser,
compile and run it. It will allow you to read input for the problem and call the solution
method. However, the solution will not be implemented. Your job is to implement the solution.
An example of a problem writeup with this methodology is
https://web.eecs.utk.edu/~jplank/topcoder-writeups/Leetcode/Number-Of-Zero-Filled-Subarrays/index.html. Give it a try.
- You need to copy two files: xxx.cpp and main.cpp. You then compile
them both with:
UNIX> g++ main.cpp
main.cpp includes xxx.cpp, but it has the input/output processing. Often, it
has examples built-in. You can then edit xxx.cpp and solve the problem.
I've noted elsewhere and note here that this way of solving the problem (including a cpp
file in another cpp file) is quirky and not good programming practice, so please don't copy this
for other software projects. It's nice and useful here though...
As it turns out, the first workflow is a lot easier for you to use, but the second workflow
makes it easier to submit your solution to Topcoder or Leetcode. You should become familiar
with both workflows -- an example of the second is
https://web.eecs.utk.edu/~jplank/topcoder-writeups/2010/Cryptography/index.html.
Testing
If the servers are working, you can submit your solution to Topcoder or Leetcode and test them
there. That's fun, so you should do it, even if it is sometimes hard on your self-esteem.
However, if the servers are not working, then testing is frustrating, so I typically provide
a way to test. That typically means copying the shell script tests.sh, running it,
and then comparing your answers to a text file answers.txt.
I show examples of doing this with both workflows in the video above, so please take a look.