CS-240
Lab 2

Purpose: Familiarize the student with the concepts of constructors, copy constructors, destructors and overloading operators.
Method:

Using the Bag class gone over in class:

  1. add two constructors; one that will be the default constructor that will always instantiate the bag with room for 10 items, and a second constructor that will take an integer (i) input and will instantiate the bag with room for i items. Remember that the insert and remove methods can affect the size of the array in that if insert causes the array to fill up then it should insure that it never fills up (by increasing the size of the dynamic array); likewise after a remove check if the dynamic array is less than half full then reallocate it as half the current size.
  2. add a copy constructor to the class
  3. add an overloaded assignment (=) operator to the class
  4. add an overloaded plus (+) operator that will allow the contents of one bag to be added to another bag ( this should leave one bag empty and the other bag with all of the items).
  5. add a destructor to the class that will return any dynamically allocated storage to the C++ run-time storage management system.
  6. compile Bag.cpp and get rid of any editing induced errors
  7. create a new file called main1.cpp and write a short test program that tests the two constructors and the modified insert and remove methods (print out proof that they work).
  8. compile main1.cpp, get rid of any compile errors and run
  9. create a new file called main2.cpp and write a short test program that tests the the copy constructor (print out evidence (on the console) that the copy constructor works properly).
  10. compile main2.cpp, get rid of any compile errors and run
  11. create a new file called main3.cpp and write a short test program that tests the overloaded assignment (=) operator (print out evidence (on the console) that the overloaded = works.
  12. compile main3.cpp, get rid of any compile errors and run.
  13. create a new file called main4.cpp and write a short test program that tests the overloaded plus (+) operator( print out evidence (on the console) that the overloaded + works.
  14. compile main4.cpp, get rid of any compile errors and run.
  15. create a new file called main5.cpp and write a short test program that tests the the class destructor (print out evidence (on the console) that the copy constructor works properly).
  16. compile main5.cpp, get rid of any compile errors and run


Last updated 02/03/2006 - RVS