answersLogoWhite

0


Best Answer

#include<iostream>

#include<vector>

class foo {

private:

static std::vector<size_t> evens;

public:

static bool add_number (size_t num);

static size_t sum();

static std::vector<size_t>& get_evens () { return evens; }

};

bool foo::add_number (size_t num) {

if ((num%2)==0) { evens.push_back (num); return true; }

return false;

}

size_t foo:sum () {

size_t sum {0};

for (auto num : evens) sum+= num;

return sum;

}

int main () {

size_t in;

while (std::cin >> in) {

foo::add_number (in);

}

for (auto num : foo::get_evens()) std::cout << num << std::endl;

std::cout << "Sum = " << foo::sum() << std::endl;

}

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a C plus plus program for calculating the sum of even numbers entered by user using static data and static member functions?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is c program to calculate product of all even numbers from entered number down to 1?

c is programming laungage


What is a program that allows a user to enter rows and columns of numbers into main memory and to perform calculations on the numbers that have been entered?

The program is a Spreadsheet. eg Microsoft Excel


The menu bar provides access to a program's functions through?

Commands provide access to a program's functions.


Shell program for calculating compound interest using for loop?

yes


What is a function in spreadsheet program?

Spreadsheet is a computer program used for calculating, organising, analysing data, and display results


How does one use french letters on Windows without downloading a program?

You can use Alt codes, which are codes that can be entered by holding down the Alt key as you enter numbers on the numpad.


What is quicken loans mortgage?

Quicken loans mortgage is basically a program that Quicken made that deals with mortgage. Those functions include keeping track of rates and calculating the projected cost of a house, car, or any thing with a loan or mortgage.


What is 357 x 74?

Hmm, if only the computer had some kind of calculating program...


The max number of functions you have used in a c program?

There is no limit to the number of functions you can have in a program. The only practical limit is dependant upon the amount of memory you have available in order to load the compiled program, whether it has 4 functions or 4 trillion functions. If the program makes use of dynamic libraries, then the amount of available memory reduces accordingly.


Why you divide a program into functions?

In order to make a large program more manageable, it is convenient to identify and isolate specific tasks that a program performs and to separate out those tasks into functions. These functions are used/invoked as needed by the main part of the program. They can also be invoked by other functions. Often a program will perform the same task in different parts of the program. Using a function to perform the task and invoking the function from the different parts of the program means that only one copy of the code is needed. This helps reduce the size of the program.


What is the importance of functions in a c plus plus program?

Functions are very important in C++, as you can't write the simplest program to print hello without using a function. Overall you can say that function are building blocks of a C++ program. Functions can also be defined by the programmer to reduce program size.


What is the importance of using functions in a c program?

C programs do not function without functions.