The goal of this assignment is to give you some practice writing simple C++ programs and to check your knowledge of some of the main concepts from:Β arrays and strings.
Which of the following is the correct way to declare a two-dimensional array called "my_grid" with the capacity to store a 3 by 5 table of integer values?
Write a function array_sum that takes two arguments: an integer array called βnumsβ and an integer called βsizeβ representing the number of values stored in the array. The function accumulates the sum of the values in the βnumsβ array and returns that sum. If size < 1, the function returns 0.
Write a function array_max that takes one argument: a two-dimensional array of integers βarrβ which will always have 3 rows and 5 columns. The functionΒ returns the largest element in the array.
Write a function unique_elements that takes an array of integers βarrβ and an integer βsizeβ (the size of βarrβ). The function returns true if there are no repeated elements in arr, otherwise it returns false.
Write a function count_evens that takes an array of integers βarrβ and an integer βnβ. The function returns an integer indicating the number of even elements among the first n elements of βarrβ.
Write a function count_occurrences that takes an array of integers βarrβ, an integer βsizeβ, and an integer βnβ. The function returns an integer indicating the number of occurrences of the value βnβ among the first size-many elements in βarrβ.
For example, if arr = [3, 3, 5, 3, 3, 2, 8], then count_occurrences(arr, 3, 5) returns 1 since there is one β5β in [3, 3, 5], and count_occurrences(arr, 6, 3) returns 4 since there are four 3βs in [3, 3, 5, 3, 3, 2].
Write a function last_index that takes an array of integers βarrβ, an integer βsizeβ, and an integer βnβ. The function returns an integer indicating the LARGEST index i such that i < size and arr[i] equals n.Β If there are no occurrences of βnβ among the first size-many elements of βarrβ, the function returns -1 to indicate "n not found".
Suppose we have included the string class header file (#include <string>), declared a variable βsβ of type string, and assigned a value to s. For example:
Write a complete C++ program that reads a line of input and prints it out; however, if the string that was read is more than 20 characters long (including whitespace characters), the message "too long" is printed instead.
The end of the input is signaled by the user hitting the "enter" key, which creates a β\nβ character at the end of the input. Note that the newline character β\nβ is discarded, it does not become part of the string which is read.
The βfindβ method in the string class takes a substring and a position in the original string and finds the first occurrence of the substring, starting from the given index.Β If the substring is not found, what is returned by the βfindβ method?
Write a complete C++ program that reads from a comma-separated string of name values (entered by standard input) and prints each name on its own line. The end of the CSV input will be signaled by two commas in a row.
Write a function second_half that has one argument, βinput_stringβ, of type string and returns a string that is the second half of βinput_stringβ. Whether βinput_stringβ has an even length, 2n, or an odd length, 2n+1, the return string will always have length n. (The center character is not included in the second half for odd-length strings.)
second_half("Piggy") returns "gy" (input length is 2*2 + 1, output length is 2).