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

#include<iostream> using std::cout; using std::cin; using std:: ostream; using s

ID: 3614645 • Letter: #

Question

#include<iostream>
using std::cout;
using std::cin;

using std:: ostream;
using std::istream;
using std::endl;

class myOps
{
   

   public:


    int *x;
    int s;


        myOps()
        {
           x = new int;
           s = 100;
        }
        myOps(int *i, intsize)
        {
           x = i;
           s = size;
        }

  
        friend myOpsoperator+(myOps&, myOps&);
        friend myOpsoperator*(myOps&, myOps&);
        myOps operator=(myOpsop);
        friend ostream&operator<<(ostream& ,const myOps&);
        friend istream&operator>>(istream& ,const myOps&);
       
};

     

myOpsoperator+(myOps& op1, myOps& op2)
{
    myOps temp;

    for(inti = 0; i < op1.s; i++)
    {
        temp.x[i] = op1.x[i] +op2.x[i];
    }
    return temp;
}


myOps operator*(myOps& op1, myOps& op2)
{
    myOps temp;

    for(inti = 0; i < op1.s; i++)
    {
        temp.x[i] = op1.x[i] *op2.x[i];
    }
    return temp;
}

myOpsmyOps::operator=(myOps op)
{
    x = op.x;
    return *this;
}

ostream&operator<<(ostream& os, const myOps& mp){

          for(inti=0;i<mp.s;i++){
            
             os<<mp.x[i]<<endl;}
    return os;

}

istream&operator>>(istream& is, const myOps& mp){

    for(inti=0;i<mp.s;i++){
        cout << "Arrayelement["<<i<<"] : ";

       is>>mp.x[i];
  
    }

returnis;

}

int main()
{

   
   
    int size1, size2;
    cout << "Array Size One: ";
    cin >> size1;
    cout << "Array Size Two: ";
    cin >> size2;
    cout <<endl;

    int big= size2;
    if(size1>size2)
        big=size1;
  

    intconst size=big;


   
    int *num1 = new int[size1];
    int *num2 = new int[size2];
    int *result= new int[size];

  
   

    myOpsa(num1,big), b(num2,big),c(result,big);
    myOpsd(result,big),e(num1,size1),f(num2,size2);
  
   
   


  
    cout<<"Please enter the first arrayelements"<<endl;
    cin >>e;
    cout<<"Please enter the second arrayelemnents"<<endl;
    cin>>f;
   

    cout<< endl;

   d=a+b;
    cout << " Addition result : ";
    cout<<d;
   
   
    cout << " Multiplication result : ";
    c = a * b;

    cout<<c;
    return 0;
}

Explanation / Answer

Please rate! In case when the sizes of your array is not equal, make sure you'llchoose the smaller size. Let me illustrate to you what happens when you chose the bigone. array1 = [1,2,3] array2 = [2,4] Addition: result = [3,6,__] Multiplication: result = [2,8,__] The last entry of your array1 has not corresponding partner in yourarray2 and so the program will display an erroneous value. Whereas if you choose the smaller array as the size of your resultarray, the last element of array1 (3) will not be added to array2,as if 3 is not there. The result array would be: Addition: result = [3,6] Multiplication: result = [2,8] The could for that would be: int main() {     int size1, size2, small;     cout > size1;     cout > size2;     cout