Question: Code in C++ Pls post pdf file and .h file Your solution should not be OS dependent, please only include libraries that are part of

Code in C++ Pls post pdf file and .h file

Your solution should not be OS dependent, please only include libraries that are part of the C++ standard. General Requirements For each of the functions described in questions 1 to 6 you are to:

1. Modify the function to count the number of operations performed when the function executes. Some questions will specify whether this is for the worst or best case. See the section on counting operations below for more detail.

2. Determine a detailed cost function for the function. This function should be written in the form wnx + yn + z where w, x, y and z are real numbers and n is a variable referring to the size of the function's input. If necessary, you should adapt this format to include other terms such as log2(n).

3. Identify (one of) the barometer operations for the function.

4. Identify the O notation running time of the function. Note that questions 3 and 5 have additional or different requirements. Counting Operations If the function return type void it should be modified to return the count of its operations; if the function already has a return value, the count should be assigned to an integer reference parameter. This reference parameter should always be the last parameter in the function's parameter list. When counting operations follow these rules.

An executable statement (a line of code that ends in a semi-colon) or a comparison counts as one operation regardless of its complexity see exceptions 2 and 5. Therefore, the statement x = 4; counts as a single operation as does the statement int w = x + y + z;.

Exception to 1 if a statement includes a function call that does not run in constant time its operation count should be the number of operations performed by that function call. This only applies to questions 5 and 6.

Note to 1 and 2 statements that include the output operator (<<) follow rule 1 not rule 2. That is, an output statement that uses cout counts as a single operation regardless of its complexity. If it also includes unrelated function calls then rule 2 applies.

The execution of an if statement or while loop comparison counts as one operation. Make sure that you count comparisons that result in false as well as true so don't forget to include the terminating comparison for while loops. Note that there are no for loops in any of the functions as this allowed me to simplify these instructions somewhat.

Return statements should not be included in the operation count

Question 1 This function prints the Cartesian product of its input array with itself.

Notes The function should be modified to return the operation count as an integer

Question 2 This function prints a triangle of numbers (which doesn't look very pretty if the numbers have more than one digit).

Notes The function should be modified to return the operation count as an integer

Question 3 This function returns a vector which contains the contents of its input array with any duplicates removed.

Notes The function should be modified to include an integer reference parameter the value of which should be set to the operation count

Answer questions 2 to 4 of the General Requirements for both the worst-case and best-case running times of the function, and

Describe, and give examples of input that constitutes the best and worst case for the algorithm

The size and push_back methods of a vector run in constant time, therefore lines that include calls to these methods still only count as a single operation as per rule 1

Question 4 This function returns an array in dynamic memory that represents the matrix that is the result of multiplying the matrix (array) parameter by itself.

The function should be modified to include an integer reference parameter the value of which should be set to the operation count

The input size is the number of rows of the matrix

Lines that include call(s) to the rcIndex function (which has a constant time complexity) still only count as a single operation as per rule 1

Question 5 This function is a recursive version of selection sort.

Notes Answer questions 2 to 4 of the General Requirements for the best-case running time of the function

Answer questions 3 and 4 (not 2) for the worst-case running time of the function

Describe, and give an example of input that constitutes the best and worst case for the algorithm 4. Do not count the actual call to a recursive function as an operation that is you

Notes

Note the cost of printing the spaces

Do not count the actual call to a recursive function as an operation that is you must include the number of operations performed by the recursive call as per rule 2, but the call itself does not count as an operation Submission Details You should submit two files.

A .h file named a3.h. This should contain your version of the functions (amended to calculate the operation count). This file should not include a main function.

A .pdf file that contains your solutions. For each question show the amended function (which you can copy and paste from your program file) followed by your answers to parts 2 to 4 of the General Requirements and your answers to additional requirements (i.e. for questions 3 and 5). Note that you can save a Word document as a .pdf file. Basic Test A main function that calls a simple test function is provided below. If your solution does not compile with this test it will not compile with our (more in-depth) testsmust include the number of operations performed by the recursive call as per rule 2, but the call itself does not count as an operation Question 6 This function prints a pattern.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!