Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************
- Author: Trisha Badlu
- Creation Date: 21 March 2017
- Due Date: 31 March 2017
- Assignment: #3
- Filename: testArray.cpp
- Course: CSC136 - 020
- Professor Name: Dr. Spiegel
- Purpose: The purpose of this file is to test each of the
- updates made in the Array class. This includes
- setting and getting the elements in use,
- printing only elements in use, adding a number
- to an array that's already filled, sorting an
- array that's partially filled, and sorting a
- full array.
- ***************************************************************/
- #include <iostream>
- #include <iomanip>
- #include <fstream>
- #include <string>
- #include "Array.h"
- using namespace std;
- int main(){
- Array List1(5);
- //Add a value to the object
- List1 += 12;
- List1 += 2;
- List1 += 30;
- //Print eltsInUse
- cout << "Test += overloaded function and setEltsInUse()" << endl
- << "function\tList1\tUnsorted" << endl
- << "Elements in use: " << List1.getEltsInUse()
- << "\tCapacity: " << List1.getCapacity() << endl;
- //Output unsorted array with in use elements
- cout << List1 << endl;
- List1 += 24;
- List1 += 6;
- //Add a value to full array
- List1 += 9;
- List1 += 16;
- List1.sort();
- //Print eltsInUse
- cout << "Test sort function\tList1\tSorted" << endl << "Elements in use: "
- << List1.getEltsInUse() << "\tCapacity: "
- << List1.getCapacity() << endl;
- //Output sorted array with in use elements
- cout << List1 << endl;
- //Test copy constructor
- Array List2(List1);
- cout << "Test copy constructor\tList2" << endl
- << "Elements in use: " << List2.getEltsInUse()
- << "\t Capacity: " << List2.getCapacity() << endl;
- cout << List2 << endl;
- //Create new object
- Array List3(4);
- //Add a value to array
- List3 += 3;
- List3 += 10;
- List3 += 54;
- List3 += 37;
- List2.sort();
- //Test operator!= overloaded function
- if(List3 != List1){
- cout << "Test != overloaded function" << endl;
- cout << "List3" << endl
- << "--------------------------------------------------------------" << endl
- << List3 << "Is not equal to:" << endl << "List1" << endl
- << "--------------------------------------------------------------" << endl
- << List1 << endl;
- }
- cout << "Test = overloaded function" << endl;
- cout << "List3\tBefore" << endl
- << "--------------------------------------------------------------"<< endl
- << List3 << endl;
- //Test operator= overloaded function
- List3 = List1;
- //Output newList
- cout << "List3\tAfter" << endl
- << "--------------------------------------------------------------"<< endl
- << List3 << endl;
- //Test operator== overloaded function
- if(List3 == List1){
- cout << "Test == overloaded function" << endl;
- cout << "List3" << endl
- << "--------------------------------------------------------------" << endl
- << List3 << "Is equal to:" << endl << "List1" << endl
- << "--------------------------------------------------------------" << endl
- << List1 << endl;
- }
- //Test operator[] overloaded function
- List1[3] = 10;
- cout << "Test [] overloaded function (List1)" << endl
- << "Elements in use: " << List1.getEltsInUse()
- << "\tCapacity: " << List1.getCapacity()
- << "\tIndex changed: 3" << endl
- << List1 << endl;
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement