首页 > 其他 > 详细

简单计算器

时间:2014-07-14 09:39:08      阅读:442      评论:0      收藏:0      [点我收藏+]

#import "ViewController.h"

#import "cal.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UILabel *calrusult;

            

 

@end

   float i=10.0;

@implementation ViewController

- (IBAction)Didclick0:(UIButton *)sender {

    if (calc.op ==‘+‘||calc.op==‘-‘||calc.op==‘*‘||calc.op==‘/‘)

    {

         if(calc.diandian==‘.‘)

         {

            calc.opvalue2=calc.opvalue2+sender.tag/i;

            i=i*10.0;

            self.calrusult.text=[NSString stringWithFormat:@"%f",calc.opvalue2];

        }

         else

         {

             calc.opvalue2=calc.opvalue2*10.0+sender.tag;

             self.calrusult.text=[NSString stringWithFormat:@"%f",calc.opvalue2];

         }

    }

    else

    {

        if(calc.diandian==‘.‘)

        {

        calc.opvalue1=calc.opvalue1+sender.tag/i;

            i=i*10.0;

        self.calrusult.text=[NSString stringWithFormat:@"%f",calc.opvalue1];

        }

        else

        {

            calc.opvalue1=calc.opvalue1*10.0+sender.tag;

            self.calrusult.text=[NSString stringWithFormat:@"%f",calc.opvalue1];

        }

    }

}

 

- (IBAction)Didclickadd:(UIButton *)sender

{

    calc.op=‘+‘;

    calc.diandian=0;

    i=10;

    

}

- (IBAction)DidlcickCut:(UIButton *)sender

{

    calc.op=‘-‘;

    calc.diandian=0;

    i=10;

}

- (IBAction)Didclickcheng:(UIButton *)sender {

    calc.op=‘*‘;

    calc.diandian=0;

    i=10;

}

- (IBAction)Didclickchu:(UIButton *)sender {

    calc.op=‘/‘;

    calc.diandian=0;

    i=10;

}

- (IBAction)xiaodian:(UIButton *)sender {

    calc.diandian=‘.‘;

}

- (IBAction)esc:(id)sender {

    calc.opvalue1=0;

    calc.opvalue2=0;

    calc.op=0;

    self.calrusult.text=[NSString stringWithFormat:@"%f",calc.opvalue1];

}

- (IBAction)Didclickequal:(id)sender {

    switch (calc.op)

    {

        case  ‘+‘:

        {

            float result=[calc work];

            self.calrusult.text=[NSString stringWithFormat:@"%f",result];

            break;

        }

        case ‘-‘:

        {

            float result=[calc run];

            self.calrusult.text=[NSString stringWithFormat:@"%f",result];

            break;

        }

        case ‘*‘:

        {

            float result=[calc start];

            self.calrusult.text=[NSString stringWithFormat:@"%f",result];

            break;

        }

        case ‘/‘:

        {

            float result=[calc chufa];

            self.calrusult.text=[NSString stringWithFormat:@"%f",result];

            break;

        }

        default:

            break;

    }

    //(clac.op==‘+‘):

    

     //float result=[calc work];

// self.calrusult.text=[NSString stringWithFormat:@"%f",result];

    

}

            

- (void)viewDidLoad {

    [super viewDidLoad];

   calc=[[cal alloc]init];//生成计算器;

    //放入动画。

    UIImage *image1=[UIImage imageNamed:@"1.jpg"];

    UIImage *image2=[UIImage imageNamed:@"2.jpg"];

    UIImageView *imageview=[[UIImageView alloc]init];

    imageview.frame=CGRectMake(0, 420, 50, 100);

    imageview.image=image2;

    imageview.highlightedImage=image2;

    imageview.highlighted=NO;

    [self.view addSubview:imageview];

    

    UIImage *image3 = [UIImage imageNamed:@"3.jpg"];

    NSArray *array=[NSArray arrayWithObjects:image1,image2,image3,nil];

    imageview.animationImages=array;

    imageview.animationDuration=3;

    [imageview startAnimating];

    [self.view addSubview:imageview];

    

    // Do any additional setup after loading the view, typically from a nib.

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

@end

 

简单计算器,布布扣,bubuko.com

简单计算器

原文:http://www.cnblogs.com/sunxiang1991/p/3839996.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!