int main(int argc, char* argv[]) { string input; Scan scan; Paint print; if (argc == 2)//无-a -f { input = argv[1]; scan.ToStringQueue(input); print.Printqueue(); } else if (argc == 3 )//第二个参数-a { input = argv[2]; cout << input << " "; scan.ToStringQueue(input); print.Printqueue(); } else// -f的情况 { fout.open(argv[3]); flag = 4; ifstream fin; fin.open(argv[2]); if (fin.is_open()) { while (fin.good() && !fin.eof())//读取到文件尾停止读入 { string message;//先将运算式存入message 再转存如input进行操作 fin >> message; input = message; ssss = argv[3]; scan.ToStringQueue(input); print.Printqueue(); } } } system("pause"); return 0; }
void File_Operate::Fileoperate() { Scan Sc; Print Put; Calculation Ca; ifstream infile; ofstream outfile; //打开文件 infile.open(getsfile.c_str(),ios::in); outfile.open(putsfile.c_str(),ios::out); string get_str; while(!infile.eof()) //未处理到文件尾 { getline(infile,get_str); //读入数据 queue<string> que; que = Sc.ToStringQueue(get_str); double result=0; result = Ca.carryout(que); outfile << result << endl; } //关闭文件 infile.close(); outfile.close(); }
int main(int argc, char* argv[]) { Scan in; Calculation cal; string input; //将传入表达式赋给input if(strcmp(argv[1], "-a") == 0) { cout << argv[2] << "= "; input = argv[2]; } else { input = argv[1]; } //首先判断输入字符串中数字串长度不超过10位 if (!in.checkNumberLen(input)) { return 0; } cal.getQueue(in.ToStringQueue(input)); return 0; }
int main(int argc, char* argv[]) { bool flag = false; stack <double>result; string character; queue<string>que_character; Scan INPUT; //Print OUTPUT; Calculation CAL; Calculation RES; character = argv[1]; if(character == "-a") { character = argv[2]; flag = true; } if(flag) { cout << character << "="; } que_character = INPUT.ToStringQueue (character); result = CAL.Separate (que_character); RES.CoutResult(result); //OUTPUT.print(que_character); return 0; }
//--------1 输出表达式; void Print::PrintStringQueue(string input) { /*创建Scan对象s*/ Scan s; Calculate c; /*获得Scan里所扫描的队列*/ queue<string> tmp = s.ToStringQueue(input); //---- 除数为0或超出十位数输ERROR if (s.IsError() == true ) { cout << "ERROR" <<endl; } else { if (c.iserror() == false) { /*依次输出符合要求的元素*/ while ( !tmp.empty() ) { cout << tmp.front() ; tmp.pop(); } cout << " " << c.Calculater(input); } else { cout << "ERROR" << endl; } } }
//以文件方式输出结果 void Print::ToPrintIs_f(string sText_txt, string sResult_txt) { ifstream in; ofstream out; //打开文件 in.open(sText_txt.c_str(), ios::in); out.open(sResult_txt.c_str(), ios::out); while (!in.eof()) { Scan scan; Calculation calculate; string sExperssion; //从sText_txt路径获取数据 getline(in, sExperssion, '\n'); //拆分表达式 scan.ToStringQueue(sExperssion); //计算表达式的值 calculate.ToCalculate(scan.q); //在sResult_txt路径下输出结果 out << calculate.m_dResult << endl; } //关闭文件 in.close(); out.close(); }
int main() { Scan scan; Print print; cin >> input; scan.ToStringQueue(input); if (scan.IsError()) { cout << "Error" << endl; } else { print.PrintQueue(scan.GetQueue()); } }
int main(int argc, const char * argv[]) { string input; bool p,a; double ans; int i; Scan scan; Print print; Calculate Calculate; p=false; a=false; i=1; // getline(cin,input); if (argc<2) return 0; input=argv[i]; while (1){ if (input=="-a") { input=argv[++i]; a=true; continue; } if (input=="-p"){ input=argv[++i]; p=true; continue; } break; } // print.PrintStringQueue( scan.ToStringQueue(input) ); ans=Calculate.getAns( scan.ToStringQueue(input) , p); if (a) cout<<input<<"="; cout<<ans<<endl; return 0; }
//以非文件方式输出结果 void Print::ToPrintIsNot_f(string sInput, bool bIs_a) { Scan scan; Calculation calculate; //拆分表达式 scan.ToStringQueue(sInput); //计算表达式的值 calculate.ToCalculate(scan.q); if (bIs_a) { cout << sInput << "= "; } cout << calculate.m_dResult << endl; }
int main(int argc, char* argv[]) { string input; string output; int temp = 0;//判断是否有“-a” int i; Scan sca; Calculation calcul; for (i = 1; i < argc; i++) { input = argv[i]; if (input == "-a") { temp = 1; continue; } } sca.ToStringQueue(input); queue<string>*q = sca.GetQueue();//定义队列指针接收队列 //如果数字符合要求才运算 if (sca.m_ijudge == 0) { if (temp == 1) { cout << input << "= "; } calcul.trans(q); double result = calcul.count(); cout << result << endl; } else { return 0; } system("pause"); return 0; }
int main(int argc , char *argv[]) { Scan scan; //Print print; Calculation calculation; string input; //cin >> input; /*根据argc的值对input赋值*/ if(argc == 2) { input = argv[1]; } else { input = argv[2]; } scan.ToStringQueue (input); /*将input传入Scan进行处理*/ calculation.GetQueue(scan.ReturnQueue()); /*将处理后的queue传入Calculation*/ calculation.Change(scan.ReturnQueue()); /*将传入的queue进行后缀转化*/ //calculation.Ans(); /*根据argc的值进行不同输出*/ if(argc == 2) { calculation.Ans(); } else { cout << argv[2] << "= "; calculation.Ans(); } //if(scan.IsError() == false) // print.print(scan.ReturnQueue()); //else //cout << "超过十位啦!"; return 0; }
int main() { string input; cin>>input; if(check(input)) { cout<<"出错啦!"<<endl; return 0; } else //数字位数不大于10时处理字符串 { Scan scan; Print print; //创建Print对象和scan对象 queue<string> q = scan.ToStringQueue(input); //调用ToStringQueue()函数获取目标队列 print.PrintQueue(q); //调用PrintQueue()函数输出队列各元素 return 0; } }
int main(int argc, char** argv) { string input; string parameter; double result; queue<string> seperatedExpression; Scan scan; Calculation cal; Print print; parameter = argv[1]; cout << setprecision(precision); if (parameter == "-a") //输入参数为 -a 的情况,输出表达式 { input = argv[2]; seperatedExpression = scan.ToStringQueue(input); if (seperatedExpression.front() == "ERROR") //若返回字符串为 ERROR 则报错并退出循环 { print.PrintLengthError(); return 0; } result = cal.Calculate(seperatedExpression); print.PrintA(input,result); } else if (parameter == "-f") //输入参数为 -f 的情况,对文件进行读写 { if (scan.Open(argv[2]) && print.Open(argv[3])) { while (!scan.IsEOF()) //循环读入每行,计算和写入文件 { result = 0; while(!seperatedExpression.empty()) { seperatedExpression.pop(); } scan.Read(); if (scan.GetInput() == "") { continue; } seperatedExpression = scan.ToStringQueue(scan.GetInput()); if (seperatedExpression.front() == "ERROR") { print.PrintLengthError(); continue; } result = cal.Calculate(seperatedExpression); print.PrintF(result); } scan.Close(); print.Close(); } else { cout << "Open file failed."; return 0; } } else //无参数情况 { input = argv[1]; seperatedExpression = scan.ToStringQueue(input); if (seperatedExpression.front() == "ERROR") { print.PrintLengthError(); return 0; } result = cal.Calculate(seperatedExpression); print.DefaultPrint(result); } return 0; }