Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me with this entire C++ lab example. I know it looks long but i prom

ID: 3860338 • Letter: P

Question

Please help me with this entire C++ lab example. I know it looks long but i promise most of it are just explanations. I will provide the given codes below the pictured instructions. thank you so much

-------------------------------------------------------------------------------------------------------------------------

// iadrv.h

#ifndef _IADRV_H

#define _IADRV_H

#include "intarray.h"

int main();

void test1();

void test2();

void test3();

void test4();

void test5();

void test6();

void test7();

void test8();

void test9();

void test10();

void test11();

void test12();

void test13();

void test14();

void test15();

void test16();

void test17();

void test18();

void test19();

void test20();

void wait();

#endif

-------------------------------------------------------------------------------------------------------------------------

// iadrv.cpp - driver program for testing IntArray class

#include <iostream>

#include <iomanip>

#include <fstream>

#include <stdlib.h>

#include "iadrv.h"

using namespace std;

ofstream csis;

int main() {

csis.open("csis.txt");

test1();

test2();

test3();

test4();

test5();

test6();

test7();

test8();

test9();

test10();

test11();

test12();

test13();

test14();

test15();

test16();

test17();

test18();

test19();

test20();

csis.close();

}

void test1() {

cout << "1. Array declared with single integer: IntArray a(10);" << endl << endl;

csis << "1. Array declared with single integer: IntArray a(10);" << endl << endl;

IntArray a(10);

for(int i = a.low(); i <= a.high(); i++)

a[i] = i * 10;

a.setName("a");

cout << a << endl;

csis << a << endl;

wait();

}

void test2() {

cout << "2. Array declared with two integers: IntArray b(-3, 6);" << endl << endl;

csis << "2. Array declared with two integers: IntArray b(-3, 6);" << endl << endl;

IntArray b(-3, 6);

for(int i = b.low(); i <= b.high(); i++)

b[i] = i * 10;

b.setName("b");

cout << b << endl;

csis << b << endl;

wait();

}

void test3() {

cout << "3. Array declared with two integers: IntArray c(6, 8);" << endl << endl;

csis << "3. Array declared with two integers: IntArray c(6, 8);" << endl << endl;

IntArray c(6, 8);

for(int i = c.low(); i <= c.high(); i++)

c[i] = i * 10;

c.setName("c");

cout << c << endl;

csis << c << endl;

wait();

}

void test4() {

cout << "4. Array declared with two identical integers: IntArray d(5, 5);" << endl << endl;

csis << "4. Array declared with two identical integers: IntArray d(5, 5);" << endl << endl;

IntArray d(5, 5);

for(int i = d.low(); i <= d.high(); i++)

d[i] = i * 10;

d.setName("d");

cout << d << endl;

csis << d << endl;

wait();

}

void test5() {

cout << "5. Array declared with no integers: IntArray z;" << endl << endl;

csis << "5. Array declared with no integers: IntArray z;" << endl << endl;

IntArray z;

for(int i = z.low(); i <= z.high(); i++)

z[i] = i * 10;

z.setName("z");

cout << z << endl;

csis << z << endl;

wait();

}

void test6() {

cout << "6. Array declared with another object of type IntArray: IntArray c(6, 8);" << endl;

cout << " Intarray e(c);" << endl << endl;

csis << "6. Array declared with another object of type IntArray: IntArray c(6, 8);" << endl;

csis << " Intarray e(c);" << endl << endl;

IntArray c(6, 8);

for(int i = c.low(); i <= c.high(); i++)

c[i] = i * 10;

c.setName("c");

cout << c << endl;

csis << c << endl;

IntArray e(c);

e.setName("e");

cout << e << endl;

csis << e << endl;

wait();

}

void test7() {

cout << "7. Array assigned to another array w/ different indices: IntArray f(1, 4);" << endl;

cout << " IntArray g(5, 8);" << endl;

cout << " f = g;" << endl << endl;

csis << "7. Array assigned to another array w/ different indices: IntArray f(1, 4);" << endl;

csis << " IntArray g(5, 8);" << endl;

csis << " f = g;" << endl << endl;

IntArray f(1, 4);

for(int i = f.low(); i <= f.high(); i++)

f[i] = i * 10;

f.setName("f");

cout << f << endl;

csis << f << endl;

IntArray g(5, 8);

for(int i = g.low(); i <= g.high(); i++)

g[i] = i * 10;

g.setName("g");

cout << g << endl;

csis << g << endl;

wait();

f = g;

cout << f << endl;

cout << g << endl;

csis << f << endl;

csis << g << endl;

wait();

}

void test8() {

cout << "8. Multiple array assignment with different indices: IntArray j(3, 6);" << endl;

cout << " IntArray k(6, 9);" << endl;

cout << " IntArray l(1, 4);" << endl;

cout << " j = k = l;" << endl << endl;

  

csis << "8. Multiple array assignment with different indices: IntArray j(3, 6);" << endl;

csis << " IntArray k(6, 9);" << endl;

csis << " IntArray l(1, 4);" << endl;

csis << " j = k = l;" << endl << endl;

IntArray j(3, 6);

for(int i = j.low(); i <= j.high(); i++)

j[i] = i * 10;

j.setName("j");

cout << j << endl;

csis << j << endl;

IntArray k(6, 9);

for(int i = k.low(); i <= k.high(); i++)

k[i] = i * 10;

k.setName("k");

cout << k << endl;

csis << k << endl;

IntArray l(1, 4);

for(int i = l.low(); i <= l.high(); i++)

l[i] = i * 10;

l.setName("l");

cout << l << endl;

csis << l << endl;

wait();

j = k = l;

cout << j << endl;

cout << k << endl;

cout << l << endl;

csis << j << endl;

csis << k << endl;

csis << l << endl;

wait();

}

