Question

In: Computer Science

The following program is used to sum arrays. Fill in blanks of the following program to...

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;

}

Solutions

Expert Solution

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 :


Related Solutions

Fill in the blanks: Consider the following equilibrium and fill in the blanks with either increase...
Fill in the blanks: Consider the following equilibrium and fill in the blanks with either increase or decrease. I2(s) + 5F2(g) ⇌ 2IF5(g) A decrease in volume results in a Blank 1 in pressure which will Blank 2 the amount of IF5.
Fill in the blanks on the following table
 Fill in the blanks on the following tableE&pshareholder basisdistributiondividendreturn of capitalcapital gain20,000300,00080,000120,00010,000170,000220,000100,000170,00020,000080,000<20,000>50,000170,000
Given the following program with fill in the blanks, implement the PQ class which is priority...
Given the following program with fill in the blanks, implement the PQ class which is priority Queue MAX heap; the higher the number, the higher the prority of that number. None of the public methods has been implemented. You will need to write other methods to help implement some of the methods. For example you will need to implement bubbleUp to help with the insert method. Methods to implement: insert -> insert one element into the PQ and maintain heap...
Fill in the blanks below with the following terms. (some terms will be used more than...
Fill in the blanks below with the following terms. (some terms will be used more than once and other terms will not be used at all) (Acetylcholine, Cholecystokinin, Gastric Inhibitory Peptide (GIP), Gastrin, Glucagon-Like Peptide 1, Histamine, Secretin, Somatostatin, chylomicrons, HDLs, LDLs, VLDLs, Cephalic, Gastric, Intestinal,) a. __VLDLs__ are low density lipoproteins carrying more triglycerides than cholesterol. b. ________, _________ and __________ are secreted into the bloodstream in response to amino acids in the digestive tract. c. __________, __________ and...
Fill in the blanks in each of the following statements
Fill in the blanks in each of the following statementsa) --------- allows you to build JavaFx GUIS using drag and drop techniques.b) The elements in the scene graph are called --------------c) A(n) ----------- file contains the description of a JavaFX GUI.d) The method ---------------- is called by FMXLLoader before the GUI is displayed
Fill in the blanks with an appropriate suggestion for the following.
Fill in the blanks with an appropriate suggestion for the following.(i) If there is no trade-off involved when we get a good, then it is called a _______________ good.(ii) If expected future price falls for a good, it's current demand _____________________ .(iii) Pencil and erasers are a pair of ___________________goods for consumers
Fill in the blanks to complete the following table.
Fill in the blanks to complete the following table.SymbolIon FormedNumber of Electrons in IonNumber of Protons in IonF__________9Te_____54_____II−_______________Mg2+_____12Part AComplete the first column of the table.Express your answer as a chemical symbol.Part BComplete the second column of the table.Express your answer as ions. Enter your answers in order given in the table, from top to bottom, separated by a comma.Part CComplete the third column of the table.Express your answer as integers. Enter your answers in order given in the table, from...
C++ Fill in the blanks please You are required to fill in the blanks in this...
C++ Fill in the blanks please You are required to fill in the blanks in this program. Consider that: -In main, the variables price and quantity were given the names of p (double) and q (int), respectively. -In the getData function, the parameters associated with the main variables p and q were called pp and pq, respectively. // Prototype: Do not include the names // of the variables in the prototype void getData (FILLTHEBLANK , FILLTHEBLANK); int main () {...
Use the following words to fill in the blanks, some may be used more than once...
Use the following words to fill in the blanks, some may be used more than once or not at all: Increase; Decrease; Greater Than; Less Than; Equal; System; Effusion; Enthalpy; Diffusion; Entropy; Mass; Volume; Density; Heat; Temperature; State; Calorimeter; Specific Heat; Gas; Extensive; Intensive, surrounding A. Calorimetry is possible because all the energy which leaves the _________ is absorbed by the _________, and vice versa B. When volume is held constant, the term for work goes to zero, which allows...
Fill in the blanks with the following numbers, not the words, for this and all the...
Fill in the blanks with the following numbers, not the words, for this and all the questions that follow. Jot them down so you won't have to keep scrolling up to the top to see what they are: Demand = 1 Supply = 2 Right = 3 Left = 4 Up = 5 Down = 6 QUESTION 6 Suppose the dollar were to strengthen in international currency markets. That is, the price of the dollar, in terms of other national...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT