//The wrong code here is the present number of times
#include<iostream>
#include<cstring>
#include<algorithm>
#include<string>
usingnamespace std;
char ltr;
string phrase;
int main()
{
cout << "Enter a string: ";
getline(cin, phrase);
cout << "Enter character to search: ";
ltr = isalpha(phrase[1000]);
cin >> ltr;
cout << "The given string is: " << phrase;
cout << "\nGiven character is " << ltr;
cout << "\nPresent number of times: " << strlen(isalpha(phrase[1000]));
//for (int i = 0; i < strlen(phrase); i++){
// cout << isalpha(phrase[i]);
//}
system("pause>0");
return 0;
}
//this is a fixed code.. no need to change
#include<iostream>
#include<string>
usingnamespace std;
string phrase;
int numspaces = 0;
char nextChar;
int main()
{
cout << "Enter a line of text: ";
getline(cin, phrase);
cout << "Given string: " << phrase;
for (int i = 0; i<int(phrase.length()); i++)
{
nextChar = phrase.at(i);
if (isspace(phrase[i]))
numspaces++;
}
cout << "\nNumber of words: " << numspaces+1;
system("pause>0");
return 0;
}
#include<iostream>
#include<string>
usingnamespace std;
char phrase[1000];
int n(0), k(0), d(0), e(0), f(0);
int main()
{
cout << "Enter a string: ";
cin.getline(phrase, 1000);
cout << "\n";
cout << "No. of uppercase: ";
for (int i = 0; i < strlen(phrase); i++){
if (isupper(phrase[i]))
n++;
}
cout << n;
cout << "\nNo. of lowercase: ";
for (int i = 0; i < strlen(phrase); i++){
if (islower(phrase[i]))
k++;
}
cout << k;
cout << "\nNo. of digits: ";
for (int i = 0; i < strlen(phrase); i++){
if (isdigit(phrase[i]))
d++;
}
cout << d;
cout << "\nNo. of others: ";
for (int i = 0; i < strlen(phrase); i++){
if (ispunct(phrase[i]))
e++;
}
for (int i = 0; i < strlen(phrase); i++){
if (isspace(phrase[i]))
f++;
}
cout << e+f;
system("pause>0");
return 0;
}