help. having trouble converting c to c++


#include <stdio.h>
#include <string.h>
#include <math.h>

#define r 1e+3
#define m0 100e+3
#define g 9.81

main()
{
double m();
double p();
double k;
double dt=1;
double t;
double T;
double x0,x1,x2;

T=1.1*m0*g;

k=m0*g/1000;

x0=0;
x1=1;

printf("0.0000 %f\n", x0);
printf("%f %f\n", dt, x1);

for (t=dt; t<90; t+=dt)
{
x2=(4*m(t)*x1-(2*m(t)-dt*(-r+k*p(x1)))*x0-2*dt*(m(t)*g-T))/(2*m(t)+dt*(-r+k*p(x1)));
x0=x1
x1=x2

print f("%f %f\n", t+dt, x2);
}
}

float m(t)
float t;
{
return(m0-r*t);
}

float p(x)
float x;
{
return(exp(-x/1000));
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <cstdio>
#include <string>
#include <cmath>

#define r 1e+3
#define m0 100e+3
#define g 9.81

double m(float);
double p(float);

int main()
{
    double k;
    double dt=1;
    double t;
    double T;
    double x0,x1,x2;

    T=1.1*m0*g;

    k=m0*g/1000;

    x0=0;
    x1=1;

    printf("0.0000 %f\n", x0);
    printf("%f %f\n", dt, x1);

    for (t=dt; t<90; t+=dt)
    {
        x2=(4*m(t)*x1-(2*m(t)-dt*(-r+k*p(x1)))*x0-2*dt*(m(t)*g-T))/(2*m(t)+dt*(-r+k*p(x1)));
        x0=x1;
        x1=x2;

        printf("%f %f\n", t+dt, x2);
    }
    return 0;
}

double m(float t)
{
    return(m0-r*t);
}

double p(float x)
{
    return(exp(-x/1000));
}


What does it calculate?
thank you. it calculates rocket launch trajectory
Topic archived. No new replies allowed.