store calculated values in a vector

hey guys i want to knw hw can i store my calculated values of sum,hdistance and vdistance in a new vector so ican manipulate dem.....thnx in advance

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream>
#include <vector>
#include<fstream>
#include<cmath>
#include<iomanip>

using namespace std;
void getValuesFromFile(vector<double>&VO,vector<double>&Theta,vector<double>&DT)
{
    double vo=0;
    double theta=0;
    double dt=0;

    ifstream infile("indata.txt");

    while (infile>>vo>>theta>>dt)
    {
        VO.push_back(vo);
        Theta.push_back(theta);
        DT.push_back(dt);


    }

}

void calculate(vector<double>VO,vector<double>Theta,vector<double>DT)
{
    double pie;
    pie=4*atan(1);
    double radians;
    radians=(Theta[0]*pie)/180;

    double hdistance=0.0;
    double vdistance=0.0;
    double sum=0;




    while(hdistance>=0)
    {


        hdistance=(VO[0]*sum*sin(radians))-(4.905*(sum*sum));
        vdistance=VO[0]*sum*cos(radians);




        cout<<fixed<<setprecision(3)<<sum<<"   "<<hdistance<<"   "<<vdistance<<endl;





        sum=sum+DT[0];


    }


}

void all(vector<double>SUM,vector<double>HDISTANCE,vector<double>VDISTANCE)
{
    double sum=0.0;
    double hdistance=0.0;
    double vdistance=0.0;
    SUM.push_back(sum);
    HDISTANCE.push_back(hdistance);
    VDISTANCE.push_back(vdistance);


} 
 




int main()
{
    vector<double> VO;
    vector<double> Theta;
    vector<double> DT;
    vector<double> SUM;
    vector<double> HDISTANCE;
    vector<double> VDISTANCE;

    getValuesFromFile(VO,Theta,DT);
    calculate(VO,Theta,DT);
    all(SUM,HDISTANCE,VDISTANCE);
    return 0;

}
create a small class or structure to hold your sum, hdistance and vdistance, and then have a vector containing type of your structure.
Do it the same way you got the data from the file.

1
2
void calculate(vector<double>VO,vector<double>Theta,vector<double>DT, 
                      vector<double>& SUM, vector<double>& HDISTANCE, vector<double>& VDISTANCE)


then you can populate them in your loop.
1
2
3
4
5
6
7
8
9
10
    while(hdistance>=0)
    {
        hdistance=(VO[0]*sum*sin(radians))-(4.905*(sum*sum));
        vdistance=VO[0]*sum*cos(radians);
        sum=sum+DT[0];

        HDISTANCE.push_back(hdistance);
        VDISTANCE.push_back(vdistance);
        SUM.push_back(sum);
    }



Topic archived. No new replies allowed.