首页 > 代码库 > 简单计算器的设计
简单计算器的设计
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *show;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
jisuan=[[jisuanqi alloc]init];
}
- (IBAction)click1:(id)sender {
if (jisuan.opp1 == 0) {
jisuan.opr2 = jisuan.opr2 * 10 + 1;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr2];
}
else{
jisuan.opr1= jisuan.opr1 * 10 + 1;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr1];}
}
- (IBAction)click2:(id)sender {
if (jisuan.opp1 == 0){
jisuan.opr2 = jisuan.opr2 * 10 + 2;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr2];
}
else{
jisuan.opr1= jisuan.opr1 * 10 + 2;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr1];}
}
- (IBAction)click3:(id)sender {
if (jisuan.opp1 == 0){
jisuan.opr2 = jisuan.opr2 * 10 + 3;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr2];
}
else{
jisuan.opr1= jisuan.opr1 * 10 + 3;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr1];}
}
- (IBAction)click4:(id)sender {
if (jisuan.opp1 == 0) {
jisuan.opr2 = jisuan.opr2 * 10 + 4;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr2];
}
else{
jisuan.opr1= jisuan.opr1 * 10 + 4;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr1];}
}
- (IBAction)click5:(id)sender {
if (jisuan.opp1 == 0) {
jisuan.opr2 = jisuan.opr2 * 10 + 5;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr2];
}
else{
jisuan.opr1= jisuan.opr1 * 10 + 5;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr1];}
}
- (IBAction)click6:(id)sender {
if (jisuan.opp1 ==0) {
jisuan.opr2 = jisuan.opr2 * 10 + 6;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr2];
}
else{
jisuan.opr1= jisuan.opr1 * 10 + 6;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr1];}
}
- (IBAction)click7:(id)sender {
if (jisuan.opp1 == 0) {
jisuan.opr2 = jisuan.opr2 * 10 + 7;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr2];
}
else{
jisuan.opr1= jisuan.opr1 * 10 + 7;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr1];}
}
- (IBAction)click8:(id)sender {
if (jisuan.opp1 == 0) {
jisuan.opr2 = jisuan.opr2 * 10 + 8;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr2];
}
else{
jisuan.opr1= jisuan.opr1 * 10 + 8;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr1];}
}
- (IBAction)click9:(id)sender {
if (jisuan.opp1 == 0) {
jisuan.opr2 = jisuan.opr2 * 10 + 9;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr2];
}
else{
jisuan.opr1= jisuan.opr1 * 10 + 9;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr1];
}
}
- (IBAction)click0:(id)sender {
if (jisuan.opp1 == 0) {
jisuan.opr1 = jisuan.opr1 * 10 ;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr1];
}
else{
jisuan.opr1= jisuan.opr1 * 10 ;
self.show.text = [NSString stringWithFormat:@"%f", jisuan.opr1];}
}
- (IBAction)clickadd:(id)sender {
jisuan.opp1 = ‘+‘;
}
- (IBAction)clicksub:(id)sender {
jisuan.opp1 = ‘-‘;
}
- (IBAction)clickmud:(id)sender {
jisuan.opp1= ‘*‘;
}
- (IBAction)clickdiv:(id)sender {
jisuan.opp1 = ‘/‘;
}
- (IBAction)clear:(id)sender {
float clear=[jisuan work5];
self.show.text = [NSString stringWithFormat:@"%f", clear];
}
- (IBAction)eql:(id)sender {
float result;
if(jisuan.opp1== ‘+‘){
result = [jisuan work1];}
else if (jisuan.opp1==‘-‘){
result = [jisuan work2];}
else if(jisuan.opp1==‘*‘)
{ result = [jisuan work3];}
else if(jisuan.opp1==‘/‘)
{ result = [jisuan work4];}
self.show.text = [NSString stringWithFormat:@"%f", result];
}