J
Justin
Hi! i'm a beginner user of c++ and i need some help. I use visual c++
6.0 on a p4 under windows 2000.
First, i read a text file with 3 fields: gestionnal age (GA), birth
weight (BW) and repetition (the number fo patient for specific GA and
BW). The file is ordered by GA and BW. I put each field in an vector.
GA took value between 22 and 44 and i want to create 2 others vector
(qcount, qcumulative) containing the number of patients for each GA
and the cumulative number of patients.
/***************************************************************************
ex:
22 100 2
22 125 3
23 150 1
23 165 4
23 170 8
25 180 10
qcount=(5,13,10)
qcumulative=(5,18,28)
****************************************************************************/
here's my code:
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <math.h>
#define pi 3.1415926
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
main()
{
vector<int> vga;
vector<int> vrep;
vector<float> vweight;
/* add space between variables for output */
ostream_iterator <int> sortie( cout, " ");
/*FILE1 should be your data file, consisting only of gestational age,
birthweight and
number of repetition in integer format.
*/
/* output and input files */
ifstream input_file ("growth1sorted.txt", ios::in);
/* Import data */
if (!input_file)
{
cerr << "The file cannot be opened";
exit(1);
}
int temp_ga; int repet;
float temp_wt;
while (input_file >> temp_ga >> temp_wt >> repet)
{
vga.insert(vga.end(), temp_ga);
vweight.insert(vweight.end(), temp_wt);
vrep.insert(vrep.end(), repet);
}
/* close the file */
input_file.close();
....
DO I WORK WITH THE RIGHT CLASS (VECTOR) FOR THIS KIND OF TASK?
thanks
6.0 on a p4 under windows 2000.
First, i read a text file with 3 fields: gestionnal age (GA), birth
weight (BW) and repetition (the number fo patient for specific GA and
BW). The file is ordered by GA and BW. I put each field in an vector.
GA took value between 22 and 44 and i want to create 2 others vector
(qcount, qcumulative) containing the number of patients for each GA
and the cumulative number of patients.
/***************************************************************************
ex:
22 100 2
22 125 3
23 150 1
23 165 4
23 170 8
25 180 10
qcount=(5,13,10)
qcumulative=(5,18,28)
****************************************************************************/
here's my code:
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <math.h>
#define pi 3.1415926
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
using namespace std;
main()
{
vector<int> vga;
vector<int> vrep;
vector<float> vweight;
/* add space between variables for output */
ostream_iterator <int> sortie( cout, " ");
/*FILE1 should be your data file, consisting only of gestational age,
birthweight and
number of repetition in integer format.
*/
/* output and input files */
ifstream input_file ("growth1sorted.txt", ios::in);
/* Import data */
if (!input_file)
{
cerr << "The file cannot be opened";
exit(1);
}
int temp_ga; int repet;
float temp_wt;
while (input_file >> temp_ga >> temp_wt >> repet)
{
vga.insert(vga.end(), temp_ga);
vweight.insert(vweight.end(), temp_wt);
vrep.insert(vrep.end(), repet);
}
/* close the file */
input_file.close();
....
DO I WORK WITH THE RIGHT CLASS (VECTOR) FOR THIS KIND OF TASK?
thanks