SHARE
TWEET

Untitled

a guest Apr 18th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /***************************************************************
  2. Author:     Trisha Badlu
  3. Creation Date:  21 March 2017                            
  4. Due Date:   31 March 2017
  5. Assignment:     #3
  6. Filename:       testArray.cpp                                  
  7. Course:     CSC136 - 020                                    
  8. Professor Name: Dr. Spiegel  
  9. Purpose:    The purpose of this file is to test each of the
  10.         updates made in the Array class. This includes
  11.         setting and getting the elements in use,
  12.         printing only elements in use, adding a number
  13.         to an array that's already filled, sorting an
  14.                 array that's partially filled, and sorting a
  15.                 full array.
  16. ***************************************************************/
  17.  
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <fstream>
  21. #include <string>
  22. #include "Array.h"
  23.  
  24. using namespace std;
  25.  
  26. int main(){
  27.   Array List1(5);
  28.   //Add a value to the object
  29.   List1 += 12;
  30.   List1 += 2;
  31.   List1 += 30;
  32.   //Print eltsInUse
  33.   cout << "Test += overloaded function and setEltsInUse()" << endl
  34.   << "function\tList1\tUnsorted" << endl
  35.   << "Elements in use: " << List1.getEltsInUse()
  36.   << "\tCapacity: " << List1.getCapacity() << endl;
  37.   //Output unsorted array with in use elements
  38.   cout << List1 << endl;
  39.   List1 += 24;
  40.   List1 += 6;
  41.   //Add a value to full array
  42.   List1 += 9;
  43.   List1 += 16;
  44.   List1.sort();
  45.   //Print eltsInUse
  46.   cout <<  "Test sort function\tList1\tSorted" << endl << "Elements in use: "
  47.   << List1.getEltsInUse() << "\tCapacity: "
  48.   << List1.getCapacity() << endl;
  49.   //Output sorted array with in use elements
  50.   cout << List1 << endl;
  51.   //Test copy constructor
  52.   Array List2(List1);
  53.   cout << "Test copy constructor\tList2" << endl
  54.   << "Elements in use: " << List2.getEltsInUse()
  55.   << "\t Capacity: " << List2.getCapacity() << endl;
  56.   cout << List2 << endl;
  57.   //Create new object
  58.   Array List3(4);
  59.   //Add a value to array
  60.   List3 += 3;
  61.   List3 += 10;
  62.   List3 += 54;
  63.   List3 += 37;
  64.   List2.sort();
  65.   //Test operator!= overloaded function
  66.   if(List3 != List1){
  67.     cout << "Test != overloaded function" << endl;
  68.     cout << "List3" << endl
  69.     << "--------------------------------------------------------------" << endl
  70.     << List3 << "Is  not equal to:" << endl << "List1" << endl
  71.     << "--------------------------------------------------------------" << endl
  72.     << List1 << endl;
  73.   }
  74.  
  75.   cout << "Test = overloaded function" << endl;
  76.   cout << "List3\tBefore" << endl
  77.   << "--------------------------------------------------------------"<< endl
  78.   << List3 << endl;
  79.   //Test operator= overloaded function
  80.    List3 = List1;
  81.    
  82.    //Output newList
  83.   cout << "List3\tAfter" << endl
  84.   << "--------------------------------------------------------------"<< endl
  85.   << List3 << endl;
  86.  
  87.   //Test operator== overloaded function
  88.   if(List3 == List1){
  89.     cout << "Test == overloaded function" << endl;
  90.     cout << "List3" << endl
  91.     << "--------------------------------------------------------------" << endl
  92.     << List3 << "Is equal to:" << endl << "List1" << endl
  93.     << "--------------------------------------------------------------" << endl
  94.     << List1 << endl;
  95.   }
  96.  
  97.   //Test operator[] overloaded function
  98.   List1[3] = 10;
  99.   cout << "Test [] overloaded function (List1)" << endl
  100.   << "Elements in use: " << List1.getEltsInUse()
  101.   << "\tCapacity: " << List1.getCapacity()
  102.   << "\tIndex changed: 3" << endl
  103.   << List1 << endl;
  104.  
  105.   return(0);
  106. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top