Thread: Determining a Triangle using get and pointer

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    2

    Unhappy Determining a Triangle using get and pointer

    a. Define a struct data type to represent a triangle as 3 points.
    b. Write a function get_triangle(), to input the three corners of a triangle and return triangle structure. Using triangle get_triangle()
    c. Write a function classify(); that will analize the shape of triangle. The input should be one triangle and the result should be a pointer to a character array. Prototype is: char * classify triangle.
    d. Write a main program with loop which will permit user to enter a series of triangles. For each echo the input, call the classify() fuction and print the triangles shape. (isosceles 2 sides equal, equilateral all sides same, or scalene no sides are equal).
    The problem I am having so far is how call to classify and determine which shape it is.
    #include <stdio.h>

    typedef struct {
    double x;
    double y;
    } point;

    int main()
    {
    point A;
    point B;
    point C;
    A . x=5;
    A . y=4;
    printf("Enter the X and Y for Point A:");
    scanf ("%lg%lg", &A.x, &A.y);
    printf("Enter the X and Y for Point B:");
    scanf ("%lg%lg", &B.x, &B.y);
    printf("Enter the X and Y for Point C:");
    scanf ("%lg%lg", &C.x, &C.y);
    printf ("The values entered for X and Y for Point A: %g\t %g\n",A.x,A.y);
    printf("The values entered for X and Y for Point B: %g\t %g\n",B.x,B.y);
    printf("The values entered for X and Y for Point C: %g\t %g\n",C.x,C.y);

    return 0;
    }

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    //+----------------------------------------------
    //| Magos' flame template v1.00
    //+----------------------------------------------

    Dear:

    [ ] Sir
    [ ] Madam
    [ ] Lazy person
    [X] Student with a program assignment
    [ ] Rupert
    [ ] Ugly naked guy


    You are being flamed because:

    [ ] You've shown an aggressive attitude towards someone in your post
    [X] You're asking us to your homework
    [ ] You haven't search google for the answer you're looking for
    [ ] You expect us to write an entire program for you
    [X] You haven't shown enough effort in this assignment
    [ ] You're a complete jerk
    [ ] You want us to debug your entire buggy program for you
    [ ] You lack valid arguments
    [ ] You degraded my momma
    [ ] You deny your own fault, blaming it on others
    [ ] Your post is completely unreadable


    I suggest you:

    [ ] Make a search on google
    [ ] Read the FAQ
    [ ] Read the forum rules/guidelines
    [ ] Rephrase your question
    [X] Make some further attempt to complete your assignment
    [ ] Release your anger somewhere else
    [X] Insert code tags around your code
    [X] Try to isolate the problem, then post again
    [ ] Check your spelling
    [ ] Check your grammar


    Finally, I'd also like to say:

    [X] Fix the things above, and we'll be happy to help you next time
    [X] Please, use code tags next time
    [ ] Don't make a post like this again
    [ ] Have a nice day!
    [ ] Your momma is fat
    Last edited by Magos; 04-10-2003 at 03:18 PM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    [X] You momma is fat
    --edit--
    lol, i think he meant "your"
    The keyboard is the standard device used to cause computer errors!

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    2
    What I was asking is not to do the homework, but to help with how to use char * classify triangle.

  5. #5
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    >>char *
    just means pointer to character. like

    Code:
    char stringer[11] = {"Hey People");
    char *stringerPtr = stringer;
    //now *stringer points to the address this string, actually, the address of the first element.
    The keyboard is the standard device used to cause computer errors!

  6. #6
    Registered User
    Join Date
    Mar 2003
    Posts
    7
    You guys are evil!
    What do you mean about code tags? I put up a post before and I didn't have that. Anyways I think she is looking for a way to use the gets function instead of scanf. To put in the points and find out what kind of triangle it is. Which I have no idea how to. And why would you care if you helped write the code anyway, maybe you just don't know how to answer the problem and if that is the case then don't even reply back, people don't have time for that and stop trying to be so cute, you're trying too hard and it's not working Magos. : P
    sue

  7. #7
    eh ya hoser, got a beer? stumon's Avatar
    Join Date
    Feb 2003
    Posts
    323
    Please do not start posting throw backs at one another. He asked for help, we cant help until he gives us more information. All we see if scanf()'s, where is the beginning of the function that tells how to figure out what kind of triangle it is, its just a bunch of math to figure where the points are on a graph. No one is going to write all his code, he gives us what he has as far as that function and we help. Its that simple. Magos was just asking for more info in his own little way.
    --edit-- See:
    I suggest you:

    [ ] Make a search on google
    [ ] Read the FAQ
    [ ] Read the forum rules/guidelines
    [ ] Rephrase your question
    [X] Make some further attempt to complete your assignment
    [ ] Release your anger somewhere else
    [X] Insert code tags around your code
    [X] Try to isolate the problem, then post again
    [ ] Check your spelling
    [ ] Check your grammar
    The keyboard is the standard device used to cause computer errors!

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Chill down, the flame template was meant as a joke.
    The problem I am having so far is how call to classify and determine which shape it is.
    This was basically my point for posting that. You're telling us you have a problem with something, but not with what. You just posted the code where you enter the points for the triangle. Where are you stuck? What part don't you understand? Is it the formula for checking if a triangle is valid? Is it the formula -> code transformatin? Please be more specific, we are not mind readersyou know .

    If it's the formula, there is three cases: The shape is a point, a line or a triangle.

    First, check if any of the points overlap (Xi = Xj & Yi = Yj for every point). If they do (if one do it's enough), it's not a triangle.

    Second, if the points lie on a straight line it is not a triangle. To check this, calculate the slope between the lines and check if they are the same. if they are, it's not a triangle. (It's enough to just calculate two of the three slopes. If two of them are equal, the third has to be too).
    To caluclate the slope, use K = (Yi - Yj) / (Xi - Xj).

    This concept must be 32978589275892728978972 years old.
    Never said I invented it...

    What do you mean about code tags? I put up a post before and I didn't have that.
    You should always use code tags when posting code (the exception would be one- or two-liners). Code tags have a purpose, you know. It makes the code easier to read, it indents properly, and every character have the same width.
    Please read the Forum guidlines before making the next post.

    Oh, and if you mean this post:
    http://cboard.cprogramming.com/showt...threadid=37270
    You were told to use code tags!

    Anyways I think she is looking for a way to use the gets function instead of scanf. To put in the points and find out what kind of triangle it is. Which I have no idea how to.
    I don't know how you got that out of her (!) post, though I agree that gets is better than scanf. Oh, and you should use fgets, not gets. See the FAQ.

    And why would you care if you helped write the code anyway,
    I usually don't mind writing code for others, as long as I find it interesting myself.

    maybe you just don't know how to answer the problem and if that is the case then don't even reply back, people don't have time for that
    What can I say? Read the forum guidlines first. Too lazy to search? (Search? It's at the top of every page...), follow these links:
    http://cboard.cprogramming.com/annou...p?s=&forumid=3
    http://cboard.cprogramming.com/showt...threadid=13473

    and stop trying to be so cute, you're trying too hard and it's not working Magos. : P
    Cute???
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed