Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

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.

image text in transcribed

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

Step: 1

blur-text-image
Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students explore these related Databases questions