Github鏈接:https://github.com/zora02/object-oriented/tree/master/Caculatorhtml
題目描述鏈接:http://www.cnblogs.com/fzuoop/p/5187275.htmlios
main.cppc++
#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.cppgit
#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.hgithub
#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.cppoop
#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.h學習
#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 */