Note that there are some explanatory texts on larger screens.

plurals
  1. POSolve pythagoras theorem in Objective-C
    primarykey
    data
    text
    <p>I am working on a programm which lets you calculate the sides in a triangle using the Pythagoras method. I recently posted my first question about this. How can I code it so that you can also work out B or A. Here is my code so far: </p> <p><strong>PythagorasCalc.m</strong></p> <pre><code> #import "PythagorasCalc.h" @implementation PythagorasCalc - (double)calculatePythagorasValue { return sqrt(A*A+B*B); } //Access Code - (double)A { return A; } - (void)setA: (double)value { if(A != value) { A = value; } } - (double)B { return B; } - (void)setB: (double)value { if(B != value) { B = value; } } - (double)C { return C; } - (void)setC: (double)value { if(C != value) { C = value; } } @end </code></pre> <p><strong>PythagorasCalc.h</strong></p> <pre><code> #import &lt;Cocoa/Cocoa.h&gt; @interface PythagorasCalc : NSObject { @private int A; int B; int C; } @property (nonatomic) double A; @property (nonatomic) double B; @property (nonatomic) double C; - (double)calculatePythagorasValue; @end </code></pre> <p><strong>AppDelegate.m</strong></p> <pre><code>#import "PythagorasCalculatorAppDelegate.h" @implementation PythagorasCalculatorAppDelegate - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { calculator = [[PythagorasCalc alloc] init]; } - (IBAction)calculateClicked:(id)sender { double A = _ATextField.doubleValue; double B = _BTextField.doubleValue; double C = _CTextField.doubleValue; calculator.A = A; calculator.B = B; calculator.C = C; _CTextField.doubleValue = [calculator calculatePythagorasValue]; } @end </code></pre> <p><strong>AppDelegate.h</strong></p> <pre><code>#import &lt;Cocoa/Cocoa.h&gt; #import "PythagorasCalc.h" @interface PythagorasCalculatorAppDelegate : NSObject &lt;NSApplicationDelegate&gt; { //Public Calculator Object PythagorasCalc *calculator; } @property (assign) IBOutlet NSWindow *window; - (IBAction)calculateClicked:(id)sender; @property (weak) IBOutlet NSTextField *ATextField; @property (weak) IBOutlet NSTextField *BTextField; @property (weak) IBOutlet NSTextField *CTextField; @end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload