CS 202 Fall 2013  >  In-Class Challenge for Tuesday, November 5, 2013

CS 202 Fall 2013
In-Class Challenge for Tuesday, November 5, 2013

Our Goal

We wish to write a class template WaitInLine. This keeps track of a “line”, like the one for a cash register at a store. You enter the line at the back and exit at the front, so that people exit the line in the same order they entered.

An object of class WaitInLine<T> should keep track of a “line” of items of type T. I will refer to type T as the value type.

WaitInLine should have three public member functions.

In addition, WaitInLine should have a default constructor. However, there is a good chance that you do not need to write it.

Example usage:

[C++]

WaitInLine<int> w;

bool b1 = w.empty();                  // Should be true
w.put(8);
bool b2 = w.empty();                  // Should be false
cout << w.get() << endl;  // Prints 8
bool b3 = w.empty();                  // Should be true

w.put(6);
w.put(42);
w.put(-17);
cout << w.get() << endl;  // Prints 6
cout << w.get() << endl;  // Prints 42
w.put(3);
cout << w.get() << endl;  // Prints -17
cout << w.get() << endl;  // Prints 3

Class template WaitInLine should be implemented in header waitinline.h. Since this is a template, there is no associated source file.

What to Do

  1. Write class template WaitInLine, in file waitinline.h, as above. The resulting code should compile and pass all tests in test_waitinline.cpp.

Other Stuff


CS 202 Fall 2013: In-Class Challenge for Tuesday, November 5, 2013 / Updated: 5 Nov 2013 / Glenn G. Chappell