void test9() {

cout << "9. Overloaded equality operator (identical elements): IntArray m(3, 7);" << endl;

cout << " IntArray n(1, 5);" << endl;

cout << " m == n" << endl << endl;

csis << "9. Overloaded equality operator (identical elements): IntArray m(3, 7);" << endl;

csis << " IntArray n(1, 5);" << endl;

csis << " m == n" << endl << endl;

IntArray m(3, 7);

for(int i = m.low(); i <= m.high(); i++)

m[i] = i * 10;

m.setName("m");

cout << m << endl;

csis << m << endl;

IntArray n(1, 5);

for(int i = n.low(); i <= n.high(); i++)

n[i] = i * 10;

n.setName("n");

cout << n << endl;

csis << n << endl;

wait();

  

m = n;

cout << m << endl;

cout << n << endl;

cout << "Returns " << (m == n ? "True." : "False.") << endl << endl;

csis << m << endl;

csis << n << endl;

csis << "Returns " << (m == n ? "True." : "False.") << endl << endl;

wait();

}

void test10() {

cout << "10. Overloaded equality operator (different elements): IntArray o(3, 7);" << endl;

cout << " IntArray p(1, 5);" << endl;

cout << " o == p" << endl << endl;

csis << "10. Overloaded equality operator (different elements): IntArray o(3, 7);" << endl;

csis << " IntArray p(1, 5);" << endl;

csis << " o == p" << endl << endl;

IntArray o(3, 7);

for(int i = o.low(); i <= o.high(); i++)

o[i] = i * 10;

o.setName("o");

cout << o << endl;

csis << o << endl;

IntArray p(1, 5);

for(int i = p.low(); i <= p.high(); i++)

p[i] = i * 10;

p.setName("p");

cout << p << endl;

cout << "Returns " << (o == p ? "True." : "False.") << endl << endl;

csis << p << endl;

csis << "Returns " << (o == p ? "True." : "False.") << endl << endl;

wait();

}

void test11() {

cout << "11. Overloaded equality operator (different size arrays): IntArray q(1, 3);" << endl;

cout << " IntArray r(1, 4);" << endl;

cout << " q == r;" << endl << endl;

csis << "11. Overloaded equality operator (different size arrays): IntArray q(1, 3);" << endl;

csis << " IntArray r(1, 4);" << endl;

csis << " q == r;" << endl << endl;

IntArray q(1, 3);

for(int i = q.low(); i <= q.high(); i++)

q[i] = i * 10;

q.setName("q");

cout << q << endl;

csis << q << endl;

IntArray r(1, 4);

for(int i = r.low(); i <= r.high(); i++)

r[i] = i * 10;

r.setName("r");

cout << r << endl;

cout << "Returns " << (q == r ? "True." : "False.") << endl << endl;

csis << r << endl;

csis << "Returns " << (q == r ? "True." : "False.") << endl << endl;

wait();

}

void test12() {

cout << "12. Overloaded inequality operator (identical elements): IntArray s(3, 7);" << endl;

cout << " IntArray t(1, 5);" << endl;

cout << " s != t;" << endl << endl;

csis << "12. Overloaded inequality operator (identical elements): IntArray s(3, 7);" << endl;

csis << " IntArray t(1, 5);" << endl;

csis << " s != t;" << endl << endl;

IntArray s(3, 7);

for(int i = s.low(); i <= s.high(); i++)

s[i] = i * 10;

s.setName("s");

cout << s << endl;

csis << s << endl;

IntArray t(1, 5);

for(int i = t.low(); i <= t.high(); i++)

t[i] = i * 10;

t.setName("t");

cout << t << endl;

csis << t << endl;

wait();

s = t;

cout << s << endl;

cout << t << endl;

cout << "Returns " << (s != t ? "True." : "False.") << endl << endl;

csis << s << endl;

csis << t << endl;

csis << "Returns " << (s != t ? "True." : "False.") << endl << endl;

wait();

}

void test13() {

cout << "13. Overloaded inequality operator (different elements): IntArray u(3, 7);" << endl;

cout << " IntArray v(1, 5);" << endl;

cout << " u != v;" << endl << endl;

csis << "13. Overloaded inequality operator (different elements): IntArray u(3, 7);" << endl;

csis << " IntArray v(1, 5);" << endl;

csis << " u != v;" << endl << endl;

IntArray u(3, 7);

for(int i = u.low(); i <= u.high(); i++)

u[i] = i * 10;

u.setName("u");

cout << u << endl;

csis << u << endl;

IntArray v(1, 5);

for(int i = v.low(); i <= v.high(); i++)

v[i] = i * 10;

v.setName("v");

cout << v << endl;

cout << "Returns " << (u != v ? "True." : "False.") << endl << endl;

csis << v << endl;

csis << "Returns " << (u != v ? "True." : "False.") << endl << endl;

wait();

}

void test14() {

cout << "14. Overloaded inequality operator (different size arrays): IntArray w(1, 3);" << endl;

cout << " IntArray x(1, 4);" << endl;

cout << " w != x;" << endl << endl;

csis << "14. Overloaded inequality operator (different size arrays): IntArray w(1, 3);" << endl;

csis << " IntArray x(1, 4);" << endl;

csis << " w != x;" << endl << endl;

IntArray w(1, 3);

for(int i = w.low(); i <= w.high(); i++)

w[i] = i * 10;

w.setName("w");

cout << w << endl;

csis << w << endl;

IntArray x(1, 4);

for(int i = x.low(); i <= x.high(); i++)

x[i] = i * 10;

x.setName("x");

cout << x << endl;

cout << "Returns " << (w != x ? "True." : "False.") << endl << endl;

csis << x << endl;

csis << "Returns " << (w != x ? "True." : "False.") << endl << endl;

wait();

}

