CMSC 160 -- Lab 5

Lab 5

Getting Started

Log into the computer science server and use wget and tar to download your starter code.
  1. Use wget to download the file at http://cs.longwood.edu/courses/cmsc160/f17/files/lab5.tgz
  2. Uncompress the lab5.tgz file by using tar -xvzf lab5.tgz
  3. Use ls to see that there is a new directory called lab5
  4. Use cd lab5 to change directory to the lab5 directory


Linux Commands

We can create new files and directories but sometimes we need to move or delete our files.
  • rm filename permanently removes (deletes) the file
  • cp oldname newname copies the file at oldname to a new file at newname.
  • mv oldname newname moves the file from oldname to the file newname. Note this does not copy, can overwrite files and removes the original file!
Each of these commands has additional options, you can find out more about linux commands by reading the man pages found using the man program. Try out man cp to see all of the options.

The Problem

We just learned about functions, so today we are going to write some functions which utilize loops and if statements. In this lab we will:
  1. write test cases using files
  2. use if statements
  3. use functions
  4. use loops
  5. use strings
You are to write the following functions. The functions are NOT listed in order of difficulty.

repeatString
input: a string str and an integer n
output: a string containing str repeated n times
example: "jd" 3 => "jdjdjd"
everyOther
input: a string str
output: a string containing every other character of str
example: "dymacek" => "dmck"
replaceChar:
intput: a string str
output: replaces each 'E' with 3
example: "DYMACEK" => "DYMAC3K"

Remember, you will be graded on style, syntax, functionality, test cases, and correctness.

Handin

When you are done you may hand in your lab by using make handin.

The lab is due at 11:59pm Sept. 26th 2017.