i want to get code for a program in visual c++ where :
1]take the name of directory say DIR
2]get a file ,say IN from that directory which has 3 column (say X, Y and Z) and many rows( display this if asked to !!)..[Also get all the files ifwhich we ask for ]
3]want an output file,say OUT, where X and Y are interchanged i.e above 'X' values in'Y' and 'Y' values in 'X'..but 'Z' remain same( and display if asked to!!)
4]get average of values(sum of numbers/number of items) in column Z and disply
5]get the total number of cells in Z more than and less than a given number 'n'
i want evrything to be displayed as a nx3 matrix
thats all.
thank you..
[input fille is table]
The CODE i have written is this:
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
const int maxrows = 40;//[ can i make it more..i mean vary with different files taken as input?? like dynamic memmory]
const int maxcols = 3;
void getdata(int table[][maxcols]);
void columnavg(const int table[][maxcols], float colavg[]);
void colsort(const int table[][maxcols], int sort[]);
void printarray(const int table[][maxcols], const float colavg[],
const int sort[]);
int main(void)
{
int table[maxrows][maxcols];
float colavg[maxrows] = {0};
int sort[maxrows] = {0};
getdata (table);
columnavg (table, colavg);
colsort (table, sort);
printarray (table, colavg, sort);
return 0;
}
/* ============================getdata=============== =========*/
void getdata(int table[][maxcols])
{
int row;
int col;
ifstream input;
input.open("scores.dat");
if(!input)
{
cerr << "Error opening file scores.dat\n";
exit (100);
}
for (row = 0; row < maxrows; row++)
for (col = 0; col < maxcols; col++)
{
input >> table[row][col];
}
return;
}
/* ==========================columnavg=============== =========*/
void columnavg(const int table[][maxcols], float colavg[])
{
int row;
int col;
for (col = 1; col < maxcols; col++)
{
for (row = 0; row < maxrows; row++)
colavg[col] += table[row][col];
colavg[col] /= maxrows;
}
return;
}
/* ============================colsort=============== ==========*/
void colsort(const int table[][maxcols], int sort[])
{
int row;
int col;
int walker;
int temp;
int min;
int max;
/* NEED HELP HERE, I need to find the max and min numbers in the last i.e 3rd column, the number of values that comes more than and less than number 1981 and how many are there such..
*/
return;
}
/* ===========================printarray============= ==========*/
void printarray(const int table[][maxcols], const float colavg[])
{
int row;
int col;
for (row = 0; row < maxrows; row++)
{
for (col = 0; col < maxcols; col++)
cout << setw(7) << table[row][col];
cout << endl;
}
for (col = 1; col < maxcols; col++)
cout << setw(7) << colavg[col];
return;