Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please avoid using magic numbers in these functions. Use constants when appropriate. Integer Functions: 1. find - Accepts an integer array, its length, and a

Please avoid using magic numbers in these functions. Use constants when appropriate.

Integer Functions:

1. find - Accepts an integer array, its length, and a integer value to find. It returns true if value exists in the array. Otherwise it returns false if not found.

2. isSorted - Accepts an integer array and length. It determines if it is sorted in ascending numeric order. Returns true, if it is sorted or false if it is not.

3. mean - Accepts a float vector. This function returns the mean of the elements of the vector. Return 0 if the vector is empty.

4. stddev - Given a float array vector return the population standard deviation as a double (divide by N not N-1). Return 0.0 if the vector is empty. You may want use mean() function above.

5. removeDups - Accepts an int vector and returns a new vector. This function should return a new vector with all duplicate elements removed.

6. reverse - Accepts an integer vector. This function flips the order, so the first element becomes the last and the last, the first, etc. Returns nothing, but the provided vector will be changed. Should work for ANY sized vector.

String Functions:

1. countUpperCaseChars - Given a string, return the number of uppercase characters. Use isupper from the cctype library.

2. convertToUpper - Given an input string convert all alphabetic characters to uppercase. Return a new string converted to uppercase. If the input string is empty just return the input string.

3. removeSpaces - Given an input string remove all spaces from this string. Return a new string with spaces removed. If the input string is empty return the original string.

4. numWords - Given a string, return the number of words it contains. A word is defined to be a sequence of alphabetic (isalpha) characters with non-alphabetic characters on each side. If alphabetic characters start or end the string, they are considered a word. The best method to solve this is to use the isalpha function to determine the beginning and end of each string.

5. characterCounts - Given a string, return a vector of ints of length 26 containing the number of times each letter was seen. Index 0 corresponds to a, 1 to b, etc Treat upper-case letters as lower-case.

#include  #include  #include  #include  #include  #include  #include  #include  using namespace std; bool find(int array[], int length, int value){ // TODO: Fill me in } bool isSorted(int array[], int length){ // TODO: Fill me in } void reverse(vector  &reverse_me) { // TODO: Fill me in } float mean(const vector  values) { // TODO: Fill me in } float stddev(const vector  values) { // TODO: Fill me in // Should use mean above } vector removeDups(vector array){ // TODO: Fill me in // This is just to keep the compiler happy return vector(); } // Strings unsigned int countUpperCaseChars(const string &countme){ // TODO: Fill me in } unsigned int numWords(const string &countme){ // TODO: Fill me in } string convertToUpper(const string &to_be_converted){ // TODO: Fill me in } string removeSpaces(const string &remove_from_me){ // TODO: Fill me in } vector  characterCounts(const string &countme){ // TODO: Fill me in } template string print(vector vec); template string print(T array[], int length); int main(){ srand(time(0)); cout << "find:" << endl; int x1[10] = {1,2,3,5,5,6,7,8,9,0}; cout << "false/0 = " << find(x1, 10, 4) << endl; cout << "false/0 = " << find(x1, 10, 99) << endl; cout << "true/1 = " << find(x1, 10, 5) << endl; cout << "true/1 = " << find(x1, 10, 0) << endl; cout << "true/1 = " << find(x1, 10, 1) << endl; cout << "true/1 = " << find(x1, 10, 6) << endl; cout << endl; cout << endl; cout << "reverse:" << endl; vector  v1 = {1,2,3,4,5}; reverse(v1); cout << "[5,4,3,2,1] = " << print(v1) << endl; reverse(v1); cout << "[1,2,3,4,5] = " << print(v1) << endl; vector  v2 = {5}; cout << "[5] = " << print(v2) << endl; vector  v3 = {1,2,4,5}; reverse(v3); cout << "[5,4,2,1] = " << print(v3) << endl; vector  v4(100); v4[0] = 4; v4[1] = 2; reverse(v4); cout << "0 = " << v4[0] << endl; cout << "2 = " << v4[98] << endl; cout << "4 = " << v4[99] << endl; cout << endl << "mean:" << endl; vector  f1 = {1.2, 2.4, 3.4}; vector  f2 = {5.6, 5.6, 5.6, 5.6, 5.6, 5.6}; cout << "2.33 = " << mean(f1) << endl; cout << "5.6 = " << mean(f2) << endl; cout << endl << "stddev:" << endl; cout << "0.899 = " << stddev(f1) << endl; cout << "0 = " << stddev(f2) << endl; cout << endl << "removedups:" << endl; vector v5; v5.push_back(1); v5.push_back(2); v5.push_back(3); v5.push_back(3); v5.push_back(4); v5.push_back(5); v5.push_back(1); vector v12 = removeDups(v5); cout << "[1,2,3,4,5] = " << print(v12) << endl; cout << "5 = " << v12.size() << endl; vector v6; for(int i = 0; i < 100; i++){ v6.push_back(i%17 + i %7); } vector v22 = removeDups(v6); cout << "22 = " << v22.size() << endl; cout << " String Functions: " << endl; string upper_test = "aaABCdeFG"; cout << "countUpperCase" << endl; cout << "5 = " << countUpperCaseChars(upper_test) << endl; cout << "5 = " << countUpperCaseChars("AAAAA") << endl; cout << "0 = " << countUpperCaseChars("aaaaa") << endl; string no_upper_case = "aaaa"; cout << "0 = " << countUpperCaseChars(no_upper_case) << endl; cout << "RemoveSpaces:" << endl; string test1 = "aa AB Cd e FG"; string test2 = "aaAB Cd e FG "; string test3 = " rrAB Cd e FG"; string test4 = " rrAB Cd e FG "; cout << "aaABCdeFG = " << removeSpaces(test1) << endl; cout << "aaABCdeFG = " << removeSpaces(test2) << endl; cout << "rrABCdeFG = " << removeSpaces(test3) << endl; cout << "rrABCdeFG = " << removeSpaces(test4) << endl; return 0; } // A sneaky way to allow 1 function to print any typed array, as long as // the passed array element can be sent to <<. // The stringstream allows us to 'print' information to a fake output // stream, and then get the result as a string. It's a simple way of // getting a non-string/character into a string. // Contense of this function will not be tested in this course! template string print(vector vect) { stringstream out; out << '['; for(int i = 0; i < vect.size(); i++){ out << vect[i]; if(i != vect.size()-1)out << ','; } out << ']'; return out.str(); } template string print(T array[], int length){ stringstream out; out << '['; for(int i = 0; i < length; i++){ out << array[i]; if(i != length-1)out << ','; } out << ']'; return out.str(); } 

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

What is the effect of word war second?

Answered: 1 week ago

Question

4. Identify cultural variations in communication style.

Answered: 1 week ago

Question

9. Understand the phenomenon of code switching and interlanguage.

Answered: 1 week ago

Question

8. Explain the difference between translation and interpretation.

Answered: 1 week ago