Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CAUsersiphermander56Downloads PE03-SAMPLEPEO3-SAMPLEp2cpp-Se File Edit Search Vi

ID: 3753673 • Letter: C

Question

CAUsersiphermander56Downloads PE03-SAMPLEPEO3-SAMPLEp2cpp-Se File Edit Search View Tools Options Language Buffers Help 1 p2cpp 2 p1.cpp 1Finclude 2 #include 3 using namespace stdj sêfile p2.cpp 7 CS 150 PE03: INTERMEDIATE STRINGS/LOOPS 9Given an input string, count the number of words ending 10in y or 'z'-so the 'y in "heavy" and the 'z' in "fez" 11count, but not the 'y' in "yelLow". Make sure that your 12comparison is not case sensitive. We'LL say that a y 13or z is at the end of a word if there is not an alphabetic 15 14Letter immediately following it. 16Do not use any string functions except for substr), 17at(), and size(). You may use isalpha from cctype as well. 18 19 This is the most difficult problem in the set, 20 so do not start with this one. 21 22Here are some other examples: 23 24* 25* 26 27 int endzy(const string& str) 28 29 30 31 32 -"fez day"2 "day fez" > 2 - "day fyyyz"2 int result; I/ Your code goes here return result 34 25 + Compiles and runs + Correctness x decreasina"Chocolate 4: EATI

Explanation / Answer


Given below is the code for the 2 functions.
Please do rate the answer if it was helpful. Thank you


int endzy(const string &str){
int count = 0;
char c1, c2;
for(int i = 0; i < str.size(); i++){
c1 = str.at(i);
if(c1 == 'y' || c1 == 'Y' || c1 == 'z' || c1 == 'Z'){
if(i+1 < str.size()){ //not end of string
c2 = str.at(i+1);
if(!isalpha(c2))
count++;
}
else //end of input string and there is a y or z
count++;
}
}
return count;
}

string decreasing(const string &str, int n){
string output = "";
for(int i = n; i >= 1; i--){
output = output + str.substr(0, i);
}
return output;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote