用户操作
[留言]  [发消息]  [加为好友] 
订阅我的博客
XML聚合    FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
hhuc05的公告
文章分类
    存档

    原创  江苏省计算机考试二级VC++历年真题啊(06春上机2) 收藏

    第二题:

    /*建立一个类。统计一个英文字符串中的英文的单词个数,字符串中的各
    各英文单词以一个或者多个空格隔开。如I am a student中的单词为4
    */
    #include<iostream.h>
    #include<string.h>
    class WORD
    {
     char str[80];
     int c;
    public:
     WORD(char *s);
     void process();
     void print();
    };
    WORD::WORD(char *s)
    {
     strcpy(str,s);
     c=0;
    }
    void WORD::process()

    {
     char *p=str;
     while(*p)
     {
      while(*p==' ')p++;c++;
      while(*p!='\0'&&*p!=' ')p++;
     }
    }


    void WORD::print()
    {
     cout<<str<<endl;
     cout<<"c="<<c<<endl;
    }
    void main()
    {
       WORD w("she ia a nice girl!");
       w.process();
       w.print();

    发表于 @ 2008年03月09日 20:46:00 | 评论( loading... ) | 编辑| 举报| 收藏

    新一篇:江苏省计算机考试二级VC++历年真题啊(06春上机08)

    • 发表评论
    • 评论内容:
    •  
    Copyright © hhuc05
    Powered by CSDN Blog