Answer to Question #247592 in C++ for Flyyboyy

Question #247592
You have been contracted by client to develop a program using c++. The Program must have the
following specifications.
The program must:
a. Allow the user to enter the full name of the university - “Ghana Communication Technology
University”.
b. Print the entire name for the university.
c. Count the number of ‘e’ in “Ghana Communication Technology University” and display.
d. Print the last 21 characters in “Ghana Communication Technology University”.
e. Replace the string “Ghana” in “Ghana Communication Technology University” with “Accra”
and print the new name.
1
Expert's answer
2021-10-06T16:33:25-0400
#include<iostream>
using namespace std;
int main()
{
string Name;
cout << "Enter the full name of the university: ";
getline (cin, Name);
cout << "Your name is: " << Name;
string str = Name;
    char checkCharacter = 'e';
    int count = 0;


    for (int i = 0; i < str.size(); i++)
    {
        if (str[i] ==  checkCharacter)
        {
            ++ count;
        }
    }
cout << "\nNumber of " << checkCharacter << " = " << count<<endl;
cout <<"The last 21 characters of the string are: "<<Name.substr(Name.length() - 21) << endl;
string str1 = Name;  
string str2 = "Accra";   
str1.replace(0,5,str2);   
cout << "String after replacement is: "<<str1<<"\n";  
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS