CS 112 Project 6: Conga!

Objectives:

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

Introduction

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.

Details

To simulate the Conga Line, you are to use the files main.cpp, CongaLine.h, CongaLine.cpp, and your List template and ListTester class 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;
   //	}
and
   //	if ( !myLine.insertBefore(otherPersonsName, yourName) ) {
   //	    cout << "\n***" << otherPersonsName
   //	         << " is not dancing!\n" << endl;
   //	}
and
  //	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 implement them in a time-efficient manner. In particular, you should avoid approaches that use multiple passes through the List, such as (a) first finding the index of the other person (one pass) and then (b) inserting before/after that index (a second pass). Implement each of these methods using a single pass 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 item preceded by an "=" separator-string. (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.)

Misc

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.

Preparing to Submit

Create a script file in which you use ls to list all your project's files, use cat to display the contents of each file, and build+run your project to demonstrate that it works correctly. Make certain that your script file is located in your project folder.

Our grader will grade your submission based on the categories given in this grade sheet, so you should make certain all of those categories are covered.

Submit


CS > 112 > Projects > 06


This page maintained by Joel Adams.