(2016.2.28)寒假第三次作业随笔
2016-02-28 20:53
344 查看
第三次作业附加作业
目标:
规范化代码参考以下网址修改 <a href="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);//整理字符串
};```
相关文章推荐
- ROS launch file 写法
- linux精讲——su切换用户
- 删除事件处理程序如何解决
- ubuntu 系统配置维护 常用命令
- MOOC《Linux内核分析》第一课
- [LeetCode]236 二叉树的最近公共父亲节点
- leetcode笔记:Majority Element II
- 安全卫士第三天
- 导入表
- python常用异常
- 菩提本无树,明镜亦非台。本来无一物,何处惹尘埃.
- uva 10780 素因子分解
- 计算机网络部分基础知识
- 2016成长之路
- Android向通讯录添加联系人的一般方法
- tcp连接断开的一些面试常识
- iOS9的新特性以及适配方案
- Scala写的wordcount
- 7. Swift 基于Xmpp和openfire实现一个简单的登录注册
- hdu 1114