Question
Write a function called compute_average that takes a vector as an argument, and returns the average of the values in the vector. I will provide
Write a function called compute_average that takes a vector
your compute_average.cpp should #include your compute_average.h
the header file should NOT contain a using statement
in your header file, all STL types must be prefaced with "std::"
your header file should guard against being #include'd twice.
compute_average.h
#ifndef COMPUTE_AVG_H #define COMPUTE_AVG_H #include "compute_average.h" #include
compute_average.cpp
#include
#include"compute_average.h"
double compute_average(std::vector
return sum; }
exercise_4.7.cpp
#include
#include
#include "compute_average.h"
using namespace std;
int main()
{
vector
double x;
while (cin >> x)
{
v.push_back(x);
}
cout << "Average : " << compute_average(v) << ' ';
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started