Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Object Oriented Deductive Hypermedia Technologies

Authors: Kamran Parsaye, Mark Chignell, Setrag Khoshafian, Harry Wong

1st Edition

0471503452, 978-0471503453

More Books

Students also viewed these Databases questions

Question

7. How might you go about testing these assumptions?

Answered: 1 week ago