I want to preface by saying this is homework but any general advice is appreciated. I'm trying to write a program (a .cpp file and a header file) that when when coupled with this .cpp file:
-----------------------------------
#include "quaternion.h"
int main (int argc, char *argv[])
{
quaternion
a = quaternion (1),
b = quaternion (2, 5, 3.2, -2.15),
c = quaternion (0, -2.1, -0.34, 1.035);
cout << "a " << a << " b " << b << " c " << c << endl;
cout << "b+c: " << b + c << endl;
cout << "c-b: " << c - b << endl;
cout << "b*c: " << b * c << endl;
cout << "c*b: " << c * b << endl;
quaternion d = b / c;
cout << "b/c: " << d << " (and ans * c: " << d * c << ")\n";
cout << "Mess: " << a + b / c - (b-a) / (a + c) << endl;
return 0;
}
------------------------------------------
will result in the following output:
1 2 3 4 5 6 7
a 1+0i+0j+0k b 2+5i+3.2j+-2.15k c 0+-2.1i+-0.34j+1.035k
b+c: 2+2.9i+2.86j+-1.115k
c-b: -2+-7.1i+-3.54j+3.185k
b*c: 13.8133+-1.619i+-1.34j+7.09k
c*b: 13.8133+-6.781i+-0.02j+-2.95k
b/c: -2.46805+0.289271i+0.239421j+-1.26679k (and ans * c: 2+5i+3.2j+-2.15k)
Mess: 0.474285+-0.395755i+-0.397248j+-0.0230095k
@xeonn:
What you have written so far does neither fulfill requirements (for that part) nor is syntactically correct.
* What member variables must a quaternion have? (You have 5 members.)
* What constructers you are expected to have?
* How should one initialize member variables in a constructor?
What's in the directions is 100 percent of it, the rest is just turn in info. I know what I have so far is incorrect, it's the best I can do so far without asking the instructor. If I could be more specific id say the problem is trying to find out how to use constructors to add values in the same way one might add large numbers on paper, vertically but without carrying values of 10 over. Thank you for your response.
If I could be more specific id say the problem is trying to find out how to use constructors to add values in the same way one might add large numbers on paper, vertically but without carrying values of 10 over. Thank you for your response.
I'm not sure what you're saying, since you're not supposed to be adding anything in your constructors. By the way, I factored out the multiplication last night, it should be helpful: