EE 360C - Programming Assignment #1


Due Date

This assignment is due in class on Monday, June 17.

Overview

This is a simple introductory assignment to get you started programming in basic C++. This assignment is really more like a C program than a C++ program, because you haven't yet had an opportunity to learn the more interesting features of C++. However, this assignment will give you a chance to experiment with writing some simple pointer manipulation code that handles a linked list. If you already know C, then this assignment should be an easy review exercise for you.

The Program Specification

The program is to read an arbitrary number of words or letters, one per line, from the standard input (terminal window or a file) and insert them into a linked list of nodes in lexicographic (alphabetic) order. The input is terminated by entering a Ctrl-D (end of file).

Once the input is terminated, all you need to do is iterate over the list and print out each word, one word per line. So, the output should just be the input words in alphabetic order. Simple. You should free all nodes in the list before terminating your program.

Documented, well structured, nicely formatted code is important. I suggest that you implement a number of simple, small functions to do things like read a word, create a new node, delete a node, etc. Don't forget that any data structures you define should be defined in a separate header (.h) file that is included by the implementation file(s).

Helpful Information

The C string library provides a string function for comparing two strings defined as type char* and terminated by '\0'. This function has the following C++ function declaration (usually found in string.h in the standard include path).
extern "C" int strcmp(const char* s1, const char* s2);
The strcmp function returns a integer value greater than zero if s1 is lexicographically greater than s2, zero is s1 and s2 are equal, and a value less than zero if s1 is lexicographically less than s2.

For example, the following code fragment shows you how strcmp works:



char *a, *b;
...
int x = strcmp(a, b);

if (x == 0)
    cout << "a equals b\n";
else
    if (x < 0)
        cout << "a less than b\n";
    else
        cout << "a greater than b\n";

Submission Information

I have written online ininstructions for submitting your assignment. For this assignment, you do not need to write a Makefile if you are using a Unix system, unless you already know how to do so.

In addition to a program listing, you should turn in a trace of a few test runs of the program using various data. Try the following data sets:

1. the
   small
   red
   fox
   jumped
   over
   the
   tall
   fence

2. Hello
   Is
   Anyone
   Out
   There

3. a
   b
   c
   .
   .
   .
   z

4. z
   y
   x
   .
   .
   .
   a