1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
// Program TwoDim manipulates a two-dimensional array variable.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int ROW_MAX = 8;
const int COL_MAX = 10;
typedef int ItemType;
typedef ItemType Table[ROW_MAX][COL_MAX];
void getData(ifstream&, Table, int&, int&); // Reads values and stores them in the table.
void printTable(ofstream&, const Table, int, int); // Write values in the table to a file.
int main()
{
Table table;
int rowsUsed;
int colsUsed;
ifstream dataIn;
ofstream dataOut;
int index = 0;
dataIn.open("twod.txt");
dataOut.open("twod.out");
string line;
getData(dataIn, table, rowsUsed, colsUsed);
printTable(dataOut, table, rowsUsed, colsUsed);
const int MAX = 80; //array size
int numbers[MAX]; //array numbers with 80 limit
if (dataIn.is_open())
{
ifstream data;
//ItemType item;
data >> rowsUsed >> colsUsed;
for (int row = 0; row < rowsUsed; row++)
{
for (int col = 0; col < colsUsed; col++)
{
while (dataIn >> numbers[col])
{
while (!dataIn.eof())
{
getline(dataIn, line);
numbers[MAX] << line;
}
}
// FILL IN Code to read the next value from input file and store it in array table.
}
}
}
//****************************************************
void printTable(ofstream& data, const Table table, int rowsUsed, int colsUsed);
// Pre: table contains valid data.
// Post: Values in array table have been sent to a file by row,
// one row per line.
{
cout << table;
}
return 0;
}
| |