C++ Program #include using std::string; /** * Problem 1: Simple strings & loops * * Given a string and an int n, create a new string * made of the first n characters of the original * string, followed by the first n-1 characters of * the original string, and so on. You may assume * that n is between 0 and the length of the string, * inclusive (i.e. n >= 0 and n <= str.length()) * * Some examples: * "Chocolate", 4 -> "ChocChoChC" * "Chocolate", 3 -> "ChoChC" * "Ice Cream", 2 -> "IcI" */ string decreasing(const string& str, int n) { string result = "not done"; // Add your code here return result; } /** * Problem 2: Intermediate Strings & Loops * * 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(), and isalpha() from . * * This is the most difficult problem in the set, * so do not start with this one. * * Here are some other examples: * - "fez day" -> 2 * - "day fez" -> 2 * - "day fyyyz" -> 2 */ int endzy(const string& str) { int result; // Add your code here return result; }
C++ Program
#include <string>
using std::string;
/**
* Problem 1: Simple strings & loops
*
* Given a string and an int n, create a new string
* made of the first n characters of the original
* string, followed by the first n-1 characters of
* the original string, and so on. You may assume
* that n is between 0 and the length of the string,
* inclusive (i.e. n >= 0 and n <= str.length())
*
* Some examples:
* "Chocolate", 4 -> "ChocChoChC"
* "Chocolate", 3 -> "ChoChC"
* "Ice Cream", 2 -> "IcI"
*/
string decreasing(const string& str, int n)
{
string result = "not done";
// Add your code here
return result;
}
/**
* Problem 2: Intermediate Strings & Loops
*
* 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(), and isalpha() from <cctype>.
*
* This is the most difficult problem in the set,
* so do not start with this one.
*
* Here are some other examples:
* - "fez day" -> 2
* - "day fez" -> 2
* - "day fyyyz" -> 2
*/
int endzy(const string& str)
{
int result;
// Add your code here
return result;
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps