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

Exercise 1: Implement the Array class that is defined below and test it in the m

ID: 3864079 • Letter: E

Question

Exercise 1: Implement the Array class that is defined below and test it in the main program. The main program must test all the functions that are defined in the class. ifndef array h #define array h class Array Class declaration public: Array (int 5) Initialize the array with 0 values Array (const Array & copy constructor -Array //destructor bool set Value (int index, int value) assign a value to an //array element bool getValue (int index, int &value;) get an array element Array & increment cascade function to increment each array element by 1 int getsize return the size of the array. void print const print each element of the array Array& Add (const Array ar) casade function to add all elements of arr to all elements of the this array (element by element) and return a reference to the resulting array bool Equal (const Array *ar) const; return true if all elements in both arrays are equal, false otherwise. Array& removeAt (int

Explanation / Answer

Answer:

#include <cstdio>
#include <limits>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
class Array
{
public :int n1;
int a;
Array(int n){
n1=n;
}
~Array();
void setvalue(int val){
a=val;
}
int getvalue(){
return a;
}
   void increament(Array obs[],int n);
int getsize(Array obs[],int n);
void print(Array obs[],int n);
int add(Array obs[],int n);
int equal(Array obs[],Array obs1[],int n);
void removeAt(int i,Array obs[]);
void insertAt(int i,int val,Array obs[]);
  

  
};
void Array:: increament(Array obs[],int n) {

for(int i=0;i<n;i++){
obs[i].getvalue()+1;
}

}

int Array::getsize(Array obs[],int n) {
return n;
}
void Array::print(Array obs[],int n) {
  
for(int i=0;i<n;i++){
cout<<obs[i].getvalue()<<" ";
}
}
int Array::add(Array obs[],int n){
int sum;

for(int i=0;i<n;i++){
sum=sum+obs[i].getvalue();
}
return sum;
}
int Array::equal(Array obs[],Array obs1[],int n){

int f=0;
for(int i=0;i<n;i++){
if(obs[i].getvalue()!=obs[i].getvalue())
f=1;
}
if(f==1)
return 0;
return 1;
}
void Array::removeAt(int i,Array obs[]){
obs[i].setvalue(0);
}
void Array::insertAt(int i,int val,Array obs[]){
obs[i].setvalue(val);
}
int main(){
int n;
cout<<"Enter the size of array"<<endl;
cin>>n;
Array *obs;
obs =new Array(n);
for(int i=0;i<n;i++){
obs[i].setvalue(5);
}
obs[1].increament(obs,n);
obs[1].getsize(obs,n);
obs[1].print(obs,n);
obs[1].add(obs,n);
obs[1].removeAt(1,obs);
obs[1].insertAt(1,6,obs);
}