嗨,我在为 HP-35 类型的计算器实现基本功能时遇到了一些麻烦和。
以下是我的主要文件:
/*
* File: main.cpp
* Author: Brenton
*
* Created on 20 September 2013, 12:10 AM
*/
#include <cstdlib>
#include "HPStack.h"
#include <iostream>
#include <sstream>
using namespace std;
/*
*
*/
int main(int argc, char** argv) {
HPStack stack;
string line;
while (getline(cin, line)) {
stringstream expression(line);
string token;
while (expression >> token) {
if (isdigit(token[0])) {
stack.push(atof(token.data()));
//From here I am having trouble, I don't know what the code is.
} else if (token == "+") { // Addition code
} else if (token == "-") { // Subtraction code
} else if (token == "/") { // Division code
} else if (token == "*") { // Multiplication code
double x = stack.pop();
double y = stack.pop();
stack.push(y + x);
}
}
cout << stack.peek();
}
return 0;
}
以下是到目前为止我创建的堆栈的代码:
/*
* File: HPStack.cpp
* Author: Brenton
*
* Created on 20 September 2013, 12:07 AM
*/
#include "HPStack.h"
HPStack::HPStack() {
}
HPStack::HPStack(const HPStack& orig) {
}
HPStack::~HPStack() {
}
下面是我的头文件代码:
/*
* File: HPStack.h
* Author: Brenton
*
* Created on 20 September 2013, 12:10 AM
*/
#ifndef HPSTACK_H
#define HPSTACK_H
class HPStack {
public:
HPStack();
void push(double);
double pop();
private:
double stack;
double x, y, z, t;
};
#endif /* HPSTACK_H */
我知道这似乎是一个愚蠢的问题,但我真的不知道我到底在用数学代码做什么,但我正在尝试。任何帮助将不胜感激