Vector problem - square addition
Posted: Sat Jun 19, 2010 1:13 pm
Okay, I've been stuck on this far too long...
What I've come up with is this:
I've looked at this for hours...
What I want to do is what it says in "addsq.hpp", add the file values in an array, but simplify it, using a vector, and not this:
Example:
Any help is much appreciated,
Joshua
What I've come up with is this:
Code: Select all
//addsq.hpp
double a_count, b_count, c_count, d_count, e_count, f_count, g_count, h_count;
int i, ii, iii, iv, v, vi, vii, viii;
int *ti = new int;
int *tii = new int;
int *tiii = new int;
int *tiv = new int;
int *tv = new int;
int *tvi = new int;
int *tvii = new int;
int *tviii = new int;
int a, b, c, d, e, f, g, h, j;
int sq_total = 64;
int sq[64] = {
0, 1, 1, 2, 2, 1, 1, 0,
1, 1, 2, 2, 2, 2, 1, 1,
1, 2, 3, 3, 3, 3, 2, 1,
2, 2, 3, 4, 4, 3, 2, 2,
2, 2, 3, 4, 4, 3, 2, 2,
1, 2, 3, 3, 3, 3, 2, 1,
1, 1, 2, 2, 2, 2, 1, 1,
0, 1, 1, 2, 2, 1, 1, 0
};
/*
add "vertically" every 8 for each file;
a b c d e f g h
i ii iii iv v vi vii viii
8 12 18 22 22 18 12 8
*/
Code: Select all
// addsq.cpp
#include "iostream"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include <cstring>
#include <algorithm>
#include <vector>
#include "addsq.hpp"
using namespace std;
void add_sq(int& i, int& ii, int& iii, int& iv, int& v, int& vi, int &vii, int &viii);
int main()
{
vector<int> myvector (sq, sq+sq_total);
a_count = (int) count (myvector.begin(), myvector.end(), sq[a]);
b_count = (int) count (myvector.begin(), myvector.end(), sq[b]);
c_count = (int) count (myvector.begin(), myvector.end(), sq[c]);
d_count = (int) count (myvector.begin(), myvector.end(), sq[d]);
e_count = (int) count (myvector.begin(), myvector.end(), sq[e]);
f_count = (int) count (myvector.begin(), myvector.end(), sq[f]);
g_count = (int) count (myvector.begin(), myvector.end(), sq[g]);
h_count = (int) count (myvector.begin(), myvector.end(), sq[h]);
a_count = (double) count (sq, sq+sq_total, 0);
b_count = (double) count (sq, sq+sq_total, 0);
c_count = (double) count (sq, sq+sq_total, 0);
d_count = (double) count (sq, sq+sq_total, 0);
e_count = (double) count (sq, sq+sq_total, 0);
f_count = (double) count (sq, sq+sq_total, 0);
g_count = (double) count (sq, sq+sq_total, 0);
h_count = (double) count (sq, sq+sq_total, 0);
void add_sq(int&,int&,int&,int&,int&,int&,int&,int&);
a = 0;
b = 1;
c = 2;
d = 3;
e = 4;
f = 5;
g = 6;
h = 7;
add_sq(a,b,c,d,e,f,g,h);
system("pause");
}
void add_sq(int& i, int& ii, int& iii, int& iv, int& vi, int& vii, int& viii)
{
for(j = 0; j < sq_total;)
{
cout << " a " << sq[i];
cout << " b " << sq[ii];
cout << " c " << sq[iii];
cout << " d " << sq[iv];
cout << " e " << sq[v];
cout << " f " << sq[vi];
cout << " g " << sq[vii];
cout << " h " << sq[viii];
*ti = i;
*tii = ii;
*tiii = iii;
*tiv = iv;
*tv = v;
*tvi = vi;
*tvii = vii;
*tviii = viii;
i = i + 1;
ii = ii + 1;
iii = iii + 1;
iv = iv + 1;
v = v + 1;
vi = vi + 1;
vii = vii + 1;
viii = viii + 1;
cout << " a " << sq[*ti]+sq[i];
cout << " b " << sq[*tii]+sq[ii];
cout << " c " << sq[*tiii]+sq[iii];
cout << " d " << sq[*tiv]+sq[iv];
cout << " e " << sq[*tv]+sq[v];
cout << " f " << sq[*tvi]+sq[vi];
cout << " g " << sq[*tvii]+sq[vii];
cout << " h " << sq[*tviii]+sq[viii] << endl;
j = j + 1;
}
}
What I want to do is what it says in "addsq.hpp", add the file values in an array, but simplify it, using a vector, and not this:
Example:
Code: Select all
a = sq[0]+sq[8]+sq[16]+sq[24]+sq[32]+sq[40]+sq[48]+sq[56];
b...
c...
d = sq[3]+sq[11]+sq[19]+sq[27]+sq[35]+sq[43]+sq[51]+sq[59];
...
h = sq[7]+sq[15]+sq[23]+sq[31]+sq[39]+sq[47]+sq[55]+sq[63];
Joshua