Note
You can do this lab using the graphic environment (Konqueror+Kwrite)
or in a terminal using vi as you wish. You can write a Makefile
if you feel it will save you time in the lab.
Set up
Login. Change directory to cs201.
Make a new directory lab05 and
change directory to it.
Perform all the exercises in this lab under this directory.
Step 1 -- download and test selection sort using array
[ selsort.cpp ]
Step 2 -- Replace the array by a vector
Hint. Look up the syntax in the book.
Make sure your new version works...
Step 3 -- remove the restriction of 100 numbers
Hint: start with an empty vector and push data into it:
while( ..... && cin >> number )
{ .... f.pushback(number); ....
}
Make sure your new version works...
Step 4 -- replace n by f.size()
Vectors know their size -- so instead of using a variable n
you can use f.size(). Make this work and then remove the
declaration of n.... and make the program work again.
Step 5 -- Strings 101
Here is a program that uses the C++ string library -- except I've
added some mistakes. Download
[ strings101.cpp ]
and use the editor and compiler to make it work the way
it should work.
Hint: the compiler gives truly obscure error messages with string operations. (1) Don't Panic. (2) Fix the first one before you do the next one. (3) when in doubt check to book.
A Challenge if you have plenty of time
Take the selsort.cpp program and change it
so it sorts a vector of strings.
. . . . . . . . . ( end of section CSci201 Laboratory 05 -- Vectors) <<Contents | End>>
Abreviations