Answer:
The C++ code is given below with appropriate comments
Explanation:
#define CATCH_CONFIG_MAIN //This tells Catch to provide a main()
#include"catch.hpp" //Header for Catch Framework
double FinalAvg( vector <int> students) // Function to calculate average.
{
double sum =0;
int i;
for( i=0;i<v.size();i++) sum+= v[i];
return v.empty() ? 0.0 : (double(sum)/ v.size());
}
vector<int> func(int argvq[ ]) // This function is made because we can not provide vector in command line argument that's why we used array which is then conerted into vector.
{
vector<int> v;
int j;
int l= sizeof(argvq)/sizeof(argvq[0]);
for(j=0;j<l;j++)
v.push_back(argq[j]);
return v;
}
TEST_CASE(" Final Average marks are computed","[func]") // TEST_ CASE macro to take one or more arguments
{
REQUIRE( func(9,5,-7) == 7); // We write our individual test assertions using the REQUIRE macro.
REQUIRE(func(2,4,6,-2) ==4);
}
Explanation Using different IDE:
#include<bits/stdc++.h>
using namespace std;
double FinalAvg(vector<int> students)
{
double sum=0;
for(int i=0;i<v.size();i++) sum+= v[i];
return v.empty() ? 0.0 : (double(sum)/v.size());
}
int main()
{
vector<int> v;
int i;
while(cin>>i&&i>0) v.push_back(i);
cout<<Final Avg(v);
return 0;
}