IC210 AY15 12-Week 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 p1p12wk p1p12wk.cpp
  3. To submit your second solution give the command:
    ~/bin/submit p2p12wk p2p12wk.cpp
  4. To submit your third solution give the command:
    ~/bin/submit p3p12wk p3p12wk.cpp

Problem 1

Write a program with source file named p1p12wk.cpp that reads n points from standard input in the following format
N = n
(x1,y1) (x2,y2) ... (xn,yn)
and writes out the x-coordinates of all n points on one line, and the y-coordinates of all n points on the following line. The output must be formatted like this:
X := [x1, x2, ..., xn]
Y := [y1, y2, ..., yn]
Here are some example runs. Your program must read input and produce output with the exact same formatting!
~/$ ./p1p12wk
N = 4
(0.5,1) (0.6,1.5) (0.7,2) (0.8,2.5)
X := [0.5, 0.6, 0.7, 0.8]
Y := [1, 1.5, 2, 2.5]
~/$./p1p12wk
N = 1
(5,8)
X := [5]
Y := [8]
~/$./p1p12wk
N = 10
(11,51) (12,52) (13,53) (14,54) (15,55) (16,56) (17,57) (18,58) (19,59) (20,60)
X := [11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
Y := [51, 52, 53, 54, 55, 56, 57, 58, 59, 60]
Note: You may assume there is at least one point, i.e. you never get input like N = 0.

Problem 2

Write a program with source file named p2p12wk.cpp that reads from standard input a number n followed by n words. These n words are to be "redacted" from the input that follows. What follows is a sequence of words and punctuation (space-separated) that is terminated by the word END (in all caps, just like that). The program will read in each word and punctuation mark and write them to the screen, except that any word that occurrs in the redacted list will be written as the equivalent number of *'s, as if it were blacked out with a marker. Here are some example runs:
~/$ ./p2p12wk
2 foo d  
foo is just food without the d . END
*** is just food without the * . 
~/$ ./p2p12wk
5 swim swimming swims Michael Phelps
I love swimming . Nobody swims better than Michael Phelps , though . As much as I like to swim , I'll never do it as well as Phelps . END
I love ******** . Nobody ***** better than ******* ****** , though . As much as I like to **** , I'll never do it as well as ****** .

Problem 3

Write a program with source file named p3p12wk.cpp that reads the name of a file that contains a grid of characters using the format illustrated here:
3 x 5
HANDS
GLOVE
NAILS
... and then reads in commands from the user of the following forms: Example input files: p3in1.txt, p3in2.txt. Sample runs:
run 1p3in1.txtrun 2p3in2.txt
~/$ ./prob3
p3in1.txt
row 0
H A N D S 
col 0
H
G
N
row 2
N A I L S 
col 1
A
L
A
quit
3 x 5
HANDS
GLOVE
NAILS
~/$ ./prob3
p3in2.txt
row 3
A T T A C K W E 
col 4
O
E
E
C
T
A
R
quit
7 X 8
H E L L O O U T
T H E R E C A R
B E T T E R R U
A T T A C K W E
R E E L T A I L
A T R E A T R U
A S S E R T T V