CS202 -- Lab 0

The purpose of this lab is to give you practice using the grading scripts that you will use in your homeworks, and submitting labs on Canvas.

The intent is for you to finish it in lab; however, if you don't you have time to finish it in lab, then finish it on your own, and submit it on your own. The due date will be midnight on the day after lab.

After this in-class lab, you'll be doing topcoder in lab.


Video

Here's a video that talks about how I go about doing lab 0 and about using the gradescript.

The program that you should write: How much gold -- src/gold.cpp

This program reads a "map" on standard input. It's really a text file in the following format: For example, the following map in data/map1.txt contains a lot of dirt, but it also contains one rock with nothing under it, and three rocks with gold: one ounce (A), three ounces (C) and 26 ounces (Z).

...............
..-............
.........A.....
..Z.........C..

Your job is to write a program called src/gold.cpp, which reads a map on standard input and prints the total ounces of gold on the map.

There is an example executable in the lab directory, in bin/gold. Try it out:

UNIX> cd /home/jplank/cs202/Lab0
UNIX> bin/gold < data/map1.txt
30
UNIX> cat data/map2.txt
ABCDE.
.F----.
--...........G
UNIX> bin/gold < data/map2.txt
28
UNIX> 

Starting on your lab

You should make a fresh directory to work in. What I would do is create a directory for the class and then make subdirectories for each lab. Here's what you should do to start lab-0:
UNIX> cd                                     # Go to your home directory
UNIX> mkdir cs202                            # Make a directory for your class work
UNIX> chmod 0700 cs202                       # Protect the directory so others can't see it. 
UNIX> cd cs202                               # Enter the directory
UNIX> mkdir lab0                             # Make a directory for the lab
UNIX> cd lab0                                # Enter the directory
UNIX> mkdir src                              # Make a directory for code
UNIX> mkdir bin                              # Make a directory for executables
UNIX> cp ~jplank/cs202/Labx/Lab0/makefile .  # Copy the lab's makefile
UNIX> touch src/gold.cpp                     # Create the file src/gold.cpp
Implement your program in src/gold.cpp. You can compile with make. Let's say you try it right now without implementing anything. You'll get an error like the following:
UNIX> make
g++ -Wall -Wextra -std=c++11 -o bin/gold src/gold.cpp
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [bin/gold] Error 1
UNIX> 
Ok -- go ahead and implement src/gold.cpp. Suppose you're done. Now it should compile:
UNIX> make
g++ -Wall -Wextra -std=c++11 -o bin/gold src/gold.cpp
UNIX> 
Test it a little with some simple "maps" -- here are some I'd try:
UNIX> echo . | bin/gold
0
UNIX> echo - | bin/gold
0
UNIX> echo A | bin/gold
1
UNIX> echo Z | bin/gold
26
UNIX> echo AZ-..-A-...----.. | bin/gold
28
UNIX> ( echo ABC... ; echo .....Z )
ABC...
.....Z
UNIX> ( echo ABC... ; echo .....Z ) | bin/gold
32
UNIX> 
Those all look good to me. Time to test using the gradescript!

Testing and Grading for Correctness

There are two programs that you should use for testing and grading. The first is gradescript. You can call it from the lab directory, and you call it with a number between 1 and 100. This will execute your gold program. You need to have your gold executable in the current directory, and call the gradescript as follows:
UNIX> /home/jplank/cs202/Labs/Lab0/gradescript 1
Problem 001 is correct.

Test: ./bin/gold < /home/jplank/cs202/Labs/Lab0/Gradescript-Examples/001.txt
UNIX> 
The gradescript is saying that test #1 worked correctly. The test that it ran was:
UNIX> ./bin/gold < /home/jplank/cs202/Labs/Lab0/Gradescript-Examples/001.txt
1
UNIX> 
You can examine the input file with cat or more, or even vi:
UNIX> cat /home/jplank/cs202/Labs/Lab0/Gradescript-Examples/001.txt
A
UNIX> 
Let us suppose that you made a mistake writing bin/gold, and that instead it is a program that always prints "1":
UNIX> cat src/retone.cpp
#include <iostream>
using namespace std;

int main()
{
  cout << "1\n";
  return 0;
}
UNIX> g++ -o bin/gold src/retone.cpp
UNIX> 
When you run problem one on it, it works fine, because "1" is the proper output for the first problem. However, it fails on problem 2:
UNIX> /home/jplank/cs202/Labs/Lab0/gradescript 1
Problem 001 is correct.

Test: bin/gold < /home/jplank/cs202/Labs/Lab0/Gradescript-Examples/001.txt
UNIX> /home/jplank/cs202/Labs/Lab0/gradescript 2
Problem 002 is incorrect.

Your standard output does not match the correct one.

TEST:

bin/gold < /home/jplank/cs202/Labs/Lab0/Gradescript-Examples/002.txt

FILES:

Your standard output is in tmp-002-test-stdout.txt.
Your standard error  is in tmp-002-test-stderr.txt.

The correct standard output is in tmp-002-correct-stdout.txt.
The correct standard error  is in tmp-002-correct-stderr.txt.

Look at correct files and your files, perhaps run 'diff -y' on them, and figure out your mistake.
Please remember to delete this files when you are finished.
UNIX> 
You can examine your output and the proper output in the files listed:
UNIX> cat tmp-002-test-stdout.txt
1
UNIX> cat tmp-002-correct-stdout.txt
30
UNIX> cat /home/jplank/cs202/Labs/Lab0/Gradescript-Examples/002.txt
...............
..-............
.........A.....
..Z.........C..
UNIX> 
That way, you can try to find your errors. In most cases, your output must match mine exactly. That can be a challenge.

The script gradeall checks your programs in 100 test cases:

UNIX> /home/jplank/cs202/Labs/Lab0/gradeall    # This is with the correct bin/gold.
Problem 001 is correct.
Problem 002 is correct.
Problem 003 is correct.

...

Problem 099 is correct.
Problem 100 is correct.

100 Correct out of 100
UNIX> 
When you have written src/gold.cpp correctly, you may submit it. Go into Canvas and submit src/gold.cpp. Before you do this, the TA's will tell you what comments and header info you need to put into your program. For this one, you must put in the proper header information, but I don't care about commenting for the rest of the program -- it's too simple.