您的位置:首页 > 编程语言

程序设计第三次作业附加 代码规范

2016-03-19 14:01 471 查看
题目:第三次作业附加

myGithub

我的程序设计第三次作业

Calculator.h

//==============================//
//文件名称:calculator.h
//作者:031502209
//时间:2016/3/23
//博客:qq952693358
//==============================//
#ifndef CALCULATOR_H
#define CALCULATOR_H
#include<string>
#include<queue>
#include<stdlib.h>
#include<iostream>
using namespace std;

//==============================//
//class:Input
//包含:输入函数Get
//函数类型:string
//说明:输入函数单独放在这个类里
//==============================//
class Input
{
public:
string Get();
};

//===============================//
//class:Print
//包含:输出函数Get
//函数类型:queue<string>
//说明:输出函数单独放在这个类里
//===============================//
class Print
{
public:
void pout(queue<string> que); // type:queue<string>
};

//===============================//
//class:Scan
//包含:函数ToStringQueue
//函数类型:queue<string>
//说明:输出函数单独放在这个类里
//===============================//
class Scan
{
// private section
public:
queue<string>ToStringQueue(string input);//type:queue<string>
};

#endif // CALCULATOR_H


Calculator.cpp

#include "calculator.h" // class's header file
#include<string>
#include<queue>
#include<stdlib.h>
#include<iostream>
using namespace std;

int t=0; // Using global variable "t";

string Input::Get()
{
string s;
cin>>s;
return s;
}

queue<string> Scan::ToStringQueue(string input)
{
// type:queue<string>

int n=input.length();
int i,j;

queue<string> que;
string s;

for(i=0 ; i<n ; i++) // Error: n has no define;
{
if(t>10)     // such as "10,000,000,000"
{
cout<<"Error"<<endl;
break;
}

if(input[i] == '-' || input[i] == '+' || input[i] == '('
|| input[i] == ')' || input[i] == '/' || input[i] == '*')
{
t=0;      //stop the count

if(s!="") //avoid null string
que.push(s);
s="";     //s.clear();

s+=input[i];

que.push(s);
s="";
}
else
{
t++;

s+=input[i];

continue;
}
}

que.push(s);
s.clear();

return que;
}

void Print::pout(queue<string> que)
{
if(t <= 10) // ifnormal
{
while(que.empty() == 0) // "que" is not empty
{
cout << que.front() << endl;

que.pop();
}
}
}

int main()
{
queue<string> que; // type:queue<string>

Scan Sc;    // Define a "Scan" object:"Sc".
Print Put;  // Define a "Print" object "Put".
Input Ge;   // Define a "Input" object "Ge".
string input;

input=Ge.Get();              // receieve input.
que=Sc.ToStringQueue(input); // receieve que.

Put.pout(que);    // printf que.
return 0;
}
// example:
// -100+(98-97)*2


2016/3/23
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: