Thread: Identifying conic sections

  1. #1
    Registered User
    Join Date
    Oct 2013
    Location
    Tagbak, Iloilo, Philippines, Philippines
    Posts
    7

    Question Identifying conic sections

    Hey guys, I'm a beginner, and I need help, I just finished a program on how to Identify any kinds of conic sections like circle,hyperbola, parabola and ellipse.
    I dont about the other codes, they work but I think they are wrong, please help me, I need to finish so that I can proceed to another program, I need to find what is the wrong in this equation, I dont know why the answer for eccentricity and others are different If I solved it manually. please guys help me..

  2. #2
    Registered User
    Join Date
    Oct 2013
    Location
    Tagbak, Iloilo, Philippines, Philippines
    Posts
    7

    My program

    this is my program:
    Code:
    #include<>
    #include<>main()
    {
       int A,B,C;
       float E,L,D,P;
       clrscr();
       printf("Enter A:\n");
       scanf("%d",&A);
       printf("Enter B:\n");
       scanf("%d",&B);
       printf("Enter C:\n");
       scanf("%d",&C);
       printf("\nThis is the General Equation of all Curves: Ax^2+By^2+Cxy+Dx+Ey+F=0");
       printf("\nThis Equation is a:");
    
    
       if ( A==B || C==0 )
          printf("\tCircle");
       else if ( A==0 && C>0 || C==0 && A>0)
          {
          printf("\tParabola");
          printf("\n\ny^2 = 4ax");
          E=1.0;
          printf("\n\nEccentricity:%f",E);
          L= 4*A;
          printf("\nLatus Rectum:%f",L);
          }
       else if ((B^2)-4*A*C<0)
          {
          printf("\tEllipse");
          printf("\n\n(x/a)^2 + (y/b)^2 = 1");
          E= sqrt (1-(B/A)^2);
          printf("\n\nEccentricity:%f",E);
          D= sqrt ((B^2)-(A^2));
          printf("\nLinear Eccentricity:%f",D);
          L= 2*B^2/A;
          printf("\nLatus Rectum:%f",L);
          P= B^2/sqrt (B^2-A^2);
          printf("\nFocal Parameter:%f",P);
          }
       else if ((B^2)-4*A*C>0)
          {
          printf("\tHyperbola");
          printf("\n\n(x/a)^2 - (y/b)^2 = 1");
          E= sqrt (1+(B/A)^2);
          printf("\n\nEccentricity:%f",E);
          D= sqrt ((B^2)+(A^2));
          printf("\nLinear Eccentricity:%f",D);
          L= 2*B^2/A;
          printf("\nLatus Rectum:%f",L);
          P= B^2/sqrt (B^2+B^2);
          printf("\nFocal Parameter:%f",P);
          }
       getch();
       return 0;
    }

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    A^2 is not the same as A*A

    Also line 17 - should it not be && to be a circle? I do not think 5*x*x+6*y*y = 7 is circle
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Oct 2013
    Location
    Tagbak, Iloilo, Philippines, Philippines
    Posts
    7
    oh ok, then I will change it to && then??.

  5. #5
    Registered User
    Join Date
    Oct 2013
    Location
    Tagbak, Iloilo, Philippines, Philippines
    Posts
    7
    I base on this site about the general form of this program Conics General Form

  6. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    ROFL! < This is a "Latus Rectum" >? ROFL!

  7. #7
    Registered User loserone+_+'s Avatar
    Join Date
    Dec 2012
    Location
    Indonesia
    Posts
    112
    ^ is bitwise operator right ?

  8. #8
    Registered User
    Join Date
    Oct 2013
    Location
    Tagbak, Iloilo, Philippines, Philippines
    Posts
    7
    Quote Originally Posted by loserone+_+ View Post
    ^ is bitwise operator right ?
    I don't know, I'm just a beginner I manage to made the program running but I don't know if it is the right codes..

  9. #9
    Registered User
    Join Date
    Oct 2013
    Location
    Tagbak, Iloilo, Philippines, Philippines
    Posts
    7
    can you teach me the right codes?? or can you pin point the wrong ones in my program?? please

  10. #10
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by RobertoRD5 View Post
    I don't know, I'm just a beginner I manage to made the program running but I don't know if it is the right codes..
    Well look it up.

    vart and loserone gave you a hint as to one of the things wrong with your program.

    I'll give another: A, B, and C are all defined in your code as ints. Your code calculates B/A in a few places. That does integer division, which produces an integral result. So 3/2 will give the result of 1, not 1.5.

    Every basic textbook on C describes what the ^ operator does, and also describes how integer division works. You will learn more by working out what is going on. The hints you've been given are sufficient to get you started. You might have to work a bit, but you WILL learn in the process. Whereas, if people just fix your code, you will learn NOTHING.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  11. #11
    Registered User
    Join Date
    Oct 2013
    Location
    Tagbak, Iloilo, Philippines, Philippines
    Posts
    7
    Quote Originally Posted by grumpy View Post
    Well look it up.

    vart and loserone gave you a hint as to one of the things wrong with your program.

    I'll give another: A, B, and C are all defined in your code as ints. Your code calculates B/A in a few places. That does integer division, which produces an integral result. So 3/2 will give the result of 1, not 1.5.

    Every basic textbook on C describes what the ^ operator does, and also describes how integer division works. You will learn more by working out what is going on. The hints you've been given are sufficient to get you started. You might have to work a bit, but you WILL learn in the process. Whereas, if people just fix your code, you will learn NOTHING.
    oh I see now where I'm wrong, thanks guys for the clues, I REALLY APPRECIATE IT, THANK YOU SO MUCH, Now I understand how ^ and int works, hmm.. maybe I need some tutorial about C programming after all.. hehehe

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [HELP] Program that checks conic section
    By Arbyn Acosta in forum C Programming
    Replies: 3
    Last Post: 09-19-2012, 08:50 AM
  2. Replies: 17
    Last Post: 03-15-2012, 05:30 AM
  3. Semaphores and critical sections
    By Yasir_Malik in forum Windows Programming
    Replies: 3
    Last Post: 04-01-2006, 11:02 AM
  4. Critical Sections, destroying
    By Hunter2 in forum Windows Programming
    Replies: 4
    Last Post: 09-02-2003, 10:36 PM
  5. When to use Critical Sections in Threads?
    By Aidman in forum Windows Programming
    Replies: 8
    Last Post: 07-20-2003, 05:10 PM

Tags for this Thread