Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

data manipulation

Status
Not open for further replies.

daula

Programmer
May 29, 2006
38
US
hello there;
I need to re-arrange data for a report.
Currently I've read the data into a vector and data is grouped by date and dollar_range. Each line stores a type and it's count:

Code:
gender_1, count
gender_2, count
gender_n, count
dollar_range_1, count
.
.
gender_1, count
gendeer_n, count
dollar_range_n, count
.
.
date_1, count
.
.
date_2, count

I'm hoping to be able to extract and re-arrange like:
date_1, count, dollar_range_1, count, gender_1, count
date_1, count, dollar_range_1, count, gender_2, count
date_1, count, dollar_range_1, count, gender_n, count
date_1, count, dollar_range_2, count, gender_1, count
date_2, count, dollar_range_1, count, gender_1, count
date_2, count, dollar_range_1, count, gender_1, count
...
date_n, count, dollar_range_n, count, gender_n, count

I have created created three vectors:
v4 = stores entire content of file.
v3 = keep the indexes to dates ( i.e the location of the date in v1)
v2 = store the number of dollar_ranges per date.
v1 = store the number of gender per dollar_range.

As you can see on my code bellow my logic is all messed up.
please, I need help.

Code:
/*
**C++
*/

struct fields
{
    string value;
    int count;
} temp_data;


struct holder_2
{
   fields date;
   fields dollar_range;
   fields gender;
} data;


void make_final ( vector<int> &v1, vector<int> &v2, vector<int> &v3, vector<struct fields> &v4 )
{
   //vector<struct holder_2> final_copy;

   vector<int>::iterator num  = v1.begin();
   vector<int>::iterator num2 = v2.begin();
   vector<int>::iterator num3 = v3.begin();

   vector<struct fields>::iterator start = v4.begin();
   vector<struct fields>::iterator end   = v4.end();

    //for(; num  != v1.end(); num++)  cout<<*num<<endl;
    //for(; num2 != v2.end(); num2++) cout<<*num2<<endl;
    //for(; num3 != v3.end(); num3++) cout<<*num3<<endl;
    //for(; itr  != v4.end(); itr++)  cout<<(*itr).sValue<<","<<(*itr).sCount<<endl;

    int j =0, k =0;
    int dat=*num3;
    int dol=*num;

    for ( int i=0; i < v4.size(); i++ )
    {
        int c =0;
        for (; j <= dat; j++) 
        {
             
             for(; k <= dol; k++)
             {
                 //  data.city.value = v4[dat].value;
                 //  data.city.count = v4[dat].count;
                 //  data.date_range.value = v4[dol].value;
                 //  data.date_range.count = v4[dol].count;
                 //  data.gender.value = v4[k].value;
                 //  data.gender.count = v4[k].count;
                 //  final_copy.push_back(data);

                 cout << v4[dat].value <<","<< v4[dat].count <<",";
                 cout << v4[dol].value <<","<< v4[dol].count  <<",";
                 cout << v4[k].value  <<","<< v4[k].count <<endl;
             }
             if ( v1.begin() != v1.end() ) v1.erase(v1.begin());
             num=v1.begin();
             dol=k+*num;
             c++;
        }
        if(v3.begin() != v3.end()) v3.erase( v3.begin() );
        num3=v3.begin();
        dat = j + *num3;
    }
}
Code:
** v4 sample**
U,4
M,57
I,5
F,220
C,1
A,18
000-005,305
U,18
M,82
I,14
F,330
C,1
A,33
005-010,478
U,20
M,109
I,25
F,490
C,6
B,1
A,56
010-015,707
U,8
M,34
I,3
F,160
C,1
A,13
015-020,219
U,30
M,131
I,17
F,683
C,6
A,74
020-025,941
U,12
M,84
I,5
F,251
C,4
B,1
A,20
7,1
025-050,378
U,2
M,18
I,1
F,59
A,9
050-075,89
F,5
075-100,5
200602,3122
U,6
M,37
I,4
F,89
C,1
B,1
A,8
000-005,146
U,7
M,68
I,7
F,182
C,2
B,1
A,17
005-010,284
U,7
M,94
I,6
F,316
C,1
B,1
A,24
010-015,449
U,5
M,38
I,4
F,145
A,13
015-020,205
U,9
M,92
I,14
F,394
C,5
A,33
7,1
020-025,548
U,17
M,164
I,14
F,470
C,4
B,1
A,52
7,1
025-050,723
U,12
M,90
I,6
F,229
C,1
B,1
A,18
7,1
050-075,358
U,1
M,7
I,2
F,11
A,5
075-100,26
200601,2739
U,4
.
.
200403,2347
 
Wow, that's quite a mess! :)
Maybe it would be easier if you post a few lines of what the file looks like, then post how those lines should look after you rearrange them. That just seems like an awful lot of vectors just for rearranging some data...
 
Thanks cpjust.
and yes, it's a big mess.
well, the input looks like the sample in my previous post (v4 sample).
the following is a sample output:
Code:
200602,3122,000-005,305,U,4
200602,3122,000-005,305,M,57
200602,3122,000-005,305,I,5
200602,3122,000-005,305,F,220
200602,3122,000-005,305,C,1
200602,3122,000-005,305,A,18
200602,3122,005-010,478,U,18
200602,3122,005-010,478,M,82
200602,3122,005-010,478,I,14
200602,3122,005-010,478,F,330
200602,3122,005-010,478,C,1
200602,3122,005-010,478,A,33
200602,3122,010-015,707,U,20
200602,3122,010-015,707,M,109
200602,3122,010-015,707,I,25
200602,3122,010-015,707,F,490
200602,3122,010-015,707,C,6
200602,3122,010-015,707,B,1
200602,3122,010-015,707,A,56
200602,3122,015-020,219,U,8
200602,3122,015-020,219,M,34
200602,3122,015-020,219,I,3
200602,3122,015-020,219,F,160
200602,3122,015-020,219,C,1
200602,3122,015-020,219,A,13
200602,3122,020-025,941,U,30
200602,3122,020-025,941,M,131
200602,3122,020-025,941,I,17
200602,3122,020-025,941,F,683
200602,3122,020-025,941,C,6
200602,3122,020-025,941,A,74
.
.
.
200602,3122,075-100,26,U,1
200602,3122,075-100,26,M,7
200602,3122,075-100,26,I,2
200602,3122,075-100,26,F,11
200602,3122,075-100,26,A,5
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top