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

can someone help me create this for studying my upcoming test so i can pratice w

ID: 3890174 • Letter: C

Question

can someone help me create this for studying my upcoming test so i can pratice with it . here are the instructions.

-----------------------

Each problem appears in its own file, p1.cpp and p2.cpp. Each file contains a single void function (p1Main and p2Main). These are "IPO" programs. However, the only thing that you will do is the processing portion of the program. The input and output are already completed. Do not do any printing or input other than that that already appears. Place your code where directed, and do not change any of the existing code outside of the marked section.

Both problems are taken from the sample code you received. P1 – simple iteration can be solved with a single loop (usually a "for" loop). P2 – intermediate iteration will require one or more loops in combination with several selection statements

--------------------------------------------------------------------------------------------------------------------------------------

p1

----------------------------

#include <iostream>
#include <string>
using namespace std;
/**
* @file p1.cpp
*
* CS 150 PE03: 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"
*/
void p1Main()
{
cout << "Enter a string: ";
string str;
getline(cin, str);
cout << "Enter an int from 0.." << str.length() << ": ";
int n;
cin >> n;
  
string result = "";
// ---- YOUR CODE GOES ONLY BELOW THIS LINE

  
// ---- YOUR CODE GOES ONLY ABOVE THIS LINE
cout << endl // make sure on last line
<< "After processing: ["" << result << ""]" << endl;
}

--------------------------

p2.cpp

---------------------------

#include <iostream>
#include <cctype>
#include <string>
using namespace std;
/**
* @file p2.cpp
*
* CS 150 PE03: 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 length(). You may, however, use the <cctype>
* classification functions, such as isdigit() and isalpha().
*
* 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
*/
void p2Main()
{
cout << "Enter a string: ";
string str;
getline(cin, str);
  
int result = -1;
// ---- YOUR CODE GOES ONLY BELOW THIS LINE

  
// ---- YOUR CODE GOES ONLY ABOVE THIS LINE
cout << endl // make sure on last line
<< "Number of words ending in y or z is [" << result << "]" << endl;
}

-----------------------------------------------------------------------------------------------

Chrome File Edit View History Bookmarks People Window Help Ocs 1 50-23378 C++ x.Rcs 150 (70 unread) .

Explanation / Answer

p1.cpp

#include<iostream>
#include<string>

using namespace std;

int main()
{
    cout << "Enter a string: ";
    string str;
    getline(cin, str);
    cout << "Enter an int from 0.." << str.length() << ": ";
    int n;
    cin >> n;
    string result = "";
    for (int i = n; i>=0; i--){
        result = result + str.substr(0,i);
    }

    cout << endl // make sure on last line
       << "After processing: ["" << result << ""]" << endl;
    return 0;
}

p2.cpp

#include<iostream>
#include<string>
#include <sstream>

using namespace std;

int main()
{
    cout << "Enter a string: ";
    string str;
    getline(cin, str);
    string word;
    int n;

    istringstream is(str);
    int result = 0;
   
    while (is >> word){
        n = word.size()-1;
        if (word[n] == 'y' || word[n] == 'Y' || word[n] == 'z' || word[n] == 'Z')
           result++;
    }
    cout << endl   // make sure on last line
         << "Number of words ending in y or z is [" << result << "]" << endl;
     return 0;
}

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