Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

std::iota(begin, end, start); std::generate(begin, end, fn); string::substring(start, length); std::sort(begin, end); std::min_element(begin, end); string::find(what , start = 0) string::find_first_of(char , start); all_of(begin, end, pred); any_of; none_of;

std::iota(begin, end, start); std::generate(begin, end, fn); string::substring(start, length); std::sort(begin, end); std::min_element(begin, end); string::find(what , start = 0) string::find_first_of(char , start); all_of(begin, end, pred); any_of; none_of; find(begin, end, item); find_if(begin, end, fn); find_if_not; count(begin, end); count_if(begin, end, fn); newend = remove(begin, end); newend = remove_if(begin, end, fn); copy(begin, end, target); copy_if(begin, end, target, fn); copy_n(begin, n, target); reverse(begin, end); fill(begin, end, value); fill_n(begin, n, value); std::array; std::map; std::map::count(key); std::back_inserter(vec); std::ifstream; std::ofstream; std::stringstream; std::getline(stream, variable); std::ostream_iterator(stream, separator); std::istream_iterator(stream); std::async(func, params...); std::exception; std::accumulate(begin, end, start)

Question 1: Answer the following questions briefly. a. What is the advantage of generic programming? [3 points]

b. What is argument dependent lookup? Why it is useful. [2 points]

c. Fill the following table as true or false. Wrong answers will count against you. [each question is 2 points]

1. When deriving from multiple classes, you should always use virtual inheritance

2. Move semantics allow non-copyable classes to be used with containers 3. Unary operator overloads must be member functions 4. You should never overload binary operators (&, | and )

5. std::map keeps its members sorted by their key 6. In C++ you can only throw objects derived from std::exception

Question 2: Write the template function Cube which returns x . [4 points]

Question 3: Trace the following code and write the output into the provided space. Answers without intermediate

steps will not get any grade.

1. std::vector v;

2. std::string s;

3. std::fill_n(std::back_inserter(v.begin()), 5, -1);

4. int i = 0;

5. for(auto &val : v) {

6. s += std::to_string(val + i++);

7. }

8. std::reverse(s.begin(), s.end());

9.std::cout << s;

Question 4: Write NP (numeric pair) template class that will hold two instances of the given type (x and y). Write default, copy and move constructors; a constructor that takes x and y values, copy assignment, + operator that adds x and y values of the left and right sides separately, and comparison operator which checks if x and y are the same for left and right sides. Additionally, add a function call operator which will return the summation of the two variables. Use const in places that are needed. [10 points]

Question 5: Write a single line answer for the following requests over vector v that contains an unknown number of integer values. You are not allowed to use loops. Hint: List of STL algorithms is given at the top of the first page. [each question is 2 points]

a. Find the and display first value that is not divisible by 3.

b. Count the elements that are divisible by 3.

c. Print out the elements that are divisible by 3.

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

Managing Your Information How To Design And Create A Textual Database On Your Microcomputer

Authors: Tenopir, Carol, Lundeen, Gerald

1st Edition

1555700233, 9781555700232

More Books

Students also viewed these Databases questions

Question

13-4 What are alternative methods for building information systems?

Answered: 1 week ago

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago