IC210 AY15 Final Practicum Exam

How to submit a solution

You will be using the submit script to submit your practicum solutions.
  1. If you don't already have the submit script, you will need to install the submit script before submitting anything. This only needs to be done once, however.
    pushd ~/; mkdir bin ; pushd ~/bin;rm -f submit;wget http://zee.cs.usna.edu/~kenney/sw/submit;chmod +x submit;popd;popd
  2. To submit your first solution give the command:
    ~/bin/submit p1final p1pfin.cpp
  3. To submit your second solution give the command:
    ~/bin/submit p2final p2pfin.cpp
  4. To submit your third solution give the command:
    ~/bin/submit p3final p3pfin.cpp

Problem 1

Name your source code file p1pfin.cpp. Read in a file of street addresses, where the file name is entered by the user. The first line tells you the number of street addresses in the file, each subseuquent line is a single address of the form:
207 Oak
You may assume each address looks like "number name" where the number is strictly a number, no letters, and the name has no spaces. Your program must print the addresses out alphabetically by street name, where addresses on the same street are ordered in increasing number.

Test Input Files: p1in1.txt, p1in2.txt, p1in3.txt.

p1in1.txt Sample Run
7              
111 Tanner
210 Oak
5 Ontario
110 Tanner
23 Ontario
207 Oak
101 Ontario
~/$ ./p1pfin
File: p1in1.txt    
207 Oak
210 Oak
5 Ontario
23 Ontario
101 Ontario
110 Tanner
111 Tanner

Problem 2

Name your source code file p2pfin.cpp. Your program should read in a file of name/points-value pairs. (Note: The first line of the file tells you how many name/points-value pairs will be in the file.) Then read in commands from the user that are of the following form:
  give 4 to Brown     ← update the points-value associated with "Brown" by giving 4 more points

  take 6 from Jones   ← update the points-value associated with "Jones" by deducting 6 points

  quit                ← quit the program, of course!
The response to a give or take command should ether be "Name not found!" if that name didn't appear in the file, or the new total points for that person (i.e. total after the giving or taking of points.

Test Input Files: p2in1.txt, p2in2.txt.

p2in1.txtSample Run
N = 3 
Brown 2      
Jones 0
Smith 5
~/$ ./p2pfin
File: p2in1.txt
> give 3 to Jones
3
> give 6 to Smith
11
> take 2 from Jones
1
> take 5 from Brown
-3
> give 7 to Jones
8
> quit

Problem 3

Name your source code file p3pfin.cpp. In the following, all distances are integers. Read in a sequence of "moves" of the form Direction followed by Distance, like L4 (left four) or R12 (right four), terminated by a Q. Then the program reads a start-point and an avoid-point, like this:
start 42 avoid 23
Note that these are to be taken as coordinates on the number line. The program must determine whether or not following the given moves from the given start point successfully avoids landing on the avoid point, meaning that after each move, the point you are at is not the avoid point. Output should be success or failure, where failure means you landed on the avoid point after some move, and success means that after no move were you on the avoid point. Note: You may not make any assumptions about how many moves there will be!
~/$ ./p3p3
L2 L3 R6 R3 R5 L6 L4 Q
start 3 avoid 7
failure
Note: points visited are: 3 → 1 → -2 → 4 → 7 → 12 → 6 → 2
~/$ ./p3p3
L2 L3 R6 R3 R5 L6 L4 Q
start 3 avoid 5
success
~/$ ./p3p3
R7 R8 L2 R11 L9 R3 L11 L6 R5 R13 R9 L6 R11 R9 R8 L10 R10 R8 L9 L8 Q
start 10 avoid 20
success
~/$ ./p3p3
R7 R8 L2 R11 L9 R3 L11 L6 R5 R13 R9 L6 R11 R9 R8 L10 R10 R8 L9 L8 Q
start 10 avoid 28
failure