objective-C中实现四则元算——支持+、-、*、/、sin、cos、tan、log等运算

本文介绍了如何在Objective-C中实现基本的四则运算,包括加(+), 减(-), 乘(*), 除(/)以及常见的数学函数如sin, cos, tan和log。通过自定义方法或利用内置库,程序员可以方便地在iOS和macOS应用中进行数学计算。" 133965123,8206604,C++ API 设计:面试必备知识点与实战解析,"['C++', 'API设计', '面试', '开发语言', 'CSDN开发云']
摘要由CSDN通过智能技术生成
#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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值