Help with simple problem

Apr 11, 2019 at 4:38pm
I am learning to code and am trying to work through some old practice problems from American Computer Science League competitions. One that I had come across to take a crack at is the Junior division contest#4 from 2001-2002 (https://www.acsl.org/acsl/sample_ques/c_4_conic_jr.pdf). I was wondering if anyone had some time to walk through it with me. Or had a solution I could check along side my code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "stdafx.h"
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string eqnType;
    // variabletype? centerPos;
    //int radius; 

    // Create an array structure for a six entry array to fill the general eqn.
    struct arrayInputs
    {
        float A, B, C, D, E, F;
    };

    // number of slots in the  array 
    struct arrayInputs coef[5];

    // Asking for and inputing values for the coefficents in of the 5 eqns. 
    for (int i = 1; i < 6; ++i)
    {
        cout << "Enter the coefficients for equation number " << i << ": ";

        cin >> coef[i].A >> coef[i].B >> coef[i].C >> coef[i].D >> coef[i].E >> coef[i].F;

        cout << "\n";

        //simple output of the values positioned in the form of the eqn

        cout << "General Equation number " << i << " is: " << coef[i].A << "x^2 + "
            << coef[i].B << "xy + " << coef[i].E << "y^2 + " << coef[i].D << "x + " << coef[i].E
            << "y + " << coef[i].F << " = 0 " << endl;

        /*
        In here I'm going to simplify the eqn with the coefficents given by the user 
        Once the eqn is in the simplified form, I can extract the 
        center position ( variable centerPos ). What type of variable would I want to use for this?

        as well as be able to extract the radius. 

        */

        if ( coef[i].A == coef[i].C )
        {
            eqnType = "Circle";
        }
        else
        {
            eqnType = "Ellipse";
        }

        cout << eqnType;// << ", " << centerPos << ", " << radius << endl;
    }

    return 0;
}


I'm not completed yet, but this is what I have so far.

Any help would be appreciated
Thank you


I'm working through the suggestions now. I'll get back.
Last edited on Apr 11, 2019 at 7:10pm
Apr 11, 2019 at 6:42pm
The link you posted is broken. Did you mean this? http://www.acsl.org/acsl/sample_ques/c_4_conic_jr.pdf

To be a circle or elipse, B must be zero, so you should check that too.

I'd pick away at what you know you need. For example, let's start by creating structs that represent a circle and an ellipse in standard form:

struct Circle {
double u, v, r; // (x-u)2 + (y-v)2 = r2
};

struct Ellipse {
double u, v, r1, r2; // (x-u)2/r12 + (y-v)2/r22 = 1
};

Now we just have to set each of these members.

Also, I see that when completing the square for a circle, they assume that the coefficients for x2 and y2 are 1. So I ask myself but what if they aren't 1? Then I notice that for a circle, those coefficients (A & C) must be equal. So you can divide the whole equation by A and that makes A and C 1. Now it's just a question of plowing through the math:

1
2
3
4
5
6
7
8
9
10
11
12
       if ( coef[i].A == coef[i].C )
        {
            Circle c;
            // do the math to set the u, v, and r members of c
            eqnType = "Circle";
        }
        else
        {
            Ellipse e;
            // do the math to set the u, v, r1, and r2 members of e
            eqnType = "Ellipse";
        }


Hope this helps.
Last edited on Apr 11, 2019 at 7:01pm
Apr 11, 2019 at 6:57pm
Yes that's it!

But I have also been going back over the code and realizing I'm going at it in a over exaggerated way. making it more complicated than it needs to be.

Output:

Enter the coefficients for equation number 1: 3 4 3 5 6 4

General Equation number 1 is: 3x^2 + 4xy + 6y^2 + 5x + 6y + 4 = 0

Circle,

endOutput.

("need to learn how to properly simplify the above eqn to extract the center point and the radius")

also I now see that my entry for C variable in the output of the eqn was set to the E variable


Apr 11, 2019 at 7:01pm
I just executed it with the first example:
Enter the coefficients for equation number 1: 1 0 1 4 -6 -3

General Equation number 1 is: 1x^2 + 0xy + -6y^2 + 4x + -6y + -3 = 0 
CircleEnter the coefficients for equation number 2:  

A type in line 35 (after B follows C not E). Missing i) centre and radius/major axis and ii) a new line before the prompt for 2nd equation.
Topic archived. No new replies allowed.