SHARE
TWEET

Untitled

a guest May 19th, 2017 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // To check consistent spelling, your program must compile with this main with
  2. // no changes to this code whatsoever. This program terminates normally.
  3. // Do NOT put an endl in operator<<.  
  4. // Be sure to name your files using lowercase. Windows is not case sensitive,
  5. // but unix/linux is case sensitive.
  6.  
  7. #include "lab2.h"
  8. #include <iostream>
  9. using namespace std;
  10.  
  11. int main() {
  12.    IntSet A(100), B(3, 5, 9, 12, 15), C(10,5,8), D(12, 5, 10, 12,-500), E, X(D), Y;
  13.  
  14.    // sets A and B acquire desired values
  15.    // A = { 3 7 9}
  16.    // B = { 3 5 9 12 15}
  17.    cout << "Enter ints for set A:  " << endl;
  18.    //cin >> A;
  19.    cout << "Enter ints for set B:  " << endl;
  20.    //cin >> B;
  21.  
  22.    cout << "A = " << A << endl;               // outputs: A = { 3 7 9}
  23.    cout << "B = " << B << endl << endl;       // outputs: B = { 3 5 9 12 15}
  24.  
  25.    cout << "Compute  C = A + B" << endl;
  26.    C = A + B;                                 // C is replaced by A+B
  27.    cout << "C = " << C << endl << endl;       // outputs: C = { 3 5 7 9 12 15}
  28.  
  29.    cout << "Ask if  A == C" << endl;
  30.    cout <<  ( (A == C)? "A == C" : "A is not == C" ) << endl << endl;
  31.  
  32.    cout << "Ask if  A != C" << endl;
  33.    cout <<  ( (A != C)? "A is not == C" : "A == C" ) << endl << endl;
  34.  
  35.    cout << "Compute B - A = " << B - A << endl;            // B - A = { 5 12 15}
  36.    cout << "Compute A - B = " << A - B << endl;            // A - B = { 7}
  37.    cout << "Compute  D = (A * B) + D" << endl;
  38.    cout << "Before: D = " << D;                            // D = { 5 10 12}
  39.    D = (A * B) + D;
  40.    cout << "    After: " << "D = " << D << endl << endl;   // D = { 3 5 9 10 12}
  41.  
  42.    cout << "Test assignment operators" << endl;
  43.    cout << "C = " << C << endl << endl;
  44.    cout << "D = " << D << endl << endl;
  45.    X = C = D = D;
  46.    Y += A *= B;
  47.    cout << "X = " << X << "    Y = " << Y << endl << endl;
  48.    cout << "C = " << C << endl << endl;
  49.    cout << "D = " << D << endl << endl;
  50.  
  51.    // miscellaneous stuff
  52.    cout << (D.isInSet(0) ? "0 in set" : "0 not in set" ) << endl;
  53.    cout << (D.isInSet(-1000) ? "-1000 in set" : "-1000 not in set" ) << endl;
  54.    cout << (A.isEmpty() ? "A empty" : "A not empty" ) << endl;
  55.    bool success;
  56.    success = D.insert(-20000);                  // handle value out of range
  57.    success = D.remove(20000);                   // handle value out of range
  58.    success = D.remove(-5000);                   // handle value out of range
  59.    success = D.insert(0);                       // put 0 in the set
  60.    success = D.insert(20000);                   // handle as you'd like
  61.  
  62.    return 0;
  63. }
RAW Paste Data
Top