#include
using namespace std;
class STR {
private:
char* s; int m, n;
public:
STR(char* t) {
s = new char[strlen(t) + 1];
strcpy(s, t);
m = 0; n = 0;
}
void fun() {
char* p = s;
while (*p)
{
if (*p ==' ' || *p == ',' || *p == '.')m++;
if (*p == '.')n++;
p++;
}
}
void print() {
cout << "字符串:" << s << endl;
cout << "句子数:" << n << endl;
cout << "单词数:" << m << endl;
}
~STR() { delete[]s; }
};
void main()
{
char a[200] = "i am a student. i am twenty. i come from china.";
STR text(a);
text.fun();
text.print();
}