博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
面向对象程序设计第五次作业
阅读量:7016 次
发布时间:2019-06-28

本文共 1738 字,大约阅读时间需要 5 分钟。

Github地址

题目要求

  • 添加一种读取四则运算的方式:输入第一个参数若为-f,则再输入两个参数,为两个文件的路径。分别为程序读取输入的文件和输出答案的文件。
  • 将输出的代码都写在Print类中。
  • 描述框架图

代码

#include
#include
#include
#include
#include"Calculator.h"#pragma warning(disable:4996)using namespace std;int main(int argc, char* argv[]){ Calculation calculation; Scan scan; Print print; string strData1; string strData2; strData1 = argv[1]; queue
queue; double answer; if (strData1 == "-a") { strData2 = argv[2]; queue = scan.ToStringQueue(argv[2]); answer = calculation.ToCalculate(queue); print.ToOutput(answer, strData2); } else if (strData1 == "-f") { string strData3; strData3 = scan.Open(argv[2]); queue = scan.ToStringQueue(strData3); answer = calculation.ToCalculate(queue); print.ToOutput(answer,strData3, argv[3]); strData3 = ""; } else { queue = scan.ToStringQueue(strData1); answer = calculation.ToCalculate(queue); print.ToOutput(answer); } system("pause"); return 0;}

scan

把文件读取放在了scan类中

string Scan::Open(char *in){    string temp;    fstream file;    file.open(in);    file >> temp;    return temp;}

print

依照不同情况进行输出

void Print::ToOutput(double answer, string exp, char *out){    ofstream file;    file.open(out);    file << exp  <<  answer << endl;}void Print::ToOutput(double answer){    cout << answer << endl;}void Print::ToOutput(double answer, string exp){cout << exp << answer << endl;

}

描述框架图

886235-20160509165251765-817380555.png

心得

这一次修改因为增加了多组数据输入,发现除了第一个答案之后都是错的。研究之后才发现是在每一组处理过后有数据残留在字符串和队列中影响了下一组,在增加了清空队列和字符串的部分才正确。所以明白以后应注意在使用各种操作之后应当还原。

转载于:https://www.cnblogs.com/Wjianting/p/5474554.html

你可能感兴趣的文章
数据库系统原理,很赞的课程!
查看>>
iis站点内存泄漏问题分析
查看>>
win10 HTTP 错误 500.21 - Internal Server Error
查看>>
如何创建Vue3.0项目
查看>>
MongoDB 启动基于角色的登录认证功能
查看>>
数据库原理整理笔记1
查看>>
如果选错云服务商,后果很严重……
查看>>
c#备份MySQL数据库 --转载
查看>>
HDU - 1247 Hat’s Words 字典树
查看>>
从client(content=&quot;&lt;p&gt;&lt;/p&gt;&quot;)中检測到有潜在危急的 Request.Form 值。
查看>>
《Effective C++》笔记:I
查看>>
C语言 指针和指针变量
查看>>
经典类与新式类的区别
查看>>
JavaMail收发邮件的步骤
查看>>
树莓派练习程序(寻迹模块)
查看>>
点击弹出居中带有透明遮罩层窗口
查看>>
C语言程序设计第四次作业——选择结构(2)
查看>>
安装Tomcat提示Failed to install Tomcat6 service...的解决办法
查看>>
17.08.07
查看>>
C#语法糖(Csharp Syntactic sugar)语法技巧
查看>>