CMSC 160 -- Lab 6

Lab 6

Getting Started



Linux Commands

There is a handy linux program called wget which takes a url (web address) and will download the file at that address.
  • wget address downloads the file at the address and saves it to the current directory
Use wget to download the file at http://cs.longwood.edu/courses/cmsc160/f17/files/lab6.tgz
Use tar -xvzf lab6.tgz to extract the code into a directory named lab6.

The Problem

Functions can help break a problem down into simpler components. 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 going to write a program which reads in two strings of text and removes every occurance of the second string from the first string. You must use two functions to solve this problem: beginsWith and removeFirst

input: two lines of text msg and word
output: the string msg with all occurences of word removed
example: "jboboo" "bo" => "jo"
example: "borkborkbork" "ork" => "bbb"
example: "bboboboo" "bo" => "bo"


beginsWith
input: a string str and a string toTest
output: a boolean value indicating if str starts with the string toTest
example: beginsWith("julian","jul") => true
example: beginsWith("borkbork","ork") => false
removeFirst
input: a string str and an integer n
output: a string containing all but the first n characters of str
example: removeFirst("julian",2) => "lian"
example: removeFirst("borkbork",4) => "bork"

Remember, you will be graded on style, syntax, functionality, test cases, and correctness. Your source files must have your name in comments to be graded.

Handin

When you are done you need to hand in your lab. You will to change to the directory which contains the directory you wish to hand in. We will use the make handin command.

The lab is due at 11:59pm Oct. 3rd 2017.