Question
Use the given code to Integer Functions: 1. find - Accepts an integer array, its length, and a integer value to find. It returns true
Use the given code to
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 and its length, return the population standard deviation as a double (divide by N not N-1). Return 0.0 if the array 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
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
float mean(const vector
float stddev(const vector
vector
// 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
template
template
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
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
template
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started