面向对象程序设计 第三次作业补充

Github链接:https://github.com/zora02/object-oriented/tree/master/Caculator(更改)

作业准备

说实话寒假打代码的时候没有认真的看过代码规范,当时觉得能把代码打出来就很开心了(´・_・`)。这几天认真的看了代码规范,感觉还是有所收获。(虽然有些内容我们现在还用不到,但是以后肯定是能用到的。)看完代码规范后对自己的代码做了一些修改。但是没有特别大的改动,主要是一些格式上的修改。还有就是注释方面我还是不很清楚,不知道该怎么注释比较合适正确,所以本来想修改一下自己的注释,但是不知道该怎么改orz。。。所以我没有改,如果这个被扣分,我认了>_<

修改后的代码

main.cpp

#include <iostream>
#include <string>
#include <queue>
#include <stdlib.h>
#include "Scan.hpp"
#include "Print.hpp"
using namespace std;


int main()
{
    string s;
    cin >> s;
    Print :: PrintQueue(Scan :: ToStringQueue(s));
}

Scan.cpp

#include "Scan.hpp"
#include <iostream>
#include <string>
#include <queue>
#include <stdlib.h>
using namespace std;

bool Scan::checkNum(char c)
{
    return ('0' <= c && c <= '9') || c == '.'; //判断数字或者是小数点
}
queue<string> Scan::ToStringQueue(string s)
{
    int len = s.size();
    string tem_s;
    queue<string> q;
    for (int i = 0 ; i < len;)
    {
        tem_s.clear();
        if (!checkNum(s[i])) //判断是符号还是数字
        {
            tem_s += s[i++]; //符号
        }
        else
        {
            while (i < len && checkNum(s[i]))
            {
                tem_s += s[i++]; //数字
            }
        }
        if (tem_s.size() > 10)
        {
            cout << "Error" << endl;
            exit(0); //报错
        }
        q.push(tem_s);
    }
    return q;
};

Scan.hpp

#ifndef Scan_hpp
#define Scan_hpp
#include <iostream>
#include <string>
#include <queue>
#include <stdlib.h>
using namespace std;

class Scan
{
    public :
    static bool checkNum(char c);

    static queue<string> ToStringQueue(string s);
    
    queue<string> q;
  
};


#endif /* Scan_hpp */

Print.cpp

#include "Print.hpp"
#include <iostream>
#include <string>
#include <queue>
#include <stdlib.h>
using namespace std;

void Print::PrintQueue(queue<string> q)
{
    while (!q.empty())
    {
        cout << q.front() << endl, q.pop();
    }
};

Print.hpp

#ifndef Print_hpp
#define Print_hpp
#include <iostream>
#include <string>
#include <queue>
#include <stdlib.h>
using namespace std;

class Print
{
public:
    static void PrintQueue(queue<string> q);    
};


#endif /* Print_hpp */

posted @ 2016-03-25 21:17  perhap_s  阅读(169)  评论(2编辑  收藏  举报