[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci Dept] / [R J Botting] >> [CSci201] >> [Lab01] >> index
[Index] [Schedule] [Syllabi] [Glossary] [Labs] [Projects] [Resources] [Grading] [Search ]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]
Wed Jan 30 09:51:15 PST 2008

Contents


    CSci201 Laboratory 05 -- Vectors

      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.

      Get credit

      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

  1. Gnu::="Gnu's Not Unix", a long running open source project that supplies a very popular C++ compiler.
  2. TBA::="To Be Announced", something I have to do.
  3. TBD::="To Be Done", something you have to do.

End