CISC220 F2014 Lab1

From class_wiki
Jump to: navigation, search

Lab #1

1. Getting started (2 points)

  • Get your Unix programming environment figured out following the set-up instructions on the course home page
  • Download the class programs cplusplus_1.tar to the computer you are working on and untar it (if it's unfamiliar, Google "tar command" or try "man tar" in Unix).
  • Make a directory called <Your Name>_Lab1 and copy the wordbyword subdirectory from the cplusplus_1 directory into it (cp wordbyword/* <Your Name>_Lab1/).
  • Verify that you can compile wordbyword by typing "make" in that directory.
    • If this doesn't work, you probably need to set your path to g++, etc. On strauss, putting this .bashrc and .profile in your home directory and re-logging in should do it.
    • Your shell must be "bash" (test with echo $SHELL). Either type "bash" after logging in or change your default shell to bash here (after logging in, click "Change your UNIX Login Shell").
  • Run it: ./wordbyword test.txt. You should get a list of words in the file.

2. C++ programming exercises

  • (1 point) Make a piglatin directory and copy the wordbyword main.cpp and Makefile into it. Change the executable name in the Makefile to piglatin. In main.cpp, erase all of the wordbyword-specific code and write a function char *piglatin(char *s) which takes a word in the form of a null-terminated C-style string and returns a string with the "pig latin" form of that word according to a simplified version of these rules. In these rules, the first letter of the word is moved to the end if it is a consonant and "ay" is appended. For example, "happy" becomes "appyhay" and "duck" becomes "uckday". If the first letter of the word is a vowel, just add "way" to the end of it. So "egg" becomes "eggway" and "awesome" becomes "awesomeway". You should use dynamic memory allocation to create the new, longer version of the string which you return.
    • Make sure to add test code to your main() to actually create a set of test word strings (by allocating char *'s and filling them in with letters), call piglatin() on them, and print what it returns
  • (2 points) Modify wordbyword to replace any punctuation which is not an apostrophe with a space (using a temporary file) before outputting and counting words. This will allow phrases like "people...for" to be counted as two words rather than one. For help with working at the character level, refer to the mutatefile program in cplusplus_1. After making these changes, how many words are in getty.txt?


3. Submission

  • Put a PDF file <Your Name>_README.pdf in <Your Name>_Lab1 explaining what OS and text editor/IDE you are using. This file should also contain a copy of the output of your programs--for this assignment, how many words were in each file, example words and their pig latin versions, etc. Please also add a section, if necessary, noting if you had to make any changes to the above instructions to get things working for you.
  • Create a single tar/zip/rar file out of the top-level and all subdirectories. This archive file should be named <Your Last Name>_Lab1.tar (or .zip or .rar, etc.).
  • Submit it in Sakai by midnight at the end of Thursday, September 4