Question

C++ 1) Write a function named WordCount, which determines the number of words in a “C...

C++

1) Write a function named WordCount, which determines the number of words in a “C type” string. The function will have one parameter (the address of the string) and will return the number of words (words are separated by one or more spaces). (15 points)

2) Write a function named VowelConsonant which will have three parameters - all “C type” strings. The function will place all vowels (the characters a, e, i, o, u) from the first string into the second string and all consonants from the first string into the third string. Assume the size of each string is sufficient hold the characters. Case of letters is not significant. (15 points)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1) int WordCount(char *a)

{

        int Countwords = 0; //Holds count of words      
        for(int i = 0; a[i] != '\0'; i++)
        {
                if (a[i] == ' ') //Checking for spaces
                {
                        words++;
                }               
        }
return words++;// coz last word will terminate without space
        }

2) void VowelConsonant(char *s1,char *s2,char *s3)

{

for(int i = 0; s1[i] != '\0'; i++)
        {
                if (s1[i] == 'a'|| s1[i] == 'e'||s1[i] == 'i'||s1[i] == 'o'||s1[i] == 'u')//Checking for vowels
                {
                s2=s2+s1[i];
                s1.erase (i,1);
               
                }               

else

{

             
                s3=s3+s1[i];
                s1.erase (i,1);

}

        }

}

Add a comment
Know the answer?
Add Answer to:
C++ 1) Write a function named WordCount, which determines the number of words in a “C...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 2) Write a function named VowelConsonant which will have three parameters - all "C type" strings....

    2) Write a function named VowelConsonant which will have three parameters - all "C type" strings. The function will place all vowels (the characters a, e, i, o, u) from the first string into the second string and all consonants from the first string into the third string. Assume the size of each string is sufficient hold the characters. Case of letters is not significant. (15 points)

  • Write a function named words_in_both that takes two strings as parameters and returns a set of...

    Write a function named words_in_both that takes two strings as parameters and returns a set of the words contained in both strings. You can assume all characters are letters or spaces. Capitalization shouldn't matter: "to", "To", "tO", and "TO" should all count as the same word. The words in the set should be all lower-case. For example, if one string contains "To", and the other string contains "TO", then the set should contain "to". The file must be named: words_in_both.py...

  • Write a function named words_in_both that takes two strings as parameters and returns a set of...

    Write a function named words_in_both that takes two strings as parameters and returns a set of the words contained in both strings. You can assume all characters are letters or spaces. Capitalization shouldn't matter: "to", "To", "tO", and "TO" should all count as the same word. The words in the set should be all lower-case. For example, if one string contains "To", and the other string contains "TO", then the set should contain "to". You can use Python's split() funciton,...

  • I need this in Visual Studio C++ Write a function that count the number of vowels,...

    I need this in Visual Studio C++ Write a function that count the number of vowels, the number of consonants and the average number of letters in each word. The function accept a C-String (char array) or a string object as an argument and return the number of vowels, number of consonants and the average number of letters in each word. Problem: Requirements: . Use pointers as part of the solution Read a string from a text file. . Write...

  • Write a function called most_consonants(words) that takes a list of strings called words and returns the...

    Write a function called most_consonants(words) that takes a list of strings called words and returns the string in the list with the most consonants (i.e., the most letters that are not vowels). You may assume that the strings only contain lowercase letters. For example: >>> most_consonants(['python', 'is', 'such', 'fun']) result: 'python' >>> most_consonants(['oooooooh', 'i', 'see', 'now']) result: 'now' The function that you write must use a helper function (either the num_vowels function from lecture, or a similar function that you...

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

  • Write a C program that will produce the EXACT output shown below. Write a program to...

    Write a C program that will produce the EXACT output shown below. Write a program to find out the number of words, spaces, vowels, consonants, along with special characters in a sentence. Take the data below as an example. Your C program should take the data in the arrays and produce the output below, neatly formatted as shown Enter a sentence: My cat’s name is Bella. You sentence includes:             Number of words: 5             Number of spaces: 4            ...

  • write a function firstLetterWords(words) that takes as a parameter a list of strings named words and...

    write a function firstLetterWords(words) that takes as a parameter a list of strings named words and returns a dictionary with lower case letters as keys. But now associate with each key the list of the words in words that begin with that letter. For example, if the list is ['ant', 'bee', 'armadillo', 'dog', 'cat'], then your function should return the dictionary {'a': ['ant', 'armadillo'], 'b': ['bee'], 'c': ['cat'], 'd': ['dog']}.

  • Write a class StringsAndThings. The class has one instance variable of type String and a constructor...

    Write a class StringsAndThings. The class has one instance variable of type String and a constructor with a parameter to initialize the instance variable. The parameter could contain any characters, including letters, digits, spaces, special characters (+, -, $, @,...), and punctuation marks. Write methods: countNonLetters - that will count how many of the characters in the string are not letters. You can use Character's isLetter method. moreVowels - which returns true if the String parameter has more vowels than...

  • In the space below, write a C function definition for a function named StrLower, which will...

    In the space below, write a C function definition for a function named StrLower, which will receive one parameter, a pointer to a null-terminated string (i.e., pointer to char), convert each character in the string to lowercase (using the tolower function from <ctype.h>), and return nothing to the caller. Inside the function definition, you may use a for loop or a while loop. If you use any variables other than the incoming parameter, you must define them locally in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT