This is the simple and logic building C++ programming exercise. The program will count the number of characters in string in C++ program. The program will display each character along with its occurrence in the string.
Source Code
#include <iostream>
#include "fromMain.cpp"
using namespace std;
int main(int argc, char** argv) {
string sentence;
int count=0;
int a;
char c1;
fromMain obj_m;
cout<< "Enter a sentence with \".\" at End"<<endl;
getline(cin,sentence,'.') ;
for(int i=65;i<123;i++){
if(((i>64)&&(i<91))||((i>96)&&(i<123))){
if(i==97){
cout<<endl;
}
cout<< (char)i<< " = ";
for(int j=0;j<sentence.length();j++){
a=sentence[j];
if(a==i){
count=count+1;
}
}
cout<<count<< " | ";
}
count=0;
}
return 0;
}
0 comments:
Post a Comment