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
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
usingnamespace 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
// used input from series and function to generate output
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
usingnamespace 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)];
}
}
}
#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)
{
unsignedint year, month, day;
};
vector<Time_read> time_vector; // vector to store date
public:
series();
bool read_data(const string &filename);
void print_data();
};
#endif
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>
usingnamespace 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;
returnfalse;
}
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 = newdouble [ 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];
}
returntrue;
}
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( constdouble &time );
};
#endif
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'|