void test15() {

cout << "15. Sum of two arrays assigned to third array: IntArray a(1, 5);" << endl;

cout << " IntArray b(4, 8);" << endl;

cout << " IntArray c = a + b;" << endl << endl;

csis << "15. Sum of two arrays assigned to third array: IntArray a(1, 5);" << endl;

csis << " IntArray b(4, 8);" << endl;

csis << " IntArray c = a + b;" << endl << endl;

IntArray a(1, 5);

for(int i = a.low(); i <= a.high(); i++)

a[i] = i * 10;

a.setName("a");

cout << a << endl;

csis << a << endl;

IntArray b(4, 8);

for(int i = b.low(); i <= b.high(); i++)

b[i] = i * 10;

b.setName("b");

cout << b << endl;

csis << b << endl;

wait();

IntArray c = a + b;

c.setName("c");

cout << c << endl;

csis << c << endl;

wait();

}

void test16() {

cout << "16. Sum of two arrays assigned to first array: IntArray d(10, 13);" << endl;

cout << " IntArray e(30, 33);" << endl;

cout << " d += e;" << endl << endl;

csis << "16. Sum of two arrays assigned to first array: IntArray d(10, 13);" << endl;

csis << " IntArray e(30, 33);" << endl;

csis << " d += e;" << endl << endl;

IntArray d(10, 13);

for(int i = d.low(); i <= d.high(); i++)

d[i] = i * 10;

d.setName("d");

cout << d << endl;

csis << d << endl;

IntArray e(30, 33);

for(int i = e.low(); i <= e.high(); i++)

e[i] = i * 10;

e.setName("e");

cout << e << endl;

csis << e << endl;

d += e;

cout << d << endl;

csis << d << endl;

wait();

}

void test17() {

cout << "17. Array declared with illegal array bounds: IntArray f(5, 2);" << endl << endl;

csis << "17. Array declared with illegal array bounds: IntArray f(5, 2);" << endl << endl;

IntArray f(5, 2);

for(int i = f.low(); i <= f.high(); i++)

f[i] = i * 10;

f.setName("f");

cout << f << endl;

csis << f << endl;

wait();

}

void test18() {

cout << "18. Array with index out of range: IntArray g(10);" << endl;

cout << " g[10] = 1;" << endl << endl;

csis << "18. Array with index out of range: IntArray g(10);" << endl;

csis << " g[10] = 1;" << endl << endl;

IntArray g(10);

for(int i = g.low(); i <= g.high(); i++)

g[i] = i * 10;

g.setName("g");

cout << g << endl;

csis << g << endl;

g[10] = 1;

wait();

}

void test19() {

cout << "19. Arrays with length mismatch: IntArray m(1, 4);" << endl;

cout << " IntArray n(2, 4);" << endl;

cout << " m = n;" << endl << endl;

csis << "19. Arrays with length mismatch: IntArray m(1, 4);" << endl;

csis << " IntArray n(2, 4);" << endl;

csis << " m = n;" << endl << endl;

IntArray m(1, 4);

for(int i = m.low(); i <= m.high(); i++)

m[i] = i * 10;

m.setName("m");

cout << m << endl;

csis << m << endl;

IntArray n(2, 4);

for(int i = n.low(); i <= n.high(); i++)

n[i] = i * 10;

n.setName("n");

cout << n << endl;

csis << n << endl;

wait();

m = n;

cout << m << endl;

cout << n << endl;

csis << m << endl;

csis << n << endl;

wait();

}

void test20() {

cout << "20. Array subscript operator: IntArray o(7, 8);" << endl;

cout << " o[7] = 25;" << endl;

cout << " o[8] = o[7];" << endl << endl;

csis << "20. Array subscript operator: IntArray o(7, 8);" << endl;

csis << " o[7] = 25;" << endl;

csis << " o[8] = o[7];" << endl << endl;

IntArray o(7, 8);

for(int i = o.low(); i <= o.high(); i++)

o[i] = i * 10;

o.setName("o");

cout << o << endl;

csis << o << endl;

o[7] = 25;

o[8] = o[7];

cout << o << endl;

csis << o << endl;

wait();

}

void wait() {

char buf;

  

cout << "Press any key to continue." << endl;

cin.get(buf);

}

Operator Overloading Lab (IntArray) The array construct in C is very efficient but also very dangerous for the unwary For example, many novice programmers fall into the trap of declaring an array of 100 elements and then try to access the element with index 100. Not only is thie an error in C, but the language won't even alert the user when the mistake is made. C++ allows programmers to define safer and more flexible array constructs if they are willing to sacrifice some of C's runtime efficiency. The purpose of this lab is to see how this is done and to gain some experience in overloading operators called IntArray rray With it, the user will be able to declare integer arrays of any size with automatic range checking of indices. The upper and lower indices can be any integer positive or negative, rather than the fixed limits of o to SIZE-1. It will also be possible to assign entire arrays to each other, compare two arrays for equal and inequality, add two arrays, and output arrays using the overloaded ity operator. For example: tinclude ciostream> include "IntArray.h" using namespace std; int main) f // Ten elements, indexed 0 to 9 // Ten elements, indexed -3 to 6 // Three elements, indexed 6 to 8 // Single element array, indexed at 5 // Ten elements, indexed 0 to 9 IntArray a (10), w(10) IntArray b(-3, 6) IntArray c(6, 8) IntArray d(5, 5); IntArray zi // high() and low() return largest and smallest legal indices for (int i =a.Iow(); i

Explanation / Answer

