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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstdlib>
using namespace std;
const int MAX_SIZE = 200;
typedef long double T; // data type for project
int readFile(T x[], T y[], T m[], istream & iStream = cin);
void writeFile(T x[], T y[], T m[], int numDataPoints, ostream & oStream = cout);
//*************************************************************************
//*************************************************************************
//include proj4.h
//include readFile.h
//include writeFile.h
int main(){
int a, size;
T x[MAX_SIZE]; // x-coordinate of data point
T y[MAX_SIZE]; // y-coordinate of data point
T z[MAX_SIZE]; // mass at data point
int numDataPoints;
ifstream fin; // declare ifstream object
fin.open("P4Data.txt"); // attach file P4Data.txt
if (fin.fail()){ // check it out
cout << "\n\aBummer! File P4Data.txt"; // report bad news
cout << " could not be opened. Goodbye.\n\n";
exit(-1); // outta here
}
ofstream fout; // declare ofstream object
fout.open("P4Out.txt"); // attach it to disk file
readFile(x, y, z, cin);
cout << readFile(x, y, z, cin) << "\n\n";
writeFile(x, y, z, numDataPoints, cout);
// fout << writeFile(x, y, z, numDataPoints, cout);
fin.close(); // close up files when done
fout.close();
system("Pause");
return EXIT_SUCCESS;
}
//*************************************************************************
//*************************************************************************
int readFile(T x[], T y[], T m[], istream & iStream){
int numDataPoints; // temp value
iStream >> numDataPoints;
if (numDataPoints > MAX_SIZE){ // ensure not too big
cout << "\n\n\aTruncating data ";
cout << "due to size constraints.\n\n";
numDataPoints = MAX_SIZE; // truncate if needed
}
for (int i = 0; i < numDataPoints; ++i) { // read data groups
iStream >> x[i];
iStream >> y[i];
iStream >> m[i];
}
return numDataPoints;
}
//*************************************************************************
//*************************************************************************
void writeFile(T x[], T y[], T m[], int numDataPoints, ostream & oStream){
// oStream << numDataPoints;
if (numDataPoints > MAX_SIZE){ // ensure not too big
cout << "\n\n\aTruncating data ";
cout << "due to size constraints.\n\n";
numDataPoints = MAX_SIZE; // truncate if needed
}
for (int i = 0; i < numDataPoints; ++i) { // read data groups
oStream << i;
oStream << x[i];
oStream << y[i];
oStream << m[i];
}
}
|