C++ Program to count lines,words and characters of a string
#include <iostream>
using namespace std;
class countli
{
char c;
int lines,words,chars;
public:
void input()
{
cout<<"Enter string termanate by # : ";
}
void operation()
{
lines=1;
words=1;
chars=1;
while(c != '#'){
cin.get(c);
chars++;
if(c==' ' || c=='\n')
words++;
if(c=='\n')
lines++;
}
}
void output()
{
cout<<"No. of lines"<<lines<<endl;
cout<<"No. of words"<<words<<endl;
cout<<"No. of characters"<<chars<<endl;
}
};
int main()
{
countli a;
a.input();
a.operation();
a.output();
return 0;
}
No comments:
Post a Comment