Github连接:https://github.com/zora02/object-oriented/tree/master/Caculator(更改)ios
说实话寒假打代码的时候没有认真的看过代码规范,当时以为能把代码打出来就很开心了(´・_・`)。这几天认真的看了代码规范,感受仍是有所收获。(虽然有些内容咱们如今还用不到,可是之后确定是能用到的。)看完代码规范后对本身的代码作了一些修改。可是没有特别大的改动,主要是一些格式上的修改。还有就是注释方面我仍是不很清楚,不知道该怎么注释比较合适正确,因此原本想修改一下本身的注释,可是不知道该怎么改orz。。。因此我没有改,若是这个被扣分,我认了>_<
main.cppgit
#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.cppgithub
#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.hppspa
#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.hppcode
#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 */