Question: Revise the following short and ugly program so that it uses a lambda expression instead of the Adder functor. Dont change sum(). #include #include const

Revise the following short and ugly program so that it uses a lambda expression instead of the Adder functor. Don’t change sum().
#include
#include
const int Size = 5;
template

void sum(std::array a, T& fp);
class Adder
{
double tot;
public:
Adder(double q = 0) : tot(q) {}
void operator()(double w) { tot +=w;}
double tot_v () const {return tot;};
};
int main()
{
double total = 0.0;
Adder ad(total);
std::array temp_c = {32.1, 34.3, 37.8, 35.2, 34.7};
sum(temp_c,ad);
total = ad.tot_v();
std::cout << "total: " << ad.tot_v() << '\n';
return 0;
}
template
void sum(std::array a, T& fp)
{
for(auto pt = a.begin(); pt != a.end(); ++pt)
{
fp(*pt);
}
}

Step by Step Solution

3.43 Rating (188 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

include include const int Size 5 template void sumstdarr... View full answer

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 Introduction Java Program Questions!