D
dave.harper
I started learning C++ a few days ago, and I've run into a couple
questions regarding what is included in the executable when the source
is compiled... I've written a simple, 1-D rocket predicting program
that's under 2K prior to compiling, but about 540k after compiling.
Does it include functions (or something else?) from the header/include
files even if they aren't used in the actual program?
Pasted below is the program.
Thanks in advance!
Dave
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
double interpolate(double t, double INDEX[], double TABLE[])
{
int count = 0;
do
{
count = count + 1;
} while (t>INDEX[(count)]);
double i1 = INDEX[(count-1)];
double i2 = INDEX[(count)];
double t1 = TABLE[(count-1)];
double t2 = TABLE[(count)];
double result = ((t-i1)/(i2-i1)*(t2-t1))+t1;
return result;
}
int main(int nNumberofArgs, char* pszArgs[])
{
double TIME[5];
double THRUST[5];
double t=0;
TIME[0]=0;
TIME[1]=.1;
TIME[2]=3;
TIME[3]=3.1;
TIME[4]=999;
THRUST[0]=0;
THRUST[1]=100;
THRUST[2]=100;
THRUST[3]=0;
THRUST[4]=0;
double y=200;
double ymax=y;
double vy=0;
double mass=2;
double CAD=.01;
double dfy;
double fm;
double dt=.01;
double isp=200;
double imp=0;
double g=9.8;
double ay;
double fy;
do
{
if (vy>0)
{
dfy=-(.5*CAD*vy*vy);
}
else
{
dfy=(.5*CAD*vy*vy);
}
fm=interpolate(t,TIME,THRUST);
mass=mass-(fm*dt/isp/g);
imp=imp+(fm*dt);
fy=fm+dfy-(mass*g);
ay=fy/mass;
if (ymax<y)
{
ymax=y;
}
y=y+((vy+ay*dt/2)*dt);
vy=vy+(ay*dt);
t=t+dt;
} while (y>0);
cout << "time is:" << endl;
cout << t << endl;
cout << mass << endl;
cout << imp << endl;
cout << ay << endl;
cout << fm << endl;
cout << dfy << endl;
cout << vy << endl;
cout << y << endl;
cout << fy << endl;
cout << ymax << endl;
system("PAUSE");
return 0;
}
questions regarding what is included in the executable when the source
is compiled... I've written a simple, 1-D rocket predicting program
that's under 2K prior to compiling, but about 540k after compiling.
Does it include functions (or something else?) from the header/include
files even if they aren't used in the actual program?
Pasted below is the program.
Thanks in advance!
Dave
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
double interpolate(double t, double INDEX[], double TABLE[])
{
int count = 0;
do
{
count = count + 1;
} while (t>INDEX[(count)]);
double i1 = INDEX[(count-1)];
double i2 = INDEX[(count)];
double t1 = TABLE[(count-1)];
double t2 = TABLE[(count)];
double result = ((t-i1)/(i2-i1)*(t2-t1))+t1;
return result;
}
int main(int nNumberofArgs, char* pszArgs[])
{
double TIME[5];
double THRUST[5];
double t=0;
TIME[0]=0;
TIME[1]=.1;
TIME[2]=3;
TIME[3]=3.1;
TIME[4]=999;
THRUST[0]=0;
THRUST[1]=100;
THRUST[2]=100;
THRUST[3]=0;
THRUST[4]=0;
double y=200;
double ymax=y;
double vy=0;
double mass=2;
double CAD=.01;
double dfy;
double fm;
double dt=.01;
double isp=200;
double imp=0;
double g=9.8;
double ay;
double fy;
do
{
if (vy>0)
{
dfy=-(.5*CAD*vy*vy);
}
else
{
dfy=(.5*CAD*vy*vy);
}
fm=interpolate(t,TIME,THRUST);
mass=mass-(fm*dt/isp/g);
imp=imp+(fm*dt);
fy=fm+dfy-(mass*g);
ay=fy/mass;
if (ymax<y)
{
ymax=y;
}
y=y+((vy+ay*dt/2)*dt);
vy=vy+(ay*dt);
t=t+dt;
} while (y>0);
cout << "time is:" << endl;
cout << t << endl;
cout << mass << endl;
cout << imp << endl;
cout << ay << endl;
cout << fm << endl;
cout << dfy << endl;
cout << vy << endl;
cout << y << endl;
cout << fy << endl;
cout << ymax << endl;
system("PAUSE");
return 0;
}