part 4 C A sample run should appear on the screen like the t


part 4
C++

A sample run should appear on the screen like the text below. Enter a number: 3 Enter a number: 10 Enter a number: 2 Enter a number: -213 Output: The largest positive number you entered was 10. Write a full program that asks the user to enter a phrase and then a single letter. The program should then report how many times that letter occurred in the phrase, displaying the letter with double quotes around it. An example is shown below where the user searched for lower-case \"g\". Enter phrase: I love programming languages! Enter letter: g The letter \"g\" occurred 4 times. Your program does not have to check upper versus lower case.

Solution

#include <iostream>
#include <string>
#include<stdio.h>
using namespace std;
int main ()
{
string phrase;
char c;
int i=0;
static int oc=0;
cout << \"Enter phrase:\"<<endl;
getline (cin,phrase);
cout<<\"Enter Letter:\"<<endl;
c=getchar();
//Below code is for occurence of Letter in String using case-sensitive
while(phrase[i]!=\'\\0\')
{
   if(c==phrase[i])
   {
       oc++;
   }
   i++;
}
cout << \"The Letter \\\"\"<<c<<\"\\\" Occured\" <<oc<< \"times\"<<endl;
return 0;
}

Hi friend, I have written code for find the number of occurence of Letter in user entered String (matching contain case-sensitivity because in your example you mentioned you are counting occurence of small g).But if you need your programme ignore case-sensitivity for counting the occurence of letter please write me.

Thanks....

 part 4 C++ A sample run should appear on the screen like the text below. Enter a number: 3 Enter a number: 10 Enter a number: 2 Enter a number: -213 Output: Th

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site