用逆波兰表达式的三角函数计算器

该博客介绍了如何使用C++实现一个逆波兰表达式的三角函数计算器。程序能够处理包括正弦、余弦和正切在内的三角函数,并处理括号、乘除、加减等运算。用户需要输入一个合法的表达式,程序会计算并输出结果。
摘要由CSDN通过智能技术生成
 
 
 
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<stack>
#include<iomanip>
#include"caltulator.h"
using namespace std;

typedef struct STK
{
	double num=889277;
	char note=0;
}stk;

char s[1000];//初始输入的数组
stk s1[1000];//字符串分割出来的部分
stk s3[1000];//最后的逆波兰表达式


bool if_minus(int & pos);
void turn_pi(int len);
double cut_num(int &pos)
{
	int f_pos = pos;      //一个数字的开始位置
	double integer = 0.0;
	double remainder = 0.0;
	int c = 0;
	while (s[pos] >= '0'&&s[pos] <= '9')
	{
		integer *= 10;
		integer += s[pos] - '0';
		pos++;
	}
	while (s[pos] == '.')
	{
		c = 1;
		pos++;
		while (s[pos] >= '0'&&s[pos] <= '9')
		{
			remainder += pow(0.1, c)*(s[pos]-'0');
			c++;
			pos++;
		}
	}
	//int pre_pos = f_pos - 1;     //一个数字开始之前的一个位
	
	return remainder + integer;
}

char cut_note(int &pos)
{
	if (s[pos] == '*')
	{
		pos++;
		return '*';
	}
	else if (s[pos] == '+')
	{
		pos++;
		return '+';
	}
	else if (s[pos] == '-')
	{
		pos++;
		return '-';
	}
	else if (s[pos] == '/')
	{
		pos++;
		return '/';
	}
	else if (s[pos] == '(')
	{
		pos++;
		return '(';
	}
	else if (s[pos] == ')')
	{
		pos++;
		return ')';
	}
	else if (s[pos] == 's')
	{
		pos++;
		if (s[pos] == 'i')
		{
			pos++;
			if (s[
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值