IC210 AY15 6-Week Practicum Exam

How to submit a solution

You will be using the submit script to submit your practicum solutions.
  1. 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 p1p6wk p1p6wk.cpp
  3. To submit your second solution give the command:
    ~/bin/submit p2p6wk p2p6wk.cpp
  4. To submit your third solution give the command:
    ~/bin/submit p3p6wk p3p6wk.cpp

Problem 1

Write a program with source file named p1p6wk.cpp that reads in a line containing a price (with leading $), followed by a one-word decriptor (e.g. drink, food, paper ...), followed by another descriptor that is ether "regular" or "sale" and, if the descriptor is "sale", a percent value for the discount, and prints out a final price (with leading $) according to the following rules:
  1. sales tax is 7% of the final cost (i.e. after discounts) of an item
  2. an item marked "sale" gets discounted from the original price by the percentage given
  3. food items are not assessed sales tax
~/$ ./prob1
$45.99 clothing sale 10%
~/$ ./prob1
$45.99 food sale 10%
~/$ ./prob1
$45.99 food regular
~/$ ./prob1
$14.55 electronics sale 20.5%

Problem 2

Write a program with source file named p2p6wk.cpp that reads in input (with no whitespace) that contains the formatting codes described below, and outputs the same text, but with the formatting codes applied. Here are some examples:
~/$ ./prob2
hi and bye.
happy but not sad.
~/$ ./prob2
I think that I
   shall never see
A poem lovely
   as a tree.
As you may have guessed, \s means a space character, \n means a newline, and \e means you've come to the end of the input, i.e. you're done.

Problem 3

Write a program with source file named p3p6wk.cpp that reads in a file with a grid filled with X's and Y's and prints out the number of rows containing at least one Y. The name of the file will be input by the user, but you may assume the user only enters good filenames (i.e. names of files that exist and are of the right format). The first line of the file contains the number of rows followed by an x followed by the number of columns. For example, for input
your program should run like this
~/$ ./prob3
because the grid has two rows with at least one Y.
Example input files: p3in1.txt, p3in2.txt, p3in3.txt Sample runs:
~/$ ./prob3
~/$ ./prob3
~/$ ./prob3