Question

C++ LANGUAGE /** * Given an input string, count the number of words ending * in...

C++ LANGUAGE

/**

* Given an input string, count the number of words ending

* in 'y' or 'z' -so the 'y' in "heavy" and the 'z' in "fez"

* count, but not the 'y' in "yellow". Make sure that your

* comparison is not case sensitive. We'll say that a y

* or z is at the end of a word if there is not an alphabetic

* letter immediately following it.

*

* Do not use any string functions except for substr(),

* at(), and size(). You may use isalpha from cctype as well.

*

*  

* Here are some other examples:

* - "fez day" -> 2

* - "day fez" -> 2

* - "day fyyyz" -> 2  

*/

int endzy(const string& str)

{

int result;

  

// Your code goes here

  

return result;

}

I WILL VOTE THUMB IF ALL PASS

0 0
Add a comment Improve this question Transcribed image text
Answer #1
/**
* Given an input string, count the number of words ending
* in 'y' or 'z' -so the 'y' in "heavy" and the 'z' in "fez"
* count, but not the 'y' in "yellow". Make sure that your
* comparison is not case sensitive. We'll say that a y
* or z is at the end of a word if there is not an alphabetic
* letter immediately following it.
*
* Do not use any string functions except for substr(),
* at(), and size(). You may use isalpha from cctype as well.
*
*
* Here are some other examples:
* - "fez day" -> 2
* - "day fez" -> 2
* - "day fyyyz" -> 2
*/
int endzy(const string &str) {
    int result = 0;
    char ch;
    for (int i = 0; i < str.size(); ++i) {
        ch = str[i];
        if (ch >= 'A' && ch <= 'Z') {
            ch += 32;
        }
        if (i == str.size() - 1 || str[i + 1] == ' ') {
            if (ch == 'y' || ch == 'z') {
                result++;
            }
        }
    }
    return result;
}
Add a comment
Know the answer?
Add Answer to:
C++ LANGUAGE /** * Given an input string, count the number of words ending * in...
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
  • c++ int count(const string& str, char a); Write a recursive function that finds the number of...

    c++ int count(const string& str, char a); Write a recursive function that finds the number of occurrences of a specified letter in a string. For example,count("Welcome",’e’)returns 2.

  • Given a String str, and a char c return the number of times that c appears...

    Given a String str, and a char c return the number of times that c appears inside str. countChar("Abcdefg", 'a') returns 1 countChar("xxXx", 'x') returns 4 countChar("", 'q'') returns 0 ----------------- Please use java public class Count { public int countProblem(String str, char c) { int res = 0; //Your work is here return result; } }

  • using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings...

    using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, the ($) character represents a number between 1-9, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many...

  • ‘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...

  • I am having problems with the following assignment. It is done in the c language. The...

    I am having problems with the following assignment. It is done in the c language. The code is not reading the a.txt file. The instructions are in the picture below and so is my code. It should read the a.txt file and print. The red car hit the blue car and name how many times those words appeared. Can i please get some help. Thank you. MY CODE: #include <stdio.h> #include <stdlib.h> #include <string.h> struct node { char *str; int...

  • This CSIS 9 Python. Java Python Warmup-2 > string_times prev next | chance Given a string...

    This CSIS 9 Python. Java Python Warmup-2 > string_times prev next | chance Given a string and a non-negative int n, return a larger string that is n copies of the original string. string_times('Hi', 2) – 'HiHi' string_times('Hi', 3) - 'HiHiHi' string_times('Hi', 1) – 'Hi' Solution: Go Save, Compile, Run (ctrl-enter) Show Solution def string_times (str, n): def string_times(str, n): result = "" for i in range(n): # range(n) is [0, 1, 2, .... n-1] result = result + str...

  • Help C++ Write a string class. To avoid conflicts with other similarly named classes, we will...

    Help C++ Write a string class. To avoid conflicts with other similarly named classes, we will call our version MyString. This object is designed to make working with sequences of characters a little more convenient and less error-prone than handling raw c-strings, (although it will be implemented as a c-string behind the scenes). The MyString class will handle constructing strings, reading/printing, and accessing characters. In addition, the MyString object will have the ability to make a full deep-copy of itself...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

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