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

C++ code issue, I\'ve tried this once already on here and didn\'t supply one spe

ID: 3794368 • Letter: C

Question

C++ code issue, I've tried this once already on here and didn't supply one specific detail. I need the driver to stay as I am supplying it. I won't supply the myArray.h file that I have, because it seems to complicate things.

\driver.cpp   

#include <iostream>
#include "myArray.h"

using namespace std;


int main()
{
myArray<int> list1(5);
myArray<int> list2(5);

int i;

cout << "list1 : ";
for (i = 0 ; i < 5; i++)
cout << list1[i] <<" ";
cout<< endl;

cout << "Enter 5 integers: ";
for (i = 0 ; i < 5; i++)
cin >> list1[i];
cout << endl;

cout << "After filling list1: ";

for (i = 0 ; i < 5; i++)
cout << list1[i] <<" ";
cout<< endl;

list2 = list1;
cout << "list2 : ";
for (i = 0 ; i < 5; i++)
cout << list2[i] <<" ";
cout<< endl;

cout << "Enter 3 elements: ";

for (i = 0; i < 3; i++)
cin >> list1[i];
cout << endl;

cout << "First three elements of list1: ";
for (i = 0; i < 3; i++)
cout << list1[i] << " ";
cout << endl;

myArray<int> list3(-2, 6);

cout << "list3: ";
for (i = -2 ; i < 6; i++)
cout << list3[i] <<" ";
cout<< endl;

list3[-2] = 7;
list3[4] = 8;
list3[0] = 54;
list3[2] = list3[4] + list3[-2];

cout << "list3: ";
for (i = -2 ; i < 6; i++)
cout << list3[i] <<" ";
cout<< endl;

   if (list1 == list2)
       cout << " list 1 is equal to list2 " << endl;
   else
       cout << " list 1 is not equal to list2" << endl;

   if (list1 != list2)
       cout << " list 1 is not equal to list2 " << endl;
   else
       cout << " list 1 is equal to list2" << endl;

   //10% EXTRA CREDIT: UNCOMMENT CODE IF YOU'VE SUCCESSFULLY IMPLEMENTED THE FOLLOWING:
   //cout << list1<< (list1 == list2 ? " is equal to" : " not equal to ") << list2 << endl;
   //cout << list1<< (list1 != list2 ? " not equal to" : " is equal to ") << list2 << endl;

return 0;
}

A.Add an overloaded operator!=(…) and operator==(…) functions.

B.Use the attached driver to test the program (lab6_Driver.cpp):

The Expected Output is:

list1 : 0 0 0 0 0

Enter 5 integers: 1 2 3 4 5

After filling list1: 1 2 3 4 5

list2 : 1 2 3 4 5

Enter 3 elements: 8 9 10

First three elements of list1: 8 9 10

list3: 0 0 0 0 0 0 0 0

list3: 7 0 54 0 15 0 8 0

list 1 is not equal to list2

list 1 is not equal to list2

Press any key to continue . . .

Explanation / Answer

#include <iostream>
#include "myArray.h"

using namespace std;


int main()
{
myArray<int> list1(5);
myArray<int> list2(5);

int i;

cout << "list1 : ";
for (i = 0 ; i < 5; i++)
cout << list1[i] <<" ";
cout<< endl;

cout << "Enter 5 integers: ";
for (i = 0 ; i < 5; i++)
cin >> list1[i];
cout << endl;

cout << "After filling list1: ";

for (i = 0 ; i < 5; i++)
cout << list1[i] <<" ";
cout<< endl;

list2 = list1;
cout << "list2 : ";
for (i = 0 ; i < 5; i++)
cout << list2[i] <<" ";
cout<< endl;

cout << "Enter 3 elements: ";

for (i = 0; i < 3; i++)
cin >> list1[i];
cout << endl;

cout << "First three elements of list1: ";
for (i = 0; i < 3; i++)
cout << list1[i] << " ";
cout << endl;

myArray<int> list3(-2, 6);

cout << "list3: ";
for (i = -2 ; i < 6; i++)
cout << list3[i] <<" ";
cout<< endl;

list3[-2] = 7;
list3[4] = 8;
list3[0] = 54;
list3[2] = list3[4] + list3[-2];

cout << "list3: ";
for (i = -2 ; i < 6; i++)
cout << list3[i] <<" ";
cout<< endl;

   if (list1 == list2)
       cout << " list 1 is equal to list2 " << endl;
   else
       cout << " list 1 is not equal to list2" << endl;

   if (list1 != list2)
       cout << " list 1 is not equal to list2 " << endl;
   else
       cout << " list 1 is equal to list2" << endl;

//cout << list1<< (list1 == list2 ? " is equal to" : " not equal to ") << list2 << endl;
   //cout << list1<< (list1 != list2 ? " not equal to" : " is equal to ") << list2 << endl;

return 0;
}

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