Let's Get Functional

Let's Get Functional

<p> CST223 Lab #4 Let's get functional</p><p>Functional programming is a different way to solve problems. While some modern programming languages are not known as functional languages, but they have incorporated functional programming paradigm via libraries. </p><p>In this lab, we will explore some functional style of programming available in the C++ standard library. No explicit recursions! For these three functions, you will need to #include <algorithm> and #include <numeric>. These functions are in the std namespace so you’ll want to do using appropriately. </p><p>Please review the powerpoint slides on these functions first. You are welcome to use the C++ standard library class vector and iterators for these questions if you want, but regular arrays and pointers work just as well. </p><p>Problem Set #1: Function Pointers</p><p>For the following problems, you need to create functions and pass function pointers to for_each, accumulate or transform algorithms. 1. Create an array and fill it with some numbers. Use for_each function to multiply 5 to each number in an array. 2. Use for_each function to print out all even numbers in an array of numbers. 3. Use for_each function to add 1 to each number in the first half of the array and use another for_each function to add 2 to each number in the second half of the array. 4. Use accumulate to find the maximum value in an array of numbers. 5. Use accumulate to count the number of 7’s in an array of numbers. 6. Use accumulate to add up all the ASCII values in a character array. 7. Use transform to add 5 to each number in the input array. 8. Use transform that takes two input arrays and multiplies the values together and store in the output array. 9. Use transform to find the number of 5’s in an array of number. (Hint: use bool or int array as the output)</p><p>Problem Set #2: Functions and adapters Solve the same problems above, except instead of passing function pointers, use function objects, lambda expressions, TR1::functions or function adapters. </p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    1 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us