main.cpp
--------------------
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdlib.h>
#include "iadrv.h"
#include "IntArray.h"
using namespace std;
ofstream csis;
void wait() ;
int main() {
    csis.open("csis");
    test1();
    test2();
    test3();
    test4();
    test5();
    test6();
    test7();
    test8();
    test9();
    test10();
    test11();
    test12();
    test13();
    test14();
    test15();
    test16();
    test17();
    test18();
    test19();
    test20();
    csis.close();}
void test1() {
    cout << "1. Array declared with single integer: IntArray a(10);" << endl << endl;
    csis << "1. Array declared with single integer: IntArray a(10);" << endl << endl;
    IntArray a(10);
    for(int i = a.low(); i <= a.high(); i++)
        a[i] = i * 10;
    a.setName("a");
    cout << a << endl;
    csis << a << endl;
    wait();}
void test2() {
    cout << "2. Array declared with two integers: IntArray b(-3, 6);" << endl << endl;
    csis << "2. Array declared with two integers: IntArray b(-3, 6);" << endl << endl;
    IntArray b(-3, 6);
    for(int i = b.low(); i <= b.high(); i++)
        b[i] = i * 10;
    b.setName("b");
    cout << b << endl;
    csis << b << endl;
    wait();}
void test3() {
    cout << "3. Array declared with two integers: IntArray c(6, 8);" << endl << endl;
    csis << "3. Array declared with two integers: IntArray c(6, 8);" << endl << endl;
    IntArray c(6, 8);
    for(int i = c.low(); i <= c.high(); i++)
        c[i] = i * 10;
    c.setName("c");
    cout << c << endl;
    csis << c << endl;
    wait();}
void test4() {
    cout << "4. Array declared with two identical integers: IntArray d(5, 5);" << endl << endl;
    csis << "4. Array declared with two identical integers: IntArray d(5, 5);" << endl << endl;
    IntArray d(5, 5);
    for(int i = d.low(); i <= d.high(); i++)
        d[i] = i * 10;
    d.setName("d");
    cout << d << endl;
    csis << d << endl;
    wait();}
void test5() {
    cout << "5. Array declared with no integers: IntArray z;" << endl << endl;
    csis << "5. Array declared with no integers: IntArray z;" << endl << endl;
    IntArray z;
    for(int i = z.low(); i <= z.high(); i++)
        z[i] = i * 10;
    z.setName("z");
    cout << z << endl;
    csis << z << endl;
    wait();}
void test6() {
    cout << "6. Array declared with another object of type IntArray: IntArray c(6, 8);" << endl;
    cout << "                                                        Intarray e(c);"    << endl << endl;
    csis << "6. Array declared with another object of type IntArray: IntArray c(6, 8);" << endl;
    csis << "                                                        Intarray e(c);"    << endl << endl;
    IntArray c(6, 8);
    for(int i = c.low(); i <= c.high(); i++)
        c[i] = i * 10;
    c.setName("c");
    cout << c << endl;
    csis << c << endl;
    IntArray e(c);
    e.setName("e");
    cout << e << endl;
    csis << e << endl;
    wait();}
void test7() {
    cout << "7. Array assigned to another array w/ different indices: IntArray f(1, 4);" << endl;
    cout << "                                                         IntArray g(5, 8);" << endl;
    cout << "                                                         f = g;"            << endl << endl;
    csis << "7. Array assigned to another array w/ different indices: IntArray f(1, 4);" << endl;
    csis << "                                                         IntArray g(5, 8);" << endl;
    csis << "                                                         f = g;"            << endl << endl;
    IntArray f(1, 4);
    for(int i = f.low(); i <= f.high(); i++)
        f[i] = i * 10;
    f.setName("f");
    cout << f << endl;
    csis << f << endl;
    IntArray g(5, 8);
    for(int i = g.low(); i <= g.high(); i++)
        g[i] = i * 10;
    g.setName("g");
    cout << g << endl;
    csis << g << endl;
    wait();
    f = g;
    cout << f << endl;
    cout << g << endl;
    csis << f << endl;
    csis << g << endl;
    wait();}
void test8() {
    cout << "8. Multiple array assignment with different indices: IntArray j(3, 6);" << endl;
    cout << "                                                     IntArray k(6, 9);" << endl;
    cout << "                                                     IntArray l(1, 4);" << endl;
    cout << "                                                     j = k = l;"        << endl << endl;

    csis << "8. Multiple array assignment with different indices: IntArray j(3, 6);" << endl;
    csis << "                                                     IntArray k(6, 9);" << endl;
    csis << "                                                     IntArray l(1, 4);" << endl;
    csis << "                                                     j = k = l;"        << endl << endl;
    IntArray j(3, 6);
    for(int i = j.low(); i <= j.high(); i++)
        j[i] = i * 10;
    j.setName("j");
    cout << j << endl;
    csis << j << endl;
    IntArray k(6, 9);
    for(int i = k.low(); i <= k.high(); i++)
        k[i] = i * 10;
    k.setName("k");
    cout << k << endl;
    csis << k << endl;
    IntArray l(1, 4);
    for(int i = l.low(); i <= l.high(); i++)
        l[i] = i * 10;
    l.setName("l");
    cout << l << endl;
    csis << l << endl;
    wait();
    j = k = l;
    cout << j << endl;
    cout << k << endl;
    cout << l << endl;
    csis << j << endl;
    csis << k << endl;
    csis << l << endl;
    wait();}
