CS 112 Project 6: Conga!


  1. Practice building List operations.
  2. Practice using pointers.
  3. Practice test-driven development.


This week's project is a one person project to complete a program that simulates a Conga Line dance:

A conga line

See this trace of the program to get a sense of how the program should behave.


To simulate the Conga Line, you are to use the files main.cpp, CongaLine.h, CongaLine.cpp, and your List template from last week. The CongaLine class in CongaLine.h has a List member named myLine, in which it stores the names of the people currently in the dance line. Since a Conga Line needs to have at least two people, the CongaLine constructor has two string parameters to which we can pass two people's names, and our simulation uses this constructor to create an initial line containing "Ann" and "Bob".

Assuming your List template is correct, these files should build and run correctly as they are. However, some of the lines in the file CongaLine.cpp are "commented out", including:

   //	if ( !myLine.insertAfter(otherPersonsName, yourName) ) {
   //	    cout << "\n***" << otherPersonsName
   //	         << " is not dancing!\n" << endl;
   //	}
   //	if ( !myLine.insertBefore(otherPersonsName, yourName) ) {
   //	    cout << "\n***" << otherPersonsName
   //	         << " is not dancing!\n" << endl;
   //	}
  //	cout << "\n " << myLine << "\n\n";
Before you can "uncomment" these lines, you will need to implement the corresponding List operation in List.h. Aside from "uncommenting" these lines and "commenting out" the line that outputs myLine using writeTo(), you should not make any other changes to main.cpp, CongaLine.h, or CongaLine.cpp.

The insertBefore/After Methods

The semantics of the first two operations are as follows:

Each operation should work correctly regardless of the position of otherPersonsName within myLine. If otherPersonsName is present within myLine, your operation should return true; otherwise it should return false, so that CongaLine::run() can display an error message.

To receive full credit for these operations, you should make them as time-efficient as you can. For example, you should avoid approaches that use multiple passes through the List.

The Output operation

The semantics of the third operation are as follows:

    anyOstream << myLine << ...

This << operation should insert the items in myLine into the ostream that is its left operand, with each pair of items separated by an '=' character. (The lines in the = character represent a person's arms.)

This operation should return return a reference to its left operand, so that these operators can be chained. (Hint: This operation should use one of the writeTo() methods you implemented last week.)


You should use test-driven development to implement these operations. A part of your grade will be based on the thoroughness of your tests. Add these tests to your ListTester class from last week.

For the insert operations, I strongly encourage you to "design" your method by drawing a diagram of what you want to have happen to the structure in each case. Once you have a diagram to go by, you are more likely to write code that actually does the right thing. (Trial and error is not a good debugging technique.)

If you get to the point where you cannot figure out what is wrong, use the debugger! The debugger is the best way to debug problems with pointers!

And finally, here is a silly video, in case you need some inspiration.


CS > 112 > Projects > 06

This page maintained by Joel Adams.