1. Use the xcode6 control to build a calculator Interface
2. Program
# Import "viewcontroller. H"
@ Interface viewcontroller ()
{
Float result;
Int I;
}
@ Property (weak, nonatomic) iboutlet uilabel * labble;
@ End
@ Implementation viewcontroller
-(Void) viewdidload {
[Super viewdidload];
CA = [[calcu alloc] init];
// Do any additional setup after loading the view, typically from a nib.
}
-(Ibaction) button1 :( ID) sender {
If (ca. OP = '+' | ca. OP = '-' | ca. OP = '*' | ca. OP = '/'))
{
CA. value2 = Ca. value2 * 10 + 1;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value2];
}
Else
{
CA. value1 = Ca. value1 * 10 + 1;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value1];
}
}
-(Ibaction) button2 :( ID) sender {
If (ca. OP = '+' | ca. OP = '-' | ca. OP = '*' | ca. OP = '/'))
{
CA. value2 = Ca. value2 * 10 + 2;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value2];
}
Else
{
CA. value1 = Ca. value1 * 10 + 2;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value1];
}
}
-(Ibaction) button3 :( ID) sender {
If (ca. OP = '+' | ca. OP = '-' | ca. OP = '*' | ca. OP = '/'))
{
CA. value2 = Ca. value2 * 10 + 3;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value2];
}
Else
{
CA. value1 = Ca. value1 * 10 + 3;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value1];
}
}
-(Ibaction) button4 :( ID) sender {
If (ca. OP = '+' | ca. OP = '-' | ca. OP = '*' | ca. OP = '/'))
{
CA. value2 = Ca. value2 * 10 + 4;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value2];
}
Else
{
CA. value1 = Ca. value1 * 10 + 4;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value1];
}
}
-(Ibaction) button5 :( ID) sender {
If (ca. OP = '+' | ca. OP = '-' | ca. OP = '*' | ca. OP = '/'))
{
CA. value2 = Ca. value2 * 10 + 5;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value2];
}
Else
{
CA. value1 = Ca. value1 * 10 + 5;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value1];
}
}
-(Ibaction) button6 :( ID) sender {
If (ca. OP = '+' | ca. OP = '-' | ca. OP = '*' | ca. OP = '/'))
{
CA. value2 = Ca. value2 * 10 + 6;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value2];
}
Else
{
CA. value1 = Ca. value1 * 10 + 6;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value1];
}
}
-(Ibaction) button7 :( ID) sender {
If (ca. OP = '+' | ca. OP = '-' | ca. OP = '*' | ca. OP = '/'))
{
CA. value2 = Ca. value2 * 10 + 7;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value2];
}
Else
{
CA. value1 = Ca. value1 * 10 + 7;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value1];
}
}
-(Ibaction) button8 :( ID) sender {
If (ca. OP = '+' | ca. OP = '-' | ca. OP = '*' | ca. OP = '/'))
{
CA. value2 = Ca. value2 * 10 + 8;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value2];
}
Else
{
CA. value1 = Ca. value1 * 10 + 8;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value1];
}
}
-(Ibaction) button9 :( ID) sender {
If (ca. OP = '+' | ca. OP = '-' | ca. OP = '*' | ca. OP = '/'))
{
CA. value2 = Ca. value2 * 10 + 9;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value2];
}
Else
{
CA. value1 = Ca. value1 * 10 + 9;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value1];
}
}
-(Ibaction) button0 :( ID) sender {
If (ca. OP = '+' | ca. OP = '-' | ca. OP = '*' | ca. OP = '/'))
{
CA. value2 = Ca. value2 * 10 + 0;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value2];
}
Else
{
CA. value1 = Ca. value1 * 10 + 0;
Self. labble. Text = [nsstring stringwithformat: @ "% F", Ca. value1];
}
}
-(Ibaction) function :( uibutton *) sender {
If (sender. Tag = 1)
{
CA. Op = '+ ';
[Email protected] "+ ";
I = 1;
}
Else if (sender. Tag = 2)
{
CA. Op = '-';
[Email protected] "-";
I = 2;
}
Else if (sender. Tag = 3)
{
CA. Op = '*';
[Email protected] "*";
I = 3;
}
Else if (sender. Tag = 4)
{
CA. Op = '/';
[Email protected] "/";
I = 4;
}
}
-(Ibaction) Clear :( ID) sender {
CA. value2 = 0;
CA. value1 = 0;
CA. Op = 0;
Result = 0;
Self. labble. Text = [nsstring stringwithformat: @ "% F", result];
}
-(Ibaction) buttondeng :( ID) sender {
If (I = 1)
{
Result = Ca. value1 + Ca. value2;
Self. labble. Text = [nsstring stringwithformat: @ "% F", result];
}
Else if (I = 2)
{
Result = Ca. value1-ca.value2;
Self. labble. Text = [nsstring stringwithformat: @ "% F", result];
}
Else if (I = 3)
{
Result = Ca. value1 * ca. value2;
Self. labble. Text = [nsstring stringwithformat: @ "% F", result];
}
Else if (I = 4)
{
Result = Ca. value1/CA. value2;
Self. labble. Text = [nsstring stringwithformat: @ "% F", result];
}
}
-(Void) didreceivememorywarning {
[Super didreceivememorywarning];
// Dispose of any resources that can be recreated.
}
@ End
3. Images