CS 202 Fall 2013 > In-Class Challenge for Tuesday, November 12, 2013 |
CS 202 Fall 2013
In-Class Challenge for Tuesday, November 12, 2013
Our Goal
We wish to write a program that keeps track of a
dataset in a vector
and applies various algorithmic modifications to it.
What to Do
- Write a program
algomod.cpp
that keeps track of avector<int>
of size 20. The program initializes the data to a collection of 20 random numbers, each in the range 0 .. 12, and then repeatedly does the following:- Print the dataset.
- Present the user with a menu of modifications to apply.
These must include:
- Re-initializing the data set to 20 values, each 0 .. 12.
- Randomly re-ordering the values in the dataset.
- Reversing the order of the values in the dataset.
- Sorting the dataset in increasing order.
- Setting every value in the dataset to 6.
- Calling Standard Library function
unique
, passing the results of thebegin
andend
member functions of thevector
. - Exit.
- Get the user’s choice. If the user chose to exit, then do so; otherwise, continue.
- Perform the requested operation.
Except for the re-inizialize option, each algorithmic modification must be performed using a single function call to a C++ Standard Library function.
Other Stuff
- You may wish to start with my program
domenu.cpp
. - You can generate a random number in the range 0 .. 12
using the following code.
[C++]
int n = rand() / (1.+double(RAND_MAX)) * 13.;
Function
rand
is declared in the standard header file<cstdlib>
.
CS 202 Fall 2013: In-Class Challenge for Tuesday, November 12, 2013 /
Updated: 12 Nov 2013 /
Glenn G. Chappell