//
// ViewController.m
// Calc
//
// Created by apple on 14-7-10.
// Copyright (c) 2014年 dengshiru. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *textFid;
@end
int i;
i = 10;
@implementation ViewController
- (IBAction)click1:(id)sender //利用if语句判断本次输入的数应在哪个位置
{
if (calc.op== '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 1;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue2];
}
else
{
calc.opValue1 = calc.opValue1 * 10 +1;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click2:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 2;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else{
calc.opValue1 = calc.opValue1 * 10 + 2;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click3:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 3;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 3;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click4:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 4;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 4;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click5:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 5;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 5;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click6:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 6;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 6;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click7:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 7;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 7;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click8:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 8;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 8;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click9:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 9;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 9;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click0:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 ;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)add:(id)sender {
calc.op = '+';
}
- (IBAction)cut:(id)sender {
calc.op = '-';
}
- (IBAction)ride:(id)sender {
calc.op = '*';
}
- (IBAction)div:(id)sender {
calc.op = '/';
}
- (IBAction)dian:(id)sender {
calc.op = '.';
}
- (IBAction)dengyu:(id)sender {
//结果计算
float dengyu = [calc work];
self.textFid.text = [NSString stringWithFormat:@"%f",dengyu];
//计算完成结果清零
calc.op = 0;
calc.opValue1 = 0;
calc.opValue2 = 0;
}
- (IBAction)clear:(id)sender {
//结果清除、清零
self.textFid.text = [NSString stringWithFormat:@""];
calc.op = 0;
calc.opValue1 = 0;
calc.opValue2 = 0;
}
- (void)viewDidLoad {
[super viewDidLoad];
//在程序运行之前生成计算器
calc = [[Caculator alloc] init];
// 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
// ViewController.m
// Calc
//
// Created by apple on 14-7-10.
// Copyright (c) 2014年 dengshiru. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UILabel *textFid;
@end
int i;
i = 10;
@implementation ViewController
- (IBAction)click1:(id)sender //利用if语句判断本次输入的数应在哪个位置
{
if (calc.op== '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 1;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue2];
}
else
{
calc.opValue1 = calc.opValue1 * 10 +1;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click2:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 2;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else{
calc.opValue1 = calc.opValue1 * 10 + 2;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click3:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 3;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 3;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click4:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 4;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 4;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click5:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 5;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 5;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click6:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 6;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 6;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click7:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 7;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 7;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click8:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 8;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 8;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click9:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 + 9;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10 + 9;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)click0:(id)sender {
if (calc.op == '+'
|| calc.op == '-'
|| calc.op == '*'
|| calc.op == '/') {
calc.opValue2 = calc.opValue2 * 10 ;
self.textFid.text = [NSString stringWithFormat:@"%F",calc.opValue2];
}
else {
calc.opValue1 = calc.opValue1 * 10;
self.textFid.text = [NSString stringWithFormat:@"%f",calc.opValue1];
}
}
- (IBAction)add:(id)sender {
calc.op = '+';
}
- (IBAction)cut:(id)sender {
calc.op = '-';
}
- (IBAction)ride:(id)sender {
calc.op = '*';
}
- (IBAction)div:(id)sender {
calc.op = '/';
}
- (IBAction)dian:(id)sender {
calc.op = '.';
}
- (IBAction)dengyu:(id)sender {
//结果计算
float dengyu = [calc work];
self.textFid.text = [NSString stringWithFormat:@"%f",dengyu];
//计算完成结果清零
calc.op = 0;
calc.opValue1 = 0;
calc.opValue2 = 0;
}
- (IBAction)clear:(id)sender {
//结果清除、清零
self.textFid.text = [NSString stringWithFormat:@""];
calc.op = 0;
calc.opValue1 = 0;
calc.opValue2 = 0;
}
- (void)viewDidLoad {
[super viewDidLoad];
//在程序运行之前生成计算器
calc = [[Caculator alloc] init];
// 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