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

Guidelines ? Code should be properly aligned and well commented. ? Follow c/c++

ID: 3619521 • Letter: G

Question

Guidelines
? Code should be properly aligned and well commented.
? Follow c/c++ rules while writing variables names, function names etc
? Use only dev-C++ for this assignment.


Problem Statement: Multiplication of two objects of same class
· You are required to write a class. Class should have an array of 10 integers as its private data member.

Class should have

A default constructor which will initialize all array elements with zero.
Getter and setter functions
An operator overloading function which will overload * operator for this class.


You are required to create three objects of the same class.
You must assign values to first and second objects through setter functions. You can either take input arrays from user or use hard coded values.
Display the values of first and second object through getter functions.
Multiply both objects and store the result of multiplication in third object.
Multiplication means the 1st element of member array of object1 should be multiplied by 1st element of member array of object2. Similarly, 2nd element should be multiplied with 2nd and so on. In the end, display the result stored in third object.
Your program should support the statement like a = b * c, where a, b and c are objects of the same class.


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

Sample output:

Object 1 :

1

2

3

4

5

6

7

8

9

10



Object 2 :

10

9

8

7

6

5

4

3

2

1



Multiplication of both objects :

10

18

24

28

30

30

28

24

18

10

Explanation / Answer

#include <iostream>
using namespace std;
class array
{public:
array()
{int i;
for(i=0;i<10;i++)
    num[i]=0;
}          
void Inputc();
void Outputc();
array operator*(array);
private:
int num[10];
};


array array::operator *(array x)
{array temp;
int i;
for(i=0;i<10;i++)
    temp.num[i]=num[i]*x.num[i];
return(temp);}
void array::Inputc(void)
{int i;
for(i=0;i<10;i++)
    {cout<<"enter element "<<i+1<<": ";
     cin>>num[i];
     }
}
void array::Outputc(void)
{int i;
for(i=0;i<10;i++)
     cout<<num[i]<<endl;
}    
int main()
{array a,b,c;
cout<<"enter elements for 1st array: ";
a.Inputc();
cout<<"enter elements for 2nd array: ";
b.Inputc();
c=a*b;
cout<<"Object 1 : ";
a.Outputc();
cout<<"Object 2 : ";
b.Outputc();
cout<<"Multiplication of both objects : ";
c.Outputc();
system("pause");
return 0;
}