I need to have the same following format of dadat, which are read in a text fil, in output.
"Mainnumber" is the first number of each matrix (1,2,3) and for each "mainnumber" (i), the number of rows are determined for each (i) by ("nof_row_per_mainnumber[i]"= numberof_rows;).
For every "Mainnumber" (matrix) it starts from the first row ("first_rows[i]"= k;).
The problem is that it says "numberof_rows" should be initialized.
1
2 3
2
4 5
6 7
3
8 9
3 5
2 6
class Classname {
int mainnumber;
int nof_row_per_mainnumber[3];
int numberof_rows;
int first_rows[3];
double first_array[6];
double second_array[6];
int total_rows;
public:
void Read(char *fname);
void Writedata();
}
void Classname::Read(char *fname)
{ int i, j;
ifstream fin(fname);
fin >> 3;
int numberof_rows;
int k= 0;
for(i= 0; i<mainnumber; i++) {
fin >> numberof_rows;
no_row_per_mainnumber[i]= numberof_rows;
first_rows[i]= k;
for(j= 0; j<numberof_rows; j++) { // read each row
fin >> first_array[k];
fin >> second_array[k];
k++;
}
}
total_rows= k;
}
void Classname::Writedata()
{ // writes model to cout in same format it was read in
int numberof_rows;
int k= 0;
for(i= 0; i<mainnumber; i++) {
cout << i+1 << endl;
no_row_per_mainnumber[i]= numberof_rows;
first_rows[i]= k;
for(j= 0; j<numberof_rows; j++) { // write each line
cout << first_array[k] << " " << second_array[k] << " ";
cout << endl;
k++;
}
}
total_rows= k;
}