Write a class Array that contains an array of integers as data member. The class contains the following member functions:
- A constructor that initializes the array elements to -1.
- Input function to input the values in the array.
- Show function to display the values of the array.
- Overload == operator to compare the values of two objects. The overloaded function returns 1 if all values of both objects are same and returns 0 otherwise.
Problem: I can't figure out how to compare using == operator.
My code:
#include<iostream>
using namespace std;
#define SIZE 10
class array{
public:
int arr[SIZE];
public:
array(){
for (int i = 0; i < SIZE; i++){
a[i] = -1;
}
}
void input(){
- cout << "Enter values";
for (int i = 0; i < SIZE; i++){
cout << "Enter value number" << i + 1;
cin >> arr[i];
}
}
void show(){
for (int i = 0; i < SIZE; i++){
cout << arr[i];
}
}
bool operator==(array& p) const
{
bool result = true;
if (p.a != arr)
result = false;
return result;
}
};
int main(){
array arr, b, c;
a.input();
b.input();
a.show(); b.show();
return 0;
}