structures

hey guys!

i'm wondering for this question i'm not exactly sure what it is asking me to do:

Consider the following struct definition

struct Triangle
{
double sideA, sideB, sideC;
};

Write a definition isEquilateral that when passed a Triangle object “myTriangle” returns true if the triangle IS equilateral (all sides are equal) and false otherwise.


It's not asking for a function so does that mean it involves nested structures? If so, how do i proof equality in a nested structure?
Actually, it is asking for a function that takes a Triangle object as its argument.

EDIT: Though I must say, that was one ambiguous command.

-Albatross
Last edited on
Are you sure, the previous questions, asked to 'Complete the following functions', 'define the following functions' so I thought this would be different...

Thanks
Okay... on second thought, maybe it's asking for a function that takes a reference pointer to a struct as an argument that will modify a boolean value inside it called isEquilateral. Or maybe the first now crossed out one...

This is ridiculously ambiguous, and I'd ask that a few other forum members help you out on this one.

One thing's for sure: you can't store functions in structs.

EDIT: Oh, and you need to declare a myTriangle somewhere.

-Albatross
Last edited on
Can final12 confirm that he has posted the question correctly.

But I think it is asking for a function (judging by the terms"passed a Triangle object" and returns true.)
yes the question is correct
Also does anyone know a algorithm to determine an isosceles triangle where 3 sides are given

a==b || b==c || a==c works but for any 2 sides that are the same but also includes if all 3 sides are the same hence not being isosceles.
I think its is asking for a function.

1
2
3
4
bool isEquilateral(const Triangle& t)
{
	return //  ... do calculation here ...
}


I can't see how you would loose marks by presenting your answer in function form.
Last edited on
final12 wrote:
Also does anyone know a algorithm to determine an isosceles triangle where 3 sides are given

a==b || b==c || a==c works but for any 2 sides that are the same but also includes if all 3 sides are the same hence not being isosceles.


Lets start with the first of the 3 tests.

If a==b we don't want c to be equal to a or b.

so we can say

(a==b && c !=a)


So the first part is:
(a==b && c !=a)|| b==c || a==c

Do something similar for the other 2 parts
final12 wrote:
a==b || b==c || a==c


Change your ors to ands.

-Albatross.
Wouldn't that be for an equilateral triangle??
Yes.

-Albatross
Last edited on
Topic archived. No new replies allowed.