Amazon.com Widgets Solution to Exercise 4 Chapter 11..!
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 25, 2013, 02:07:05 AM
Home Help Search chat Login Register   
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+  Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+  Old Stuff
| |-+  Answers to Exercises
| | |-+  Chapter 11
| | | |-+  Solution to Exercise 4 Chapter 11..!
Pages: [1]   Go Down
Print
Author Topic: Solution to Exercise 4 Chapter 11..!  (Read 422 times)
danish
Newbie
*
Posts: 16


Email




« on: August 15, 2011, 07:19:11 AM »

//  CalculatorTrig.h
Code: (Objective-C)
#import "Calculator.h"
#import <Math.h>

@interface Calculator (CalculatorTrig)

- (double) sin;
- (double) cos;
- (double) tan;

@end


//  CalculatorTrig.m
Code: (Objective-C)
#import "CalculatorTrig.h"

@implementation Calculator (CalculatorTrig)

- (double)sin
{   
    d = sin(number);
   
    return d;
}

- (double)cos
{
    d = cos(number);
   
    return d;
}

- (double)tan
{
    d = tan(number);
   
    return d;
}

@end

//  Calculator.h
Code: (Objective-C)
#import <Foundation/Foundation.h>

@interface Calculator : NSObject
{
    double number;
    double d;
}

@property double number, d;

- (void) print;


@end


//  Calculator.m
Code: (Objective-C)
#import "Calculator.h"

@implementation Calculator

@synthesize number, d;

- (void)print
{
    printf("%.2f\n", d);
}

@end


//  main.m
Code: (Objective-C)
#import "CalculatorTrig.h"

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
   
    Calculator *myCalc = [[Calculator alloc] init];

    [myCalc setNumber:4];
   
    [myCalc tan];
    [myCalc print];
   
    [myCalc sin];
    [myCalc print];
   
    [myCalc cos];
    [myCalc print];
   
    [myCalc release];
    [pool drain];
    return 0;
}

cheers...  Smiley
Logged
danish
Newbie
*
Posts: 16


Email




« Reply #1 on: August 15, 2011, 07:23:17 AM »

You dont have to import the math.h in the category header file..my bad..math.h gets imported automatically when you import Foundation.h

cheers..  Smiley
Logged
Pages: [1]   Go Up
Print
Jump to:  



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.