Objective-c Seventh Post-lesson Exercise 3

Source: Internet
Author: User

Q: Does the fraction class apply to negative fractions? For example: Can 1/4-1/2 be displayed as-1/4?

1 //--------class definition implementation refer to the previous essay, where you need to change the print method and main Main method Section----------2- (void) Print: (BOOL) Yesorno//Print3 {4     if(Yesorno = =YES) {5 [self reduce];6     }7     8     if(Num <0)9     {Tennum =-num; OneNSLog (@"-%i/%i", Num,den); A     } -     Else -     { theNSLog (@"%i/%i", Num,den); -     } - } -  +-(Fraction *) subfraction: (Fraction *) F - { +Fraction *result =[[Fraction alloc]init]; A      atResult.num = num * F.den-den *F.num; -Result.den = den *F.den; -      -     //[result reduce]; -      -     returnresult; in      - } to  +  - #import<Foundation/Foundation.h> the #import "Fraction.h" *  $ intMainintargcConst Char*argv[]) {Panax Notoginseng @autoreleasepool { -Fraction *MYF =[[Fraction alloc]init]; theFraction *myf_2 =[[Fraction alloc]init]; +Fraction *Myresult; A          the         intI//accept input 1 or 0 +BOOL b;//Boolean type to determine the value of I -          $[MyF SETN:1ANDSETD:4]; $[Myf_2 SETN:1ANDSETD:2]; -          -NSLog (@"need to simple? 1 or 0");//prompt to enter 1 or 0 thescanf"%i",&i); -b = i;//Pass the I value to the Boolean type B to determine whether to reduce the scoreWuyi          theMyresult = [MyF subfraction:myf_2];//Subtraction - [Myresult print:b]; Wu          -Myresult = [MyF mulfraction:myf_2];//multiplication About         //[Myresult print]; $          -Myresult = [MyF divfraction:myf_2];//Division - [Myresult print:b]; -          A         //[Myresult print]; +          the          -     } $     return 0; the}

Objective-c Seventh Post-lesson Exercise 3

Related Article

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.