### Average/ Problem with variable accessing

Hello! I need to find an average but...

Here We have some data:

76.709999, 76.879997, 75.629997, 75.779999, 75.779999
76.900002, 77.639999, 76, 76.239998, 76.239998
76.849998, 78.019997, 74.209999, 78, 78
78, 78.160004, 75.75, 75.910004, 75.910004
76.110001, 76.139999, 73.75, 74.989998, 74.989998
75.190002, 75.580002, 73.860001, 75.400002, 75.400002
75.089996, 76.349998, 75.010002, 75.629997, 75.629997
75.709999, 75.980003, 75.209999, 75.610001, 75.610001
75.68, 75.699997, 74.25,74.470001, 74.470001
74.050003, 74.830002, 73.449997, 74.440002, 74.440002
74.849998, 75.339996, 74.5, 75.190002, 75.190002

Each line contains 5 numbers.
I had to create a container for storing each line

<
class Data {
private:
double a[6];
public:
// default constructor
Data() {
for (int i = 0; i < 5; i++) {
a[i] = 0; }
}

// constructor
Data( double b[5]) {

for (int i = 0; i < 5; i++) {
a[i] = b[i];
}
}
};
>

So Each line is an object.

I will have to deal with more data like this so to segregate this I created another container:

<
// Container for holding lines
class Container {
private:
vector<Data> v1;
public:
// push object into a vector
v1.push_back(d);
}
>

My job is to count an 3 days circular moving average for one before last column and add this information to Data container
So if we have: 75.779999
76.239998
78 --> Here I should start adding average: ~76.63
75.910004 --> ~76.71
74.989998 --> ~76.26

My problem is that I don't know how to access that one before last number from Container "point of view". For example I have Container x with 20 objects inside. Those Objects are my lines where that variable is hiding.

Thank you for any help! :)
Last edited on
 how to access that one before last number from Container "point of view".

The "one before last number" is inside the array `double a[6]` in class `Data`. If you wanted to get fancy, you could add a member function to `Data` to return the element `a[3]` - assuming there are five values contained in positions 0 to 4 inclusive.

From the `Container` point of view, each element of the array `v1` has its own individual value, so there will be more than one "one before last number".

Just a thought, rather than writing customised classes, you might simply use a vector or two:
 `` `` `` vector> container;``

Topic archived. No new replies allowed.