In: Computer Science
The following program is used to sum arrays. Fill in blanks of
the following program to complete the program and make the output
is: s = 150.
#include <iostream.h>
class Arr {
int *a,n; public:
Arr():a(0),n(0){} Arr(int *aa, int nn)
{n=nn;
a=new int [n];
for(int i=0;i<nn;i++) *(a+i)=*(aa+i); }
~Arr(){delete a;} _____________
{return *(a+i);} };
void main() {
int b [5]={10,20,30,40,50}; Arr a1(b,5);
int i=0,s=0;
_____________ s+=a1.GetValue(i);
cout<<"s="<<s<<endl;
}
C++ program :
#include <iostream>
using namespace std;
class Arr { //C++ class
int *a,n;
public:
Arr():a(0),n(0){}
Arr(int *aa, int nn)
{
n=nn;
a=new int [n];
for(int i=0;i<nn;i++)
*(a+i)=*(aa+i);
}
~Arr(){delete a;}
int GetValue(int i) //method to get the
value
{return *(a+i);}
};
int main() {
//declaring array
int b [5]={10,20,30,40,50};
Arr a1(b,5);
int i=0,s=0;
for(i=0;i<5;i++)s+=a1.GetValue(i);
cout<<"s="<<s<<endl;
return 0;
}
=======================================
Output :