Use xcode6 to make a powerful Calculator

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.