Provide an implementation of the mymaximum function whose


Exercise 1: Finding the maximum value

int mymaximum(int a[], int numberOfElements);

Provide an implementation of the mymaximum function whose declaration is shown above. The first argument of the function is an array of int and the second argument is the number of ints that are in the array. The function returns the largest int that is in the array.

Write test code that thoroughly tests the function. The test code should use assertions.

Exercise 2: Appending integers

void append(vector & v, int n);

Provide an implementation of the function whose declaration is shown above. The first argument of the function is a vector of int and the second argument is the number of consecutive integers to append to the vector starting from 0 and ending at n - 1. The function appends onto the vector v the values 0, 1, 2, ..., n - 1. (Hint: use the push_back function of vector to append these values to v.)

Write test code that thoroughly tests the function. The test code should use assertions.

Exercise 3: Appending vectors

void appendVector(vector & v, const vector & w);

Provide an implementation of the appendvector function whose declaration is shown above. Both arguments of the function are vectors of int. The function should modify vector v by appending to it all the elements of w. For example, if v = (4, 2, 5) and w = (11, 3), then v will become (4, 2, 5, 11, 3) as a result of calling the function. Hint: the vector class has a function called push_back that appends values passed into it.

Exercise 4: Vector insertion

Suppose a vector v contains a sequence of integers ordered from lowest to highest. For example, v might contain the values 3, 6, 7, 12.

Write a function called insert that takes this vector v as a first argument and an integer k as the second argument. The function inserts k into the vector so that it preserves the order of elements. For example, if v were (3, 6, 7, 12) and k were 8, then after calling the function, v would be (3, 6, 7, 8, 12). In your implementation of insert, do not use the insert function of the vector class (v.insert).
Write test code that thoroughly tests the function. The test code should use assertions.

Exercise 5: Counting occurrences

int countOccurrences(const vector & v, int k);
Implement the function countoccurrences whose declaration appears above. The first argument of the function is a vector v of integers and the second argument is an integer k. The function returns the number of times k occurs in v.

Exercise 6: Two-dimensional arrays

bool isAllZeros(int a[50][100]);

Implement the function isAllZeros that uses a loop nested inside another loop to determine whether a 2-dimensional array contains only zeros. A declaration of the function is shown above. The array passed into the function will have 50 rows and 100 columns.

Exercise 7: Identical Vectors

bool areIdentical(const vector & a, const vector & b);

Write a predicate function that checks whether two vectors are identical (contain exactly the same elements in the same order). A declaration of the function is shown above. The function returns true if the two vectors are identical; otherwise it returns false.

Exercise 8: Unlucky Vectors

bool isUnlucky(vector & v);

Implement a function that determines if the unlucky number 13 appears in a vector. The function returns true if 13 appears in the vector at least once; otherwise it returns false. Write test code that tesets every statement in the function. Use assertions in your test code.

Exercise 9: Ordered Vectors

bool isStrictlyIncreasing(const vector & v);

Write a predicate function called isStrictlylncreasing that checks whether a vector of integers contains values that are in strictly increasing order. A declaration of the function is shown above. The function returns true if the elements are in strictly increasing order; otherwise it returns false. For example, it will return true for v = (2, 4, 5, 6, 8) and it will return false for (3, 4, 6, 6, 9).

Exercise 10: Flatten

vector flatten(int a[100][200]);

Write a function named flatten that takes a 2-dimensional array of integers with 100 rows and 200 columns and returns a vector that contains all of the array's elements. Copy the values a row at a time. In other words, first copy row 0 into the vector, then row 1, then row 2, and so on. The declaration of flatten is given above.

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Provide an implementation of the mymaximum function whose
Reference No:- TGS01037363

Expected delivery within 24 Hours