void test9() {
    cout << "9. Overloaded equality operator (identical elements): IntArray m(3, 7);" << endl;
    cout << "                                                      IntArray n(1, 5);" << endl;
    cout << "                                                      m == n"             << endl << endl;
    csis << "9. Overloaded equality operator (identical elements): IntArray m(3, 7);" << endl;
    csis << "                                                      IntArray n(1, 5);" << endl;
    csis << "                                                      m == n"             << endl << endl;
    IntArray m(3, 7);
    for(int i = m.low(); i <= m.high(); i++)
        m[i] = i * 10;
    m.setName("m");
    cout << m << endl;
    csis << m << endl;
    IntArray n(1, 5);
    for(int i = n.low(); i <= n.high(); i++)
        n[i] = i * 10;
    n.setName("n");
    cout << n << endl;
    csis << n << endl;
    wait();

    m = n;
    cout << m << endl;
    cout << n << endl;
    cout << "Returns " << (m == n ? "True." : "False.") << endl << endl;
    csis << m << endl;
    csis << n << endl;
    csis << "Returns " << (m == n ? "True." : "False.") << endl << endl;
    wait();}
void test10() {
    cout << "10. Overloaded equality operator (different elements): IntArray o(3, 7);" << endl;
    cout << "                                                       IntArray p(1, 5);" << endl;
    cout << "                                                       o == p"            << endl << endl;
    csis << "10. Overloaded equality operator (different elements): IntArray o(3, 7);" << endl;
    csis << "                                                       IntArray p(1, 5);" << endl;
    csis << "                                                       o == p"            << endl << endl;
    IntArray o(3, 7);
    for(int i = o.low(); i <= o.high(); i++)
        o[i] = i * 10;
    o.setName("o");
    cout << o << endl;
    csis << o << endl;
    IntArray p(1, 5);
    for(int i = p.low(); i <= p.high(); i++)
        p[i] = i * 10;
    p.setName("p");
    cout << p << endl;
    cout << "Returns " << (o == p ? "True." : "False.") << endl << endl;
    csis << p << endl;
    csis << "Returns " << (o == p ? "True." : "False.") << endl << endl;
    wait();
}
void test11() {
    cout << "11. Overloaded equality operator (different size arrays): IntArray q(1, 3);" << endl;
    cout << "                                                          IntArray r(1, 4);" << endl;
    cout << "                                                          q == r;"           << endl << endl;
    csis << "11. Overloaded equality operator (different size arrays): IntArray q(1, 3);" << endl;
    csis << "                                                          IntArray r(1, 4);" << endl;
    csis << "                                                          q == r;"           << endl << endl;
    IntArray q(1, 3);
    for(int i = q.low(); i <= q.high(); i++)
        q[i] = i * 10;
    q.setName("q");
    cout << q << endl;
    csis << q << endl;
    IntArray r(1, 4);
    for(int i = r.low(); i <= r.high(); i++)
        r[i] = i * 10;
    r.setName("r");
    cout << r << endl;
    cout << "Returns " << (q == r ? "True." : "False.") << endl << endl;
    csis << r << endl;
    csis << "Returns " << (q == r ? "True." : "False.") << endl << endl;
    wait();
}
void test12() {
    cout << "12. Overloaded inequality operator (identical elements): IntArray s(3, 7);" << endl;
    cout << "                                                         IntArray t(1, 5);" << endl;
    cout << "                                                         s != t;"           << endl << endl;
    csis << "12. Overloaded inequality operator (identical elements): IntArray s(3, 7);" << endl;
    csis << "                                                         IntArray t(1, 5);" << endl;
    csis << "                                                         s != t;"           << endl << endl;
    IntArray s(3, 7);
    for(int i = s.low(); i <= s.high(); i++)
        s[i] = i * 10;
    s.setName("s");
    cout << s << endl;
    csis << s << endl;
    IntArray t(1, 5);
    for(int i = t.low(); i <= t.high(); i++)
        t[i] = i * 10;
    t.setName("t");
    cout << t << endl;
    csis << t << endl;
    wait();
    s = t;
    cout << s << endl;
    cout << t << endl;
    cout << "Returns " << (s != t ? "True." : "False.") << endl << endl;
    csis << s << endl;
    csis << t << endl;
    csis << "Returns " << (s != t ? "True." : "False.") << endl << endl;
    wait();
}
void test13() {
    cout << "13. Overloaded inequality operator (different elements): IntArray u(3, 7);" << endl;
    cout << "                                                         IntArray v(1, 5);" << endl;
    cout << "                                                         u != v;"           << endl << endl;
    csis << "13. Overloaded inequality operator (different elements): IntArray u(3, 7);" << endl;
    csis << "                                                         IntArray v(1, 5);" << endl;
    csis << "                                                         u != v;"           << endl << endl;
    IntArray u(3, 7);
    for(int i = u.low(); i <= u.high(); i++)
        u[i] = i * 10;
    u.setName("u");
    cout << u << endl;
    csis << u << endl;
    IntArray v(1, 5);
    for(int i = v.low(); i <= v.high(); i++)
        v[i] = i * 10;
    v.setName("v");
    cout << v << endl;
    cout << "Returns " << (u != v ? "True." : "False.") << endl << endl;
    csis << v << endl;
    csis << "Returns " << (u != v ? "True." : "False.") << endl << endl;
    wait();
}
void test14() {
    cout << "14. Overloaded inequality operator (different size arrays): IntArray w(1, 3);" << endl;
    cout << "                                           IntArray x(1, 4);" << endl;
    cout << "                                           w != x;"           << endl << endl;
    csis << "14. Overloaded inequality operator (different size arrays): IntArray w(1, 3);" << endl;
    csis << "                                           IntArray x(1, 4);" << endl;
    csis << "                                           w != x;"           << endl << endl;
    IntArray w(1, 3);
    for(int i = w.low(); i <= w.high(); i++)
        w[i] = i * 10;
    w.setName("w");
    cout << w << endl;
    csis << w << endl;
    IntArray x(1, 4);
    for(int i = x.low(); i <= x.high(); i++)
        x[i] = i * 10;
    x.setName("x");
    cout << x << endl;
    cout << "Returns " << (w != x ? "True." : "False.") << endl << endl;
    csis << x << endl;
    csis << "Returns " << (w != x ? "True." : "False.") << endl << endl;
    wait();
}
void test15() {
    cout << "15. Sum of two arrays assigned to third array: IntArray a(1, 5);"   << endl;
    cout << "                                               IntArray b(4, 8);"   << endl;
    cout << "                                               IntArray c = a + b;" << endl << endl;
    csis << "15. Sum of two arrays assigned to third array: IntArray a(1, 5);"   << endl;
    csis << "                                               IntArray b(4, 8);"   << endl;
    csis << "                                               IntArray c = a + b;" << endl << endl;
    IntArray a(1, 5);
    for(int i = a.low(); i <= a.high(); i++)
        a[i] = i * 10;
    a.setName("a");
    cout << a << endl;
    csis << a << endl;
    IntArray b(4, 8);
    for(int i = b.low(); i <= b.high(); i++)
        b[i] = i * 10;
    b.setName("b");
    cout << b << endl;
    csis << b << endl;
    wait();
    IntArray c = a + b;
    c.setName("c");
    cout << c << endl;
    csis << c << endl;
    wait();
}
void test16() {
    cout << "16. Sum of two arrays assigned to first array: IntArray d(10, 13);" << endl;
    cout << "                                               IntArray e(30, 33);" << endl;
    cout << "                                               d += e;"             << endl << endl;
    csis << "16. Sum of two arrays assigned to first array: IntArray d(10, 13);" << endl;
    csis << "                                               IntArray e(30, 33);" << endl;
    csis << "                                               d += e;"             << endl << endl;
    IntArray d(10, 13);
    for(int i = d.low(); i <= d.high(); i++)
        d[i] = i * 10;
    d.setName("d");
    cout << d << endl;
    csis << d << endl;
    IntArray e(30, 33);
    for(int i = e.low(); i <= e.high(); i++)
        e[i] = i * 10;
    e.setName("e");
    cout << e << endl;
    csis << e << endl;
    d += e;
    cout << d << endl;
    csis << d << endl;
    wait();
}
void test17() {
    cout << "17. Array declared with illegal array bounds: IntArray f(5, 2);" << endl << endl;
    csis << "17. Array declared with illegal array bounds: IntArray f(5, 2);" << endl << endl;
    IntArray f(5, 2);
    for(int i = f.low(); i <= f.high(); i++)
        f[i] = i * 10;
    f.setName("f");
    cout << f << endl;
    csis << f << endl;
    wait();
}
void test18() {
    cout << "18. Array with index out of range: IntArray g(10);"    << endl;
    cout << "                                   g[10] = 1;"         << endl << endl;
    csis << "18. Array with index out of range: IntArray g(10);"    << endl;
    csis << "                                   g[10] = 1;"         << endl << endl;
    IntArray g(10);
    for(int i = g.low(); i <= g.high(); i++)
        g[i] = i * 10;
    g.setName("g");
    cout << g << endl;
    csis << g << endl;
    g[10] = 1;
    wait();
}
void test19() {
    cout << "19. Arrays with length mismatch: IntArray m(1, 4);" << endl;
    cout << "                                 IntArray n(2, 4);" << endl;
    cout << "                                 m = n;"            << endl << endl;
    csis << "19. Arrays with length mismatch: IntArray m(1, 4);" << endl;
    csis << "                                 IntArray n(2, 4);" << endl;
    csis << "                                 m = n;"            << endl << endl;
    IntArray m(1, 4);
    for(int i = m.low(); i <= m.high(); i++)
        m[i] = i * 10;
    m.setName("m");
    cout << m << endl;
    csis << m << endl;
    IntArray n(2, 4);
    for(int i = n.low(); i <= n.high(); i++)
        n[i] = i * 10;
    n.setName("n");
    cout << n << endl;
    csis << n << endl;
    wait();
    m = n;
    cout << m << endl;
    cout << n << endl;
    csis << m << endl;
    csis << n << endl;
    wait();
}
void test20() {
    cout << "20. Array subscript operator: IntArray o(7, 8);" << endl;
    cout << "                              o[7] = 25;"        << endl;
    cout << "                              o[8] = o[7];"      << endl << endl;
    csis << "20. Array subscript operator: IntArray o(7, 8);" << endl;
    csis << "                              o[7] = 25;"        << endl;
    csis << "                              o[8] = o[7];"      << endl << endl;
    IntArray o(7, 8);
    for(int i = o.low(); i <= o.high(); i++)
        o[i] = i * 10;
    o.setName("o");
    cout << o << endl;
    csis << o << endl;
    o[7] = 25;
    o[8] = o[7];
    cout << o << endl;
    csis << o << endl;
    wait();
}
void wait() {
    char buf;
    cout << "Press any key to continue." << endl;
    cin.get(buf);
}
----------------------------------------------
iadrv.h
-------------------------------
#ifndef _IADRV_H
#define _IADRV_H
#include "intarray.h"
int main();
void test1();
void test2();
void test3();
void test4();
void test5();
void test6();
void test7();
void test8();
void test9();
void test10();
void test11();
void test12();
void test13();
void test14();
void test15();
void test16();
void test17();
void test18();
void test19();
void test20();
void wait();
#endif
----------------------------------------------
IntArray.cpp
-------------------------------
#include "IntArray.h"
#include <fstream>
extern ofstream csis;
IntArray::IntArray(){
    min = 0;
    max = 9;
    size = 10;
    array[size];}
