我的积分计算器

本文介绍了如何利用C++编程语言实现一个积分计算器,详细探讨了相关数学原理和编程技巧,包括数值积分方法的选择和代码实现过程。
摘要由CSDN通过智能技术生成
#include<iostream>	
#include<string>
#include<stack>
#include<iomanip>
#include<cmath>
#define double long double
using namespace std;
double x;
bool checkisoperatorchar(char ch) {
	if (ch == '+' || ch == '-' || ch == '/' || ch == '*' || ch == '(' || ch == ')'||ch=='^')
		return 1;
	else
		return 0;
}
int priority(char ch)
{

	if (ch == '/' || ch == '*')
		return 2;
	else if (ch == '+' || ch == '-')
		return 1;
	else if (ch == '^')
		return 3;
}
double calculateRPN(string s)
{
	stack<double>nums;
	int len = s.size();
	double temp = 0;
	double tempsmall = 0;
	for (int i = 0; i < len; i++)
	{
		if (s[i] == 'x')
		{
			nums.push(x);
		}
		else if (s[i] == 'e')
		{
			nums.push(2.718281);
		}
		else if (s[i] == 'π')
		{
			nums.push(3.1415926);
		}
		else if (s[i] >= '0' && s[i] <= '9') {
			temp = temp * 10 + (s[i] - '0');
		}
		else if (s[i] == '.') {
			tempsmall = 0.1;
			i++;
			while (i!=len&&s[i]!=' ') {
				
					temp += tempsmall * (s[i] - '0');
					tempsmall *= 0.1;
					i++;
				}
			nums.push(temp);
			temp = 0;
			}
		
		else if (s[i] == ' '&&s[i-1]<='9'&&s[i-1]>='0') {
			nums.push(temp);
			temp = 0;
		}

		else if (s[i] == '*')
		{
			double m = nums.top();
			nums.pop();
			m *= nums.top();
			nums.pop();
			nums.push(m);
		}
		else if (s[i] == '+')
		{
			double m = nums.top();
			nums.pop();
			m += nums.top();
			nums.pop
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值