Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write this function in c++.Use of string and is not allowed .You are required to use char*. Gtest cases to pass: Q2.1 TEST(Question2_1, First) {

Write this function in c++.Use of string and is not allowed .You are required to use char*.

Gtest cases to pass:

Q2.1

TEST(Question2_1, First) { char s[]="This is a test String"; int* arr; int size; countLetters(s,arr,size); /* arr should contain the frequency of characters given in sequence of original character array. i-e Index 0 contains frequency of 'T' //case sesitive Index 1 contains frequency of 'h' Index 2 contains frequency of 'i' Index 3 contains frequency of 's' Index 4 contains frequency of ' '(space) Index 5 contains frequency of 'a' and so on */ ASSERT_EQ(1,arr[0]); ASSERT_EQ(1,arr[1]); ASSERT_EQ(3,arr[2]); ASSERT_EQ(3,arr[3]); ASSERT_EQ(4,arr[4]); ASSERT_EQ(1,arr[5]);

}

TEST(Question2_1, second) { char s[]="Hello World"; int* arr; int size; countLetters(s,arr,size); /* arr should contain the frequency of characters given in sequence of original character array. i-e Index 0 contains frequency of 'H' //case sesitive Index 1 contains frequency of 'e' Index 2 contains frequency of 'l' Index 3 contains frequency of 'o' Index 4 contains frequency of ' '(space) Index 5 contains frequency of 'W' and so on */ ASSERT_EQ(1,arr[0]); ASSERT_EQ(1,arr[1]); ASSERT_EQ(3,arr[2]); ASSERT_EQ(2,arr[3]); ASSERT_EQ(1,arr[4]); ASSERT_EQ(1,arr[5]);

}

int main(int argc, char **argv) {

testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS(); }

Q2.2

TEST(Question2_2, First) { char s1[]="This is a test String New Line"; int* arr1; int size1; countWordsBasedOnLength(s1,arr1,size1); /* arr should contain the frequency of words as given. i-e Index 0 contains frequency of spaces Index 1 contains frequency of length 1 words/characters except space Index 2 contains frequency of length 2 words Index 3 contains frequency of length 3 words and so on */ ASSERT_EQ(7,size1); ASSERT_EQ(7,arr1[0]); ASSERT_EQ(2,arr1[1]); ASSERT_EQ(1,arr1[2]); ASSERT_EQ(1,arr1[3]); ASSERT_EQ(3,arr1[4]); ASSERT_EQ(1,arr1[6]);

}

TEST(Question2_2, second) {

char s[]="Hello World"; int* arr; int size; countWordsBasedOnLength(s,arr,size); /* arr should contain the frequency of words as given. i-e Index 0 contains frequency of spaces Index 1 contains frequency of length 1 words/characters except space Index 2 contains frequency of length 2 words Index 3 contains frequency of length 3 words and so on */ ASSERT_EQ(6,size); ASSERT_EQ(1,arr[0]); ASSERT_EQ(0,arr[1]); ASSERT_EQ(0,arr[2]); ASSERT_EQ(0,arr[3]); ASSERT_EQ(0,arr[4]); ASSERT_EQ(2,arr[5]);

}

int main(int argc, char **argv) {

testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS(); }image text in transcribed

0 3 of 5 a Assignment_1_Spr2020.pdf 78.3% Q - X Q2: Text Analysis The availability of computers with string-manipulation capabilities has resulted in some rather interesting approaches to analyzing the writings of great authors. This exercise examines three methods for analyzing texts with a computer. You have to use char * for the following exercises. 1. Write a function that receives a string consisting of several lines of text and returns an array indicating the number of occurrences of each letter of the alphabet in the text. For example, the phrase "To be, or not to be that is the question": contains one "a," two "b's." no "c's," and so on. 1 void count Letters (char *string int *&array, int & size) 2 Parameters: 3 Input: 4 char *: a multiline string 5 Output: 6 int *: an array containing counts of each letter, 7 to be allocated in function 8 int : array size */ 91 10 2. Write a function that receives a string consisting of several lines of text and returns an array indicating the number of one-letter words, two-letter words, three letter words, and so on, appearing in the text. For example, the phrase "Whether this nobler in the mind to suffer contains 2. 3. 4. etc. length words. 1 void count Words Base dOnLength(char *string int *array/*to be allocated */ 2 int & size /* updated array size*/) 3 Parameters: 4 Input 5 char * : a multi-line string 6 Output: 7 int*: an array containing counts of each different length words, 8 to be allocated in function 9 int : array size */ 10 { 11 3. Write a function that receives a string consisting of several lines of text and returns arrays indicating unique words and the number of occurrences of each unique word in the text along with their size. 1 void counting Unique Words (char *string , char **&uwords/ list of unique words:*/ 2 int *karray /*to be allocated */ int & size /*updated array size*/) 3 Parameters 4 Input 5 char * : a multiline string 6 Output: 7 char **: an array of unique words 8 int *: their counts 9 int : number of unique words */ 10 1 11 } 0 3 of 5 a Assignment_1_Spr2020.pdf 78.3% Q - X Q2: Text Analysis The availability of computers with string-manipulation capabilities has resulted in some rather interesting approaches to analyzing the writings of great authors. This exercise examines three methods for analyzing texts with a computer. You have to use char * for the following exercises. 1. Write a function that receives a string consisting of several lines of text and returns an array indicating the number of occurrences of each letter of the alphabet in the text. For example, the phrase "To be, or not to be that is the question": contains one "a," two "b's." no "c's," and so on. 1 void count Letters (char *string int *&array, int & size) 2 Parameters: 3 Input: 4 char *: a multiline string 5 Output: 6 int *: an array containing counts of each letter, 7 to be allocated in function 8 int : array size */ 91 10 2. Write a function that receives a string consisting of several lines of text and returns an array indicating the number of one-letter words, two-letter words, three letter words, and so on, appearing in the text. For example, the phrase "Whether this nobler in the mind to suffer contains 2. 3. 4. etc. length words. 1 void count Words Base dOnLength(char *string int *array/*to be allocated */ 2 int & size /* updated array size*/) 3 Parameters: 4 Input 5 char * : a multi-line string 6 Output: 7 int*: an array containing counts of each different length words, 8 to be allocated in function 9 int : array size */ 10 { 11 3. Write a function that receives a string consisting of several lines of text and returns arrays indicating unique words and the number of occurrences of each unique word in the text along with their size. 1 void counting Unique Words (char *string , char **&uwords/ list of unique words:*/ 2 int *karray /*to be allocated */ int & size /*updated array size*/) 3 Parameters 4 Input 5 char * : a multiline string 6 Output: 7 char **: an array of unique words 8 int *: their counts 9 int : number of unique words */ 10 1 11 }

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

Discuss various types of training methods.

Answered: 1 week ago

Question

Question Can a self-employed person adopt a profit sharing plan?

Answered: 1 week ago