Transfer results from different classes into one class by reference?

I have:
- 1 class to read a data series (series.h and series.cpp)
- 1 class for a function (function.h and function.cpp)
I'm trying to create another class which has input from 2 above class (as constant references) and produce output which has the same length as data series. Therefore, I create an object based on series class to store the result. But the program keep saying that the syntax wasn't correct despite I tried all methods I knew
Plz help me. Any suggestion would be appreciated.
This is my solution so far

* Main
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
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

#include "function.h"
#include "series.h"
#include "integral.h"

// Main program
int main ()
{
    function function1;
    series in1;             // input data
    series out1;            // used to store result
    integral integral1;     // used input from series and function to generate output

    // read input data
    in1.read_data(string("data_test.txt"));
    in1.print_data();

    // test if function is correct
    function1.give_value( 5000.0 );

    // do integral from series and function to generate output
    integral1.do_integral( in1, function, &out1 );

    return 0;
}



* Integral class
- header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Declaration  the integral class
// Member functions are defined in integral.cpp
// used input from series and function to generate output

// prevent multiple inclusion of header file
#ifndef INTEGRAL
#define INTEGRAL

class integral
{
    private:
        double* result;

    public:
        integral();
        void do_integral( const series &input, const function &func, double* result )
};

#endif 


- integral.cpp
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
// used input from series and function to generate output

#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

#include "integral.h"

integral::integral()
{
    result = NULL;
}

// Function for calculating convoluted integral
void integral::do_integral( const series &input, const function &func, double* result )
{
    const series &input;
    const function &func;
    series* result;

    // Loop for calculating integral
    for ( int i = 1; i < series.length; ++i )   // take length value from class series
    {
        for (int j = 0; j <= i; ++j )
        {
            result += series.data[i-j] * function.give_value[(3600*j)];
        }
    }
}


* Series class:
- header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#ifndef SERIES
#define SERIES

class series
{
    private:
        int length;                         // number of points
        double* data;
        struct Time_read                    // structure used to store time (format: xx/yy/zz)
        {
            unsigned int year, month, day;
        };
        vector<Time_read> time_vector;      // vector to store date

    public:
        series();
        bool read_data(const string &filename);
        void print_data();
};

#endif 


- series.cpp
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
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

#include "series.h"

// constructor initializes each data member to zero
series::series()
{
    length = 0;
    data = NULL;
}

// Read data from file
bool series::read_data(const string &filename)
{
    ifstream inputdata(filename.c_str());

    // check if file couldn't be opened
    if ( !inputdata )
    {
        cerr << "Error: file could not be opened" << endl;
        return false;
    }

    string dummy_string;    // temporary string used to read words
    float temp;

    // read and set length value
    inputdata >> dummy_string >> dummy_string >> dummy_string >> temp;
    length = temp;
    cout << "Length= " << length << endl;

    // read through "DATA" and "DATA" letters
    inputdata >> dummy_string >> dummy_string;

    data = new double [ length ];                   // allocate space for an array
    // Read date (xx/yy/zz)
    Time_read time_input;
    for (int i = 0; i < length; ++i)
    {
        inputdata >> setw(2) >> time_input.day;    // read 2 char and store them in time_input.day
        inputdata.ignore(1);                        // ignore 1 char. in this case "/" char
        inputdata >> setw(2) >> time_input.month;   // read 2 char and store in time_input.month
        inputdata.ignore(1);                        // ignore 1 char
        inputdata >> setw(2) >> time_input.year;     // read 2 char and store in time_input.year

        // store the reading result in time_vector
        time_vector.push_back(time_input);

        // read data
        inputdata >> data[i];
    }
    return true;
}

void series::print_data()
{
    cout << "--------------------------------" << endl;
    for (int i = 0; i < length; ++i)
    {
        cout << time_vector[i].day << "/" << time_vector[i].month << "/" << time_vector[i].year << " ";
        cout << setw(10) << data[i];
        cout << endl;   // new line at the end of each row
    }
    cout << "--------------------------------" << endl;
}


* function class
- header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// prevent multiple inclusion of header file
#ifndef FUNCTION
#define FUNCTION

class function
{
    private:
        double trans;

    public:
        function();
        double give_value( const double &time );
};

#endif 


- function.cpp
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
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

#include "function.h"

// constructor initializes each data member to zero
function::function()
{
    trans = 0.0;
}

// Calculate function
double function::give_value( const double &time )
{
    const double   PI = 3.14159;
    double trans = 0.0;
    double diffuse = 0.0;
    double c = 2.0;
    double D = 10.0;
    double dx = 10000.0;

    trans = dx / ( 2.0 * sqrt( PI * D * pow(time, 3)));
    diffuse = dx - c * time;
    diffuse = exp ( - pow (diffuse, 2) / ( 4.0 * D * time ));
    trans *= diffuse;
    cout << setw(3) << time << setw(18) << trans << endl;
    return trans;
}


- sample data series
Number of points 18
DATE DATA
11/11/02 6.903
11/11/02 6.903
11/11/02 6.930
11/11/02 6.903
11/11/02 6.930
11/11/02 6.957
11/11/02 6.984
11/11/02 6.984
11/11/02 6.957
11/11/02 6.957
11/11/02 6.984
11/11/02 6.984
12/11/02 7.012
12/11/02 7.067
12/11/02 7.122
12/11/02 7.150
12/11/02 7.205
12/11/02 7.261

thank you!
But the program keep saying that the syntax wasn't correct


Tell us exactly what error(s) you're getting and what line(s) they're on.
Thanks for your reply

These are the errors:

integral.h|16|error: ISO C++ forbids declaration of 'series' with no type|
integral.h|16|error: expected ',' or '...' before '&' token|
integral.h|17|error: expected ';' before '}' token|
integral.h|17|error: expected ';' before '}' token|
integral.cpp|21|error: ISO C++ forbids declaration of 'series' with no type|
integral.cpp|21|error: expected ',' or '...' before '&' token|
integral.cpp|21|error: no 'void integral::do_integral(int)' member function declared in class 'integral'|

madtraveller
Topic archived. No new replies allowed.