Assume the existence of a class Arr with two public data mem

Assume the existence of a class Arr with two (public) data members: a pointer to integer named arr_ptr, and an integer variable named length that will contain the number of elements in the array . Assume the variable a has been declared to be of type Arr, an array has been allocated and assigned to arr_ptr, and length has been assigned the proper value (i.e., the number of elements in the array ). Write the code to add 1 to each element of the array .

Solution

you can simply use the below code

for (int i = 0; i < a.len; i++) //here len means length

{


a.arr_ptr[i] += 1;


}

Assume the existence of a class Arr with two (public) data members: a pointer to integer named arr_ptr, and an integer variable named length that will contain t

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site