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.
- 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.)
- 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.
- 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.
- Now alter the words program to just print the count of words in the input
(followed by a newline).
- Write a program using getline from the lectures
to count the number of lines in the input.
- Make a copy of that program,
and modify the copy to print out the longest line of the input.
- 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.