IntArray::IntArray(int upper){
    min = 0;
    max = upper - 1;
    size = upper;
    array[size];}
IntArray::IntArray(int lower, int upper){
    if (lower > upper) {
        cout << "Error: Lower boundary out of range - Program Halt..." << endl;
        csis << "Error: Lower boundary out of range - Program Halt..." << endl;
    }
    else if (lower == upper) {
        min = lower;
        max = upper;
        size = 1;
        array[size];
    }
    else {
        min = lower;
        max = upper;
        size = ((upper) - (lower)) + 1;
        array[size];
    }
}

IntArray::IntArray(const IntArray& arr)
{
    min = arr.min;
    max = arr.max;
    size = arr.size;
    for (int i = arr.min; i <= arr.max; i++) {
        array[i] = arr.array[i];
    }
}
void IntArray::setName(string s)
{
    name = s;
}
int IntArray::low()
{
    return min;
}
int IntArray::high()
{
    return max;
}
IntArray& IntArray::operator=(IntArray& arr)
{
    min = arr.min;
    max = arr.max;
    int offset = arr.min;
    int* ptr = (arr.array+offset);

    if (size != arr.size) {
        cout << "Error: Size mismatch. Program halt..." << endl << endl;
        csis << "Error: Size mismatch. Program halt..." << endl << endl;
    }

    for (int i = min; i <= max; i++) {
        array[i] = *(ptr+i);
    }

    return *this;
}
int IntArray::operator==(IntArray& arr)
{
    int offset = arr.min;
    int* ptr1 = (array+min);
    int* ptr2 = (arr.array+offset);
    int check = 0;

    if ( (size) == (arr.size) ) {
        for (int i = min; i <= max; i++) {
            if ( *(ptr1+i) == *(ptr2+i) ) {
                check = 1;
            }
            else {
                return 0;
            }
        }
    }

    return check;
}
int IntArray::operator!=(IntArray& arr)
{
    int offset = arr.min;
    int* ptr1 = (array+min);
    int* ptr2 = (arr.array+offset);
    int check = 1;

    if ( (size) == (arr.size) ) {
        for (int i = min; i <= max; i++) {
            if ( *(ptr1+i) == *(ptr2+i) ) {
                check = 0;
            }
            else {
                return 1;
            }
        }
    }

    return check;
}
int& IntArray::operator[](int val)
{
    if (val < min || val > max) {
        cout << "Error: Out of legal range. Program halt..." << endl;
        csis << "Error: Out of legal range. Program halt..." << endl << endl;
    }

    return val;
}
void IntArray::operator+=(IntArray& arr)
{
    int offset = arr.min;
    int* ptr = (arr.array+offset);

    if ( (max - min) != (arr.max - arr.min) ) {
        cout << "Error: Must have same number of elements. Program halt..." << endl;
        csis << "Error: Must have same number of elements. Program halt..." << endl;
    }
    else {
        for (int i = min; i <= max; i++) {
            array[i] = *(array+i) + *(ptr+i);
        }
    }
}
IntArray operator+(IntArray& arr1, IntArray& arr2)
{
    IntArray temp(arr1.size);
    int offset = arr1.min;
    int offset2 = arr2.min;
    int* ptr1 = (arr1.array+offset);
    int* ptr2 = (arr2.array+offset2);

    if ( (arr1.size) != (arr2.size) ) {
        cout << "Error: Must have same number of elements. Program halt..." << endl;
        csis << "Error: Must have same number of elements. Program halt..." << endl;
    }
    else {
        for (int i = 0; i <= temp.size; i++) {
            temp.array[i] = *(ptr1+i) + *(ptr2+i);
        }
    }
    return IntArray(temp);
}

