Gravity in C++ using classes and lists (no graphical representation)

Hi!

What I need to achieve is a program which will simulate gravity in 2D plane (only x and y axis), using Euler equation, based on class of an astronomical object and a list of said objects.

As for the object, I need to give it both positions, a mass and a velocity (if it exists from the beginning). Radius is ignored, since I'm not going into collisions.

Then, I was told to recalculate every object's position and velocity accordingly, when I add a new object to the list, based on this new object's mass.

I have no idea how to do this, since all of this should be determined by time, right? It's a constantly changing situation, especially without taking collision into account. This means that all the objects will be inifnitely spinning and flying around, so I can't simply say "well, upon adding a new object, the previous one moved to XY and stayed there".

I tried searching for that before, but most gravity projects use Box2D engine or similar libraries, while everything I need to do is to use a simple class, a list and a formula.

I know the maths behind it, Gravitational Constant, force equations and whatnot, but I have absolutely no clue how to implement this. I'm having a big problem, since the assignment is for Monday, and having a lot of work on my own (I have a freshly started-up company) I forgot a lot from C++ lectures.

I will be really grateful if anyone could help me with that, thanks in advance!

P.S. I've already seen http://www.cplusplus.com/forum/beginner/60975/ - but it's based on one, big mass in the center, to which every other object relates to. What I need is to create a class, which will be a list for an object class, using pointers, then every new object in the list will change the parameters of the previous objects.
I've declared the class (not all the variables are there)

1
2
3
4
5
6
7
8
9
10
11
class CBody  
    {  
    protected:  
        double x;  
        double y;  
        double mass;  
    public:  
        void move(double time, list<CBody> CBodyList);  
        CBody();  
        ~CBody();  
    };

but I am unable to come up with the right method how to exactly make the new list object's values alter the position (by move() method) of the previous ones and represent it in time.

Do you have any ideas? Basically what I want to achieve is that whenever I add a new object with given values (I'm using rand() right now, but I'll probably use cin>>stuff later) it triggers a move() method inside every previous celestial body and adjusts their position accordingly. The problem is - it's not a fixed state, it's happening all the time, how to define the time exactly?

Big thanks for any clarification!

EDIT: Do I need to declare the list before passing it as a parameter in method? Above code causes errors in VS2010, saying that C2061: syntax error : identifier 'list'. What's wrong?
Topic archived. No new replies allowed.