Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please write in C++ Given a list of random numbers, compute the sum of these numbers. You may not use a for-loop to solve this

Please write in C++

Given a list of random numbers, compute the sum of these numbers. You may not use a for-loop to solve this problem.

Starter Code:

#include  #include  #include  #include  #include  #include  static int getRandomNumber(); template std::ostream& operator<<(std::ostream& out, std::vector list) { out << "["; for (const auto& val : list) { out << val << ", "; } out << "]"; return out; } int main() { std::vector list; std::generate_n(std::back_inserter(list), 20, []() { return getRandomNumber(); }); std::cout << list << " "; // TODO: compute the sum of the numbers in the list and print it out // NOTE: no for loops, use algorithms } static int getRandomNumber() { static std::mt19937 rng{ std::random_device{}() }; static std::uniform_int_distribution rand{ 0, 100 }; return rand(rng); } 

Sample Output:

[10, 1, 93, 97, 30, 60, 97, 65, 55, 99, 52, 5, 76, 85, 25, 49, 49, 37, 22, 8, ] 1015

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

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago