-
I Need Help
ive been up for 2 days now. yes thats 48 hrs. my teach wants us to create a calculator that can do complex number. he wants use to have functions take in values, functions that take those values and do add, subtract, etc. BUT, he said to use structs for complex numbers. I HAVE NO IDEA WHAT HE MEANS. I HAVE NO IDEA WTF A STRUCT IS USED FOR. I M GONNA KILL MYSELF IF I CANT GET SLEEP SOON!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
-
A struct is a class with every member function/data public.
-
a) I don't see a reason why you shouldn't be sleeping.
b) A struct is a definition of a variable type that has more than one member and may have functions that operate on it.
Example:
struct Point
{
int x;
int y;
};
int main()
{
Point p;
p.x = 4;
p.y = 7;
return 0;
}
Obviously, each complex number has two parts, too. Both belong to the same variable.
-
the grunt work comes when you need to, depending on how functional you want the program to be, overload the various functions/operators, sometimes multiple times to allow for things like:
complex + complex versus
comple + int versus
int + complex versus
double + complex versus
complex + double
or else write templated functions to cover all the various possibilities,
etc. for the -, *, / operators and whatever else.