Note that there are some explanatory texts on larger screens.

plurals
  1. POAssistance needed writing simple Objective-C program
    text
    copied!<p>I have been struggling along with an online objective-c class for a few weeks now. I'm feeling very stupid.. My latest assignment is to write a program that demonstrates a class named Circle by asking the user for the circle's radius, creating a Circle object, and then reporting the circle's area, diameter, and circumference. We should have the following member variables:</p> <pre><code>radius: a double pi: a double initialized to 3.14159 </code></pre> <p>and the following member functions:</p> <pre><code>setRadius - a mutator function for the radius variable getRadius - an accessor function for the radius variable getArea - returns the area of the circle, which is calculated as: area = pi * radius * radius getDiameter - returns the diameter of the circle, which is calculated as: diameter = radius * 2 getCircumference - returns the circumference of the circle, which is calculated as: circumference = 2 * pi * radius </code></pre> <p>The member variables of the class should be set as private.</p> <p>Here is my program so far:</p> <p>Main:</p> <pre><code>int main(int argc, const char * argv[]) { @autoreleasepool { int radius; NSLog(@"Enter the circles radius:"); scanf ("%d", &amp;radius); } return 0; } </code></pre> <hr> <p>Interface:</p> <pre><code>#import &lt;Foundation/Foundation.h&gt; //circle class @interface circle : NSObject { @private -(double) radius; -(double) pi; } @property int setRadius, getRadius; -(double) getArea; -(double) getDiameter; -(double) getCircumcerence; @end </code></pre> <hr> <p>Implementation: </p> <pre><code>#import "circle.h" @implementation circle @synthesize setRadius, getRadius; -(double) pi { pi = 3.14159; } -(double) getArea { pi * radius * radius; } -(double) getDiameter { radius * 2; } -(double) getCircumcerence { 2 * pi * radius; } @end </code></pre> <p>As you can see, I haven't gotten very far. I am confused as how to simply utilize my methods in my main, and am sure I have already made mistakes. </p> <p>Any advice is appreciated! I really need help, and am short on time. Also, this may be far-fetched but if anyone could maybe skype with me and help me through it? Thanks!</p>
 

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