views:

81

answers:

1

So I've made easy math programs with C before, but my task at hand is a bit complex for where my knowledge is at the moment.

I need to take the calculator found here (calculator: http://ohts.wustl.edu/risk/calculator.html, appendix which covers it a bit: http://ohts.wustl.edu/risk/formula.html) and program it into a ObjC program. I'm having a hard time trying to figure out the weight/formula for this. Hoping to find help in the right direction on how I can figure this out.

A: 

All of the implementation is C only, it makes no sense to wrap doubles in NSNumber.

#import <Cocoa/Cocoa.h>

@interface GRE:NSObject
@end
@implementation GRE
+ (NSNumber *) compute:(double) age :(double) iop :(double) cct :(double) vcd :(double) psd
{
        double meanage =  5.64301, betaage = 0.23260;
        double meaniop =  24.1386, betaiop = 0.09025;
        double meancct = -14.3349, betacct = 0.71503;
        double meanpsd =  9.76001, betapsd = 0.12376;
        double meanvcd =  3.60828, betavcd = 0.17689;
        double S0_t = 0.91831;

        double t_cct = -1.0 * (cct/40.0);
        double t_psd = psd / .2;
        double t_vcd = vcd / 0.1;

        double agedecade = age / 10.0;
        double xbetamean = (agedecade - meanage) * betaage +
                (iop - meaniop) * betaiop +
                (t_cct - meancct) * betacct +
                (t_psd - meanpsd) * betapsd +
                (t_vcd - meanvcd) * betavcd;

        double risk = 1 - pow(S0_t, exp(xbetamean));
        return [NSNumber numberWithDouble:risk];
}
@end
int main()
{
        NSAutoreleasePool * p = [NSAutoreleasePool new];

        NSLog(@"Risk: %@", [GRE compute:(55) :(24) :(540): (.40) : (2.2)]);

        [p release];
}
diciu