Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Not sure what is causing my code to get the wrong answers? I had to follow theses functions than ran the code for the tests

Not sure what is causing my code to get the wrong answers?

I had to follow theses functions than ran the code for the tests below

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.

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 #include using namespace std; bool find(int array[], int length, int value){ for(int i=0;i { if(array[i]==value){ return true; } } return false; } bool isSorted(int array[], int length){ for(int i=0;i for(int j=i+1;i if(array[i]>array[j]){ return false; } break; } } return false; } void reverse(vector &reverse_me){ vector v1(reverse_me.size()); int c=0; for(int i=reverse_me.size()-1;i>=0;i--) { v1[c]=reverse_me[i]; c++; } reverse_me = v1; } float mean(const vector values) { float tot=0.0; for(int i=0;i tot+=values[i]; } float Me = tot/values.size(); return Me; } float stddev(const vector values) { int s = values.size(); float Di; float add2=0; float Mean2 = mean(values); for ( int i = 0; i { add2 += pow((values[i]-Mean2),2); } Di= sqrt(add2/(s)); return Di; } bool myfunction (int i, int j) { return (i==j); } vector removeDups(vector array) { int tp=0; vector v1(array.size()); for(int i=0;i { int co = 0; for(int j=i+1;j if(array[i]==array[j]){ co++; } } if(co==0){ v1[tp]=array[i]; tp++; } } return v1; } unsigned int countUpperCaseChars(const string &countme) { int c=0; for(int i=0;i { if(isupper(countme[i])){ c++; } } return c; } unsigned int numWords(const string &countme) { int co=0; for(int i=0;i if(isspace(countme[i])){ co++; } } return co; } string convertToUpper(const string &to_be_converted){ string n1; for(int i=0;i if(isalpha(to_be_converted[i])) { n1[i] = toupper(to_be_converted[i]); }else { n1[i] = to_be_converted[i]; } } return n1; } string removeSpaces(const string &remove_from_me) { string n1; for(int i=0; remove_from_me[i]; i++) if(remove_from_me[i] == ' '){ }else { n1[i] = remove_from_me[i]; } return n1; } vector characterCounts(const string &countme){ vector v1(countme.size()); int c=0; for(int i=0;i { if(isalpha(countme[i])){ v1[c]= countme[i]; c++; } } return v1; } template string print(vector vec); template string print(T array[], int length); int main(){ srand(time(0)); cout

image text in transcribedimage text in transcribed

1: numWords: 1 We have seven words in this sentence Test feedback numNords returned 6 when it should have returned seven 2: numWords: 2 0/2 one word only. Test feedback numWords returned: 0 when it should have returned one 3: Numwords: 3 A 0/2 This paragraph contains twenty-three words and three lines of text.InThis is a new sentence.InThis is a new sentence as well Test feedback numords returned: 21 when it should have returned twenty-three 4: NumWords: 4 0/2 this sentence has multiple spaces in odd places and the word count is fourteen. Test feedback numWords returned: 28 when it should have returned fourteen

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