#import <Foundation/Foundation.h>
double PI=3.141592654;
@interface Caculator : NSObject
{
}
+(double) angleTorad : (double)angle;
+(void) trans : (char*)a : (char*)b;
+(double) comp_value : (char*)exp;
+(double) expr_parser : (char*)expr;
@end
@implementation Caculator
+(double) angleTorad : (double) angle
{
return (2*PI*angle)/360;
}
+(void) trans : (char*) a : (char*) b
{
char stock[128]={0};
int top=0;
int len=0;
int i=0;
int j=0;
top = -1;
j = -1;
len = strlen(a);
for (i=0; i<len; i++)
{
switch(a[i])
{
case '(':
stock[++top] = '(';
break;
case '+':
case '-':
while( top>=0 && stock[top]!='(' )
{
b[++j] = stock[top--];
}
stock[++top] = ' ';
stock[++top] = a[i];
break;
case '*':
case '/':
while( top>=0 && stock[top]!='(' && stock[top]!='+' && stock[top]!='-' )
{
b[++j] = stock[to
objective-C中实现四则元算——支持+、-、*、/、sin、cos、tan、log等运算
最新推荐文章于 2024-09-10 16:48:02 发布
本文介绍了如何在Objective-C中实现基本的四则运算,包括加(+), 减(-), 乘(*), 除(/)以及常见的数学函数如sin, cos, tan和log。通过自定义方法或利用内置库,程序员可以方便地在iOS和macOS应用中进行数学计算。"
133965123,8206604,C++ API 设计:面试必备知识点与实战解析,"['C++', 'API设计', '面试', '开发语言', 'CSDN开发云']
摘要由CSDN通过智能技术生成