Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9015555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:46:39+00:00 2026-06-16T03:46:39+00:00

I’m trying to build a good triangle class, seeing I use them a lot.

  • 0

I’m trying to build a good triangle class, seeing I use them a lot. I decided to modify my class so that the user can set a bool, to choose to use degrees rather than radians. Every thing still seems to work as it should, except it’s description, interestingly:

    IMTriangle *tri = [[IMTriangle alloc]init];
    tri.shouldUseDegrees = YES;
    tri.SideA = 3;
    tri.SideB = 4;
    tri.SideC = 5;

    [tri solve];
    NSLog(@"tri %@", tri);
    double A = tri.angleA;
    double B = tri.angleB;
    double C = tri.angleC;
    NSLog(@"A = %f  B = %f  C = %f",A,B,C);
    NSLog(@"tri  %@",tri);

Gives me this

tri a=3.0000 b=4.0000 c=5.0000 A=0.6435 B=0.9273 C=1.5708 perimeter=6.0000 area=12.0000 height=4.0000 shouldUseDegrees 1
A = 36.869897  B = 53.130098  C = 90.000004
tri  a=3.0000 b=4.0000 c=5.0000 A=36.8699 B=53.1301 C=90.0000 perimeter=6.0000 area=12.0000 height=4.0000 shouldUseDegrees 1

After I get the angles from my triangle object to use them, its description suddenly is as I would expect. I don’t know if it has something to do with the custom setters and getters I’m using:

-(void) setAngleA:(double)angleA
{
    if (!_shouldUseDegrees){
        _angleA = angleA;
    }
    else _angleA = angleA * M_PI/180;
}
-(double) angleA
{
    if (!_shouldUseDegrees) {
        return _angleA;
    }
    return  _angleA *= 180/M_PI;
}

or my description method

-(NSString *) description;
{

    return [NSString stringWithFormat:@"a=%.4f b=%.4f c=%.4f A=%.4f B=%.4f C=%.4f perimeter=%.4f area=%.4f height=%.4f shouldUseDegrees %i", _sideA , _sideB , _sideC , _angleA , _angleB , _angleC , self.area , self.perimeter , self.height ,_shouldUseDegrees];

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T03:46:40+00:00Added an answer on June 16, 2026 at 3:46 am

    You have two problems.

    First off, you need to stop reassigning _angleA in your accessor:

    return  _angleA *= 180/M_PI;
    

    That ought to be:

    return  _angleA * 180/M_PI;
    

    The other is that you want your printout in degrees. Since your instance variable is always holding radians, change _angleA, _angleB, _angleC to self.angleA, self.angleB, self.angleC to invoke your custom accessors instead of printing the values of the instance variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.