(2016.3.26)第3次附加作业随笔
2016-03-26 20:30
288 查看
第三次作业附加作业
目标:
规范化代码 参考以下网址修改http://wenku.baidu.com/link?url=WIJB7CAfMEyN1fGSCiUaxnnMmMUubRMHR8I1KXMsQmmhDBVGI_lYICFMKTjt36MODh1qgx0mkIuKIIWlvMX6J7cOCNRWVxFCIW80bKiiPTC&qq-pf-to=pcqq.group
代码链接
代码链接反思
我觉得学习规范的确的是好习惯,如果不是我加了注释,这次回看就根本看不懂了。 而且写多了一些,规范这东西真的很方便 就是不知道这次改没改成老师要求的
具体代码
main.cpp
#include <iostream> #include <string> #include<stdlib.h> #include <queue> #include "Scan.h" #include "Print.h" using namespace std; /* run this program using the console pauser or add your own getch, system("pause") or input loop */ /*修改版*/ int main(int argc, char** argv) { cout<<"请输入一个四则运算表达式:"<<endl; // 输入字符串 string demo; cin>>demo; // 实例化Scan和Print Scan s; Print p; queue<string> temp=s.ToStringQueue(demo); if (temp.empty()){ cout<<"输入数字超过10位(包括小数位"<<endl; }else{ p.printString(temp); } system("pause"); return 0; }
print.cpp
<code>#include <iostream> #include <string> #include <queue> #include "print.h" using namespace std; void Print::printString(queue<string> temp){ // 当队列不为空时循环 while (!temp.empty()) { // 输出并删除队列 首位 cout << temp.front()<<endl; temp.pop(); } }
print.h
<code>#include <iostream> #include <string> #include <queue> using namespace std; class Print { public : void printString(queue<string> input);//打印字符串 };
Scan.cpp
#include <iostream> #include <string> #include <queue> #include "Scan.h" using namespace std; queue<string> Scan::ToStringQueue(string input){ //定义长度 int length=0; // 初始化字符串和列表 string temp1=""; string temp2=""; queue<string> ans; queue<string> enmpty; // 遍历input for (int i=0;i<input.length();i++) { if (input[i]>='0'&&input[i]<='9'||input[i]=='.') { // 符合条件 length++; // 超过10位报错 if (length>10) { return enmpty; } // 储存非单个或单个的数字 temp1=temp1+input[i]; // 判断除除了最后一位的input的 下一位 if (i!=(input.length()-1)) { // 断后一位是否符合条件 ,符合交给下一位去做 if (input[i+1]>='0'&&input[i+1]<='9'||input[i+1]=='.') { } // 不符合就将储存的temp1加入队列中 else { ans.push(temp1); temp1=""; length=0; } } // 把单个数字的input加入 else { ans.push(temp1); temp1=""; length=0; } } // 将出了数字的加队列 else { temp2=input[i]; ans.push(temp2); } } return ans; }``` ####Scan.h
include
include
include
using namespace std;class Scan{
public:
queue ToStringQueue(string input);//整理字符串
};
```
相关文章推荐
- 专题一 Problem G
- 如何在php中用百度云推送进行消息的推送
- Bestcoder Div2 #77 A So easy
- Socket send函数和recv函数详解
- 树:BST、AVL、红黑树、B树、B+树
- C#中string.format用法详解
- 第20篇《结网》读书笔记
- 学习进度条——第四周
- 更新iOS和Xcode版本所遇到的问题
- myisam和innodb索引实现的不同
- C中结构体与C++中类的区别
- exec函数族
- 求数组最大字数组之和第一部
- Ubuntu在qt下使用caffe的pro写法
- 用户和用户组文件
- AVL如何保持平衡
- error c4996
- leetcode_076 Minimun Window Substring
- hdoj 2028Lowest Common Multiple Plus
- Linux(1):fork函数