美文网首页
第二章 实践大题

第二章 实践大题

作者: 陈靖靖靖靖 | 来源:发表于2016-04-16 11:03 被阅读6次

    首先

    我发现这个东西根本不需要团队合作啊..除了那个高级功能我完全不知道应该怎么做,虽然可能知道一点,但是因为GUI技术是在太太太,算了,就根本没有所以难以实现

    然后

    先附上三个基本功能的函数:


    // Count the chars num
    int CharCount(char* filename)
    {
    int num = 0;
    string s;
    ifstream fp(filename);
    
    if (!fp.is_open())
    {
        cout << "Error opening file" << endl;
        exit(1);
    }
    
    while (getline(fp, s))
        num += s.size();
    
    fp.close();
    
    return num;
    }
    

    //Count the words num
    int WordCount(char* filename)
    {
    int num = 0;
    string s, str;
    ifstream fp(filename);
    
    if (!fp.is_open())
    {
        cout << "Error opening file" << endl;
        exit(1);
    }
    
    while (getline(fp, s))
    {
        istringstream ss(s);
    
        while (ss >> str)
            if(!(str[0]>='0' && str[0]<='9'))
            num++;
    }
    
    fp.close();
    
    return num;
    }
    

    //Count the lines num
    int LineCount(char* filename)
    {
    int num = 0;
    string s;
    ifstream fp(filename);
    
    if (!fp.is_open())
    {
        cout << "Error opening file" << endl;
        exit(1);
    }
    
    while (getline(fp, s))
        num++;
    
    fp.close();
    
    return num;
    }
    

    然后拓展功能懒得贴了,说一下主要思路
    代码行:字符大于1就可以了且如果含有注释的话那就要更大一点
    注释行:如果含有//或者/的而且其他字符数量小于等于1*
    空行:字符小于等于1即可


    主函数:妈妈我会用命令行参数啦!!!

    #include"functions.h"
    
    int main(int argc, char* argv[])
    {
    if (argv[1][1] == 'c')
    {
        int num = CharCount(argv[2]);
        cout << "Char nums is " << num << '\n' << endl;
    }
    else if (argv[1][1] == 'w')
    {
        int num = WordCount(argv[2]);
        cout << "Word nums is " << num << '\n' << endl;
    }
    else if (argv[1][1] == 'l')
    {
        int num = LineCount(argv[2]);
        cout << "Line nums is " << num << '\n' << endl;
    }
    else
        cout << "Wrong Input!!!" << endl;
    
    system("pause");
    }

    相关文章

      网友评论

          本文标题:第二章 实践大题

          本文链接:https://www.haomeiwen.com/subject/uaonlttx.html