Question: Complete the functions given in Array1D class so that main should work properly. #include using namespace std; // Your Task : //=========== //complete the functions

Complete the functions given in Array1D class so that main should work properly.

#include

using namespace std;

// Your Task :

//===========

//complete the functions given in Array1D class so that main should work properly.

class Array1D

{

public:

int arr[10];

Array1D()

{

for (int i =0 ; i < 10 ; i++)

{

arr[i] == 0;

}

}

int operator[] (int k); // dipslay array element at index k .

// k should in the range otherwise display index out of range error

void operator += (int v); // add a value v in all elements of array

friend ostream& operator << (ostream& o , Array1D a); // display array

friend istream& operator >> (istream& o , Array1D a); // input array elements from user

};

int main()

{

Array1D num;

cin >> num ; // inout array elements e.g 2,3,4,5,6,7,8,9,10

cout << num; // display array elements . output -> 2,3,4,5,6,7,8,9,10

cout << num[3]; // show element at index 3 . output -> 5

cout << num[10]; //output -> Index out of range error

num += 3;

cout << num ; // output -> 5,6,7,8,9,10,11,12,13

}

INPUT IS ALWAYS 10 ELEMENTS

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!