ostream& operator<<(ostream& os, const IntArray& arr)
{
    if (arr.min == arr.max) {
        int i = arr.min;
        os << arr.name << "[" << i << "] = " << arr.array[i] << endl;
    }
    else {
        for (int i = arr.min; i <= arr.max; i++) {
            os << arr.name << "[" << i << "] = " << arr.array[i] << endl;
        }
    }
    return os;
}
----------------------------------------------
IntArray.h
-------------------------------
#ifndef __Operator_Overloading_Lab__IntArray__
#define __Operator_Overloading_Lab__IntArray__
#include <iostream>
using namespace std;
class IntArray {
private:
    string name;
    int min;
    int max;
    int size;
    int array[];
public:
    IntArray();
    IntArray(int);
    IntArray(int, int);
    IntArray(const IntArray&);
    void setName(string);
    int low();
    int high();
    IntArray& operator=(IntArray&);
    int operator==(IntArray&);
    int operator!=(IntArray&);
    int& operator[](int);
    void operator+=(IntArray&);
    friend IntArray operator+(IntArray&, IntArray&);
    friend ostream& operator<<(ostream&, const IntArray&);
};
#endif

csis.txt

-------------------------------

1. Array declared with single integer: IntArray a(10);

a[0] = 0

a[1] = 10

a[2] = 20

a[3] = 30

a[4] = 40

a[5] = 50

a[6] = 60

a[7] = 70

a[8] = 80

a[9] = 90

2. Array declared with two integers: IntArray b(-3, 6);

b[-30] = 1

b[-29] = 1606416256

b[-28] = 32767

b[-27] = 2046468856

b[-26] = 32767

b[-25] = 41600

b[-24] = 1

b[-23] = 65666

b[-22] = 1

b[-21] = 25090

b[-20] = 0

3. Array declared with two integers: IntArray c(6, 8);

c[6] = 60

c[7] = 70

c[8] = 80

