Question: 1. Correct the logic/syntax error in the code below to produce the correct output, WITHOUT CHANGING ITS FLOW. 2. Explain in detail the reason/concept behind

1. Correct the logic/syntax error in the code below to produce the correct output, WITHOUT CHANGING ITS FLOW.

2. Explain in detail the reason/concept behind the error.

THE PROGRAM SHOULD PRINT THE AVERAGE OF VECTOR ELEMENTS, WHOSE SIZE AND TYPE ARE DEFINED BY THE USER.

1. Correct the logic/syntax error in the code below to produce the

CODE FOR REFERENCE

#include

using namespace std;

template

class A{

vector B;

A(vector C ){

B=C;

}

public:

Avg avg(){

Avg sum = 0;

for(int i=0;i

sum += this->B[i];

return sum/B.size();

}

};

int main(){

// the type of this vector should be defined by user input, by "cin>>"

vector numbers; // or vector ??

A a(numbers);

int size;

int val;

cout

cin>>size;

cout

for(int i=0;i

cout

cin>>val;

numbers.push_back(val);

}

cout

return 0;

}

Labs + Prac - TempArrAvg.cpp

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!