part 4 C++ A sample run should appear on the screen like the text below. Enter a
ID: 3938100 • Letter: P
Question
part 4
C++
Explanation / Answer
#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]!='')
{
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....
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.