4. Array declared with two identical integers: IntArray d(5, 5);

d[5] = 50

5. Array declared with no integers: IntArray z;

z[0] = 0

z[1] = 10

z[2] = 20

z[3] = 30

z[4] = 40

z[5] = 50

z[6] = 60

z[7] = 70

z[8] = 80

z[9] = 90

6. Array declared with another object of type IntArray: IntArray c(6, 8);

Intarray e(c);

c[6] = 60

c[7] = 70

c[8] = 80

e[6] = 60

e[7] = 70

e[8] = 80

7. Array assigned to another array w/ different indices: IntArray f(1, 4);

IntArray g(5, 8);

f = g;

f[1] = 10

f[2] = 20

f[3] = 30

f[4] = 40

g[5] = 50

g[6] = 60

g[7] = 70

g[8] = 80

f[5] = 1

f[6] = 41600

f[7] = 5

f[8] = 26114

g[5] = 50

g[6] = 60

g[7] = 70

g[8] = 80

8. Multiple array assignment with different indices: IntArray j(3, 6);

IntArray k(6, 9);

IntArray l(1, 4);

j = k = l;

j[3] = 30

j[4] = 40

j[5] = 50

j[6] = 60

k[6] = 60

k[7] = 70

k[8] = 80

k[9] = 90

l[1] = 10

l[2] = 20

l[3] = 30

l[4] = 40

j[1] = 30

j[2] = 40

j[3] = 1

j[4] = 70600

k[1] = 20

k[2] = 30

k[3] = 40

k[4] = 1

l[1] = 10

l[2] = 20

l[3] = 30

l[4] = 40

9. Overloaded equality operator (identical elements): IntArray m(3, 7);

IntArray n(1, 5);

m == n

m[3] = 30

m[4] = 40

m[5] = 50

m[6] = 60

m[7] = 70

n[1] = 10

n[2] = 20

n[3] = 30

n[4] = 40

n[5] = 50

m[1] = 20

m[2] = 30

m[3] = 40

m[4] = 50

m[5] = 1

n[1] = 10

n[2] = 20

n[3] = 30

n[4] = 40

n[5] = 50

Returns False.

10. Overloaded equality operator (different elements): IntArray o(3, 7);

IntArray p(1, 5);

o == p

o[3] = 30

o[4] = 40

o[5] = 50

o[6] = 60

o[7] = 70

p[1] = 10

p[2] = 20

p[3] = 30

p[4] = 40

p[5] = 50

Returns False.

11. Overloaded equality operator (different size arrays): IntArray q(1, 3);

IntArray r(1, 4);

q == r;

q[1] = 10

q[2] = 20

q[3] = 30

r[1] = 10

r[2] = 20

r[3] = 30

r[4] = 40

Returns False.

12. Overloaded inequality operator (identical elements): IntArray s(3, 7);

IntArray t(1, 5);

s != t;

s[3] = 30

s[4] = 40

s[5] = 50

s[6] = 60

s[7] = 70

t[1] = 10

t[2] = 20

t[3] = 30

t[4] = 40

t[5] = 50

s[1] = 20

s[2] = 30

s[3] = 40

s[4] = 50

s[5] = 5

t[1] = 10

t[2] = 20

t[3] = 30

t[4] = 40

t[5] = 50

Returns True.

13. Overloaded inequality operator (different elements): IntArray u(3, 7);

IntArray v(1, 5);

u != v;

u[3] = 30

u[4] = 40

u[5] = 50

u[6] = 60

u[7] = 70

v[1] = 10

v[2] = 20

v[3] = 30

v[4] = 40

v[5] = 50

Returns True.

14. Overloaded inequality operator (different size arrays): IntArray w(1, 3);

IntArray x(1, 4);

w != x;

w[1] = 10

w[2] = 20

w[3] = 30

x[1] = 10

x[2] = 20

x[3] = 30

x[4] = 40

Returns True.

15. Sum of two arrays assigned to third array: IntArray a(1, 5);

IntArray b(4, 8);

IntArray c = a + b;

a[1] = 10

a[2] = 20

a[3] = 30

a[4] = 40

a[5] = 50

b[4] = 40

b[5] = 50

b[6] = 60

b[7] = 70

b[8] = 80

c[0] = 50

c[1] = 70

c[2] = 90

c[3] = 110

c[4] = 130

16. Sum of two arrays assigned to first array: IntArray d(10, 13);

IntArray e(30, 33);

d += e;

d[10] = 100

d[11] = 110

d[12] = 120

d[13] = 130

e[30] = 300

e[31] = 310

e[32] = 320

e[33] = 330

d[10] = 321

d[11] = 70930

d[12] = 121

d[13] = 41730

17. Array declared with illegal array bounds: IntArray f(5, 2);

Error: Lower boundary out of range - Program Halt...

18. Array with index out of range: IntArray g(10);

g[10] = 1;

g[0] = 0

g[1] = 10

g[2] = 20

g[3] = 30

g[4] = 40

g[5] = 50

g[6] = 60

g[7] = 70

g[8] = 80

g[9] = 90

Error: Out of legal range. Program halt...

19. Arrays with length mismatch: IntArray m(1, 4);

IntArray n(2, 4);

m = n;

m[1] = 10

m[2] = 20

m[3] = 30

m[4] = 40

n[2] = 20

n[3] = 30

n[4] = 40

Error: Size mismatch. Program halt...

m[2] = 40

m[3] = 36062

m[4] = 1

n[2] = 20

n[3] = 30

n[4] = 40

20. Array subscript operator: IntArray o(7, 8);

o[7] = 25;

o[8] = o[7];

o[7] = 70

o[8] = 80

o[7] = 25

o[8] = 25

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote