CS 335-0 Homework

 

 

Homework #1. Due 9/17 beginning of class.

These exercises are to be completed (legibly) on paper.

  1. Write a recursive palindrome checker. ( see page 1142, #11 for more details). Your solution should clearly identify the base case(s) and the general case. You must provide a driver program segment to show how your function would be invoked.
  2. Consider the quicksort program on page 1134. For each data set below, show the contents of the array set at the end of the first two calls to the partition function.
    1. 10 28 37 15 24 27 13 87 33 52
    2. 1 21 2 22 3 33 4 44 5 55


Hw #2 Due 10/15 7:59 am
20 points
Due Thursday 10/15 7:59 am

  1. Copy the files:  IntArray.h, IntArray.cpp and hwia.cpp   from the class library to your main cs335-0 directory.
  2. Add a ‘capacity’ data member as discussed in class.
  3. Add the following function definitions and implementations to the .h and .cpp files.

    capacity()   ;   returns the capacity.

    pop_back() ;  removes the last element (No capacity change )
    push_back( int );   adds a new element to the end; capacity is increased if needed

  1. Add code to the driver program to demonstrate that your functions work.

When your code is working, create a photo file named:   hwia.photo  as follows:


$ photo hwia.photo
$ g++ hwia.cpp IntArray.cpp
$ a.out
$ cat IntArray.h
$ cat IntArray.cpp
$ cat hwia.cpp
<CTRL-D> 


Hw #3 Due 10/20 7:59 am
20 points

  1. Copy the files:  SimpleVector.h and hwSV.cpp   from the class library to your main cs335-0 directory.
  2. Add a ‘capacity’ data member as discussed in class.
  3. Add the following function definitions and implementations to the .h file.

    capacity()   ;   returns the capacity.

    pop_back() ;  removes the last element (No capacity change )
    push_back( T );   adds a new element to the end; capacity is increased if needed

    // T is the template type

  1. Add code to the driver program to demonstrate that your functions work.

When your code is working, create a photo file named:   hwSV.photo  as follows:


$ photo hwia.photo
$ g++ hwSV.cpp
$ a.out
$ cat SimpleVector.h
$ cat hwSV.cpp
<CTRL-D>