Data Structures - C++

Homework Assignments 2005

  1. You should know how to make a dynamicly allocated array. Study my example with int arrays thoroughly. Make sure you understand it. Discuss it with others in the class. (Don't worry if you don't understand the the functions printf and scanf, just know that they are basically like cout and cin.) Then write the same thing using the class box instead. Make a dynamically allocated array of boxes. The class box should look like this:
    class box{
    int height;
    int length;
    int width;
  2. Modify my program dynamic_array.cpp so that the user can assign his own values to the array. Also, allow that after he has created his array he can decide to make it bigger by any amount he wants. (He may do this any number of times so you will need an infite loop.) To do this, you will have to create a new array of the larger total size and then copy the values from the old array into the new and then let him put more values into the new array and finally, delete the old array. Remember to hold onto a pointer to the old array so that you can delete it when you are done copying its contents into the new array.
  3. Do the same as the above with a box class array instead of an int array. Also, add the method computeVolume to the box class.
  4. Create a Linked list of Boxes and provide the following functionality:
    addBox (int, int, int, box** Head)
    findBoxbyHeight(int H, box* Head) this function should go through the list and print out the h,l, and w of the first box it finds with the height specifiied. It should also print out the place in the list where the box is located.
    save this for last: deleteBoxbyHeight(int, box** Head) deletes a box from anywhere in the list if it has the specified height.
  5. Make a class Student with the following attributes: firstname, lastname, t.z.number, GPA, next. It should have the methods setGPA, and the overloaded operators > and < . Create the class StudentLL which is a linked list class containing the attribute head of type Box and an orderedAdd method which will add new students according in ascending order. Use the > and < operators to keep the list sorted.
  6. Create a LIFO class with push and pop functions. The push function should return 1 on success and -1 on failure. The pop function should return a pointer to a Student, or a pointer cast of -1 on failure. The class should have the attributes: Head, maxSize and currentSize. The LIFO should be composed of nodes which are Students. and the Student class constructor should take also a pointer to the next node he is supposed to point to.
  7. Create an array based FIFO. Make a fixed sized array of boxes. Write the push anD pop functions. Popping from an empty list should return the error code -1. Similarly, pushing to a full list should cause the same error. You must recycle the once freed spaces in the array so that if the max size is 10, you will be able to add 8 for example, then remove 4 and still be able to add 6 more boxes to the array . You will need to write a setBox method to set the values of the already created boxes.
  8. Write a binary tree class which has the addnode and deletenode functions. Also include a printTreeInOrder function which should print all the nodes of the tree in ascending order according to whatever greater than / less than evaluation you choose.
  9. Write a linked list of nodes which is capable of containing various classes. All the classes should inherit from one class ( say , Employee ) and the linked list should be implemented in terms of that parent class. Each child class should have its own version of a print function. The linked list class should have a printallnodes member function which should print all the nodes of the linked list. Be sure to use virtual functions so that pointers of type parent can be used to call child versions of the print function. Include a delete node and add node function in the linked list class.
  10. Write a quicksort function which can sort an array of integers.
  11. ( Make a student database . Have two classes , student and teacher. Allow a teacher to add students freely while the program is running. (program should be in an infinite loop) . Use dynamic memory allocation to keep the database the exact right size. Student class should have attributes: name, classestaking grades. Teacher has name, classesteaching and password. Student can register to courses and can check their grades and average. they cannot change their grades. Teachers can give themselves courses and can change (or give) grades to students whom they teach. They can also see the grades of their students. Make appropriate methods. )