//
// Viewcontroller. m
// Calculator
//
// Created by Apple on 14-7-10.
// Copyright (c) 2014 apple. All rights reserved.
//
# Import "viewcontroller. H"
# Import "calculat. H"
@ Interface viewcontroller ()
{
Float result;
Int I;
}
@ Property (weak, nonatomic) iboutlet uilabel * lab;
@ End
@ Implementation viewcontroller
-(Void) viewdidload
{
[Super viewdidload];
Cal = [[calculat alloc] init];
}
-(Ibaction) Click :( uibutton *) sender
{
Nslog (@ "% d, % @", Sender. Tag, Sender. currenttitle );
// Self. Lab. Text = [nsstring stringwithformat: @ "% d", Sender. Tag];
If (Cal. opsb = '+'
| Cal. opsb = '-'
| Cal. opsb = '/'
| Cal. opsb = '*')
{
Cal. opvalue2 = Cal. opvalue2 * 10 + sender. Tag;
Self. Lab. Text = [nsstring stringwithformat: @ "% F", Cal. opvalue2];
}
Else
{
Cal. opvalue1 = Cal. opvalue1 * 10 + sender. Tag;
Self. Lab. Text = [nsstring stringwithformat: @ "% F", Cal. opvalue1];
}
}
-(Ibaction) Sb :( ID) sender {Cal. opsb = '+ ';
Self. Lab. Text = [nsstring stringwithformat: @ "+"];
I = 1;
}
-(Ibaction) SBM :( ID) sender {Cal. opsb = '-';
Self. Lab. Text = [nsstring stringwithformat: @ "-"];
I = 2;
}
-(Ibaction) SBC :( ID) sender {Cal. opsb = '/';
Self. Lab. Text = [nsstring stringwithformat: @ "/"];
I = 3;
}
-(Ibaction) SBH :( ID) sender {Cal. opsb = '*';
Self. Lab. Text = [nsstring stringwithformat: @ "*"];
I = 4;
}
-(Ibaction) didclickedequal :( ID) sender {
// Calculation Result
If (I = 1)
{
Result = [Cal work1];
Self. Lab. Text = [nsstring stringwithformat: @ "% F", result];
}
Else if (I = 2)
{
Result = [Cal work2];
Self. Lab. Text = [nsstring stringwithformat: @ "% F", result];
}
Else if (I = 3)
{
Result = [Cal work3];
Self. Lab. Text = [nsstring stringwithformat: @ "% F", result];
}
Else if (I = 4)
{
Result = [Cal work4];
Self. Lab. Text = [nsstring stringwithformat: @ "% F", result];
}
}
-(Void) didreceivememorywarning {
[Super didreceivememorywarning];
// Dispose of any resources that can be recreated.
}
-(Ibaction) CD :( ID) sender
{
Cal. opsb = 0;
Cal. opvalue1 = 0;
Cal. opvalue2 = 0;
Self. Lab. Text = [nsstring stringwithformat: @ "0"];
}
@ End