In my class, we went over this stuff briefly and now that it's time to apply it, I'm completely confused. The book hasn't helped much either.
1 2 3 4 5 6 7 8 9 10 11
MassData getMassData(T x[], T y[], T m[], int numDataPoints);
MassData getMassData(T x[], T y[], T m[], int numDataPoints){
MassData massData;
massData.cenMassX = 0;
massData.cenMassY = 0;
massData.totMass = 0;
return massData;
}
Here's the portion of my code that is relevant. Not only am I confused about finding the center of mass of the 13-sided irregular shape (given its coordinates and side lengths), but how I would output this is my main function.
How would I output something like: Total Mass:
Center of Mass:
Obviously those statements use cout, but I don't know how to output the calculated values.
You want to output the members of a struct? Is that your question? If yes you could do it this way (C):
1 2 3 4 5 6 7 8 9
#include <cstdio>
int main()
{
MassData massData;
// initialization and calculus...
printf("%d %d\n", massData.cenMassX, massData.cenMassY); // assuming those two members are int
return 0;
}
Or the C++ way:
1 2 3 4 5 6 7 8 9 10 11
#include <iostream>
usingnamespace std;
int main()
{
MassData massData;
// initialization and calculus...
cout<<massData.cenMassX<<" "<<massData.cenMassY<<endl;
return 0;
}