Exercise Sheet 1

IN3013/INM173 - Object-Oriented Programming in C++

The practical work for this course will be done on the University's Unix systems. We'll be using the GNU C++ compiler (g++) and a text editor. One possibility is nedit, which does syntax highlighting for various languages, including C++ and Java.

  1. Create a new directory for this week's exercises. In that directory, create a text file hello.cc containing the ``hello world'' program from the lecture. (Our C++ source files will always end in ``.cc''; other systems use different conventions.)

  2. Compile the program with the command
        make hello
    
    This will create an executable file called hello, which you can run by typing
        ./hello
    

    If you make any changes, you'll need to type ``make hello'' again before running the new version.

  3. Do the same with the words program, calling it words.cc. To run it reading input from a file, say
        ./words <file
    
    where file is some text file; words.cc itself will do.

  4. Now alter the words program to just print the count of words in the input (followed by a newline).

  5. Write a program using getline from the lectures to count the number of lines in the input.

  6. Make a copy of that program, and modify the copy to print out the longest line of the input.

  7. Make a copy of that program, and modify the copy to store the lines of the input in a vector, and then print them out in reverse order.