Lab Assignment--Command-Line Linux and Parsing


Part 1-Linux/Unix Commands

Follow all of the steps:
  1. log onto Linux
  2. start a script in your home directory
  3. in your cs330 lab directory create three new directories named 'weather', 'assignment', and 'web'
  4. change the permissions of the directory 'web' to -rwx r-x r-x using the octal form of chmod
  5. change your working directory to weather
  6. without using a text editor create three files called 'today', 'tomorrow', and 'deer'
  7. check the permissions with ls -l
  8. change the permissions of 'deer' to -rwx r-- r--
  9. change the permissions of 'today' to -rw- r-- r--
  10. check the permissions with ls -l
  11. copy 'deer' to a file called 'good'
  12. create a directory named 'cars'
  13. move the file 'good' to the directory 'cars' and rename it 'today2'
  14. change working directory to 'cars'
  15. check permissions with ls -l
  16. move up one directory
  17. remove the directory 'cars' and its contents
  18. exit from the script

Part 2-Parsing Line Input

General Goal:

Create a C++ class and test program that:

Details:

For this, you might like to review how to separate your code into three files.

Create the implementation (oneline.cpp) and test program (main.cpp) for the following oneline.h file:

#include <string>
using namespace std;

class OneLine
{
   public:
      OneLine();
      ~OneLine();
      void breakLine();
      void printReverse();
      istream &readLine(istream& is);
      string returnLine();
   private:
      string oneLine;
      char **words;
      int wordCount;
      void resetLine();
};

The following provides a description of each of the functions implemented in oneline.cpp:

OneLine
  • initialize oneLine to empty string
  • initialize wordCount to 0
breakLine
  • create a temporary C String version of oneLine
  • use strtok to break the temporary line into words
  • allocate enough space to hold all of the words and store them in words
  • store a count of the number of words in wordCount
  • (this is meant as a general algorithm, you may have to fiddle a little to get this working. Hint: this may involve cycling through all the words with strtok twice)
printReverse
  • cycle through the words from wordCount-1 to 0
  • print each word as you are cycling
readLine
  • call resetLine to free up memory and reset oneLine and wordCount to empty string and zero respectively
  • read one line from is (in this case, a file stream) and store it in oneLine
  • return is
returnLine
  • return oneLine
resetLine
  • if allocation has occurred then free up the words
  • set oneLine to be an empty string
  • set wordCount to zero
~OneLine
  • if allocation has occurred then free up the words

The following provides the algorithm of main.cpp:

  1. create an ifstream for the file test.txt (please use this file for testing)
  2. create a OneLine object
  3. while you can still read from the file:
    1. call readLine
    2. call breakLine
    3. call printReverse
  4. close the file

For this assignment please use strdup whenever you need to allocate space and copy a string.

Output:

The following is a link to the output produced using test.txt:

Deliverables: