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
|
#include <iostream>
#include <new>
#include <fstream>
#include <cstdio>
#include <string>
#include <istream>
#include <ios>
#include <iomanip>
using namespace std;
class WellSlice{
double x,y,
pressure,
flowrate;
public:
void set_value (double, string);
void print_values ();
};
void WellSlice::set_value (double value, string variable){
if (variable =="x1") {x = value;}
else if (variable =="y1"){y = value;}
else if (variable =="pressure1"){pressure = value;}
else if (variable =="flowrate1"){flowrate = value;}
}
void WellSlice::print_values (){
cout << x << ", " << y << ", " << pressure << ", " << flowrate;
}
void ReadInputData (int *i, WellSlice **Well){
int n;
ifstream InputData ("Input.txt");
double x1, y1, pressure1, flowrate1;
x1 = y1 = pressure1 = flowrate1 = 0;
if (InputData.is_open()){
int* iaux; iaux = (int*)i;
InputData >> *iaux;
*Well = new (nothrow) WellSlice[*i];
for (n=0; n<*i; n++){
InputData >> x1;
InputData >> y1;
InputData >> pressure1;
InputData >> flowrate1;
if (InputData.eof() == true) break;
*Well[n].set_value(x1, "x1");
*Well[n].set_value(y1, "y1");
*Well[n].set_value(pressure1, "pressure1");
*Well[n].set_value(flowrate1, "flowrate1");
}
}
}
int main(){
WellSlice * Well;
int i, n;
ReadInputData (i, &Well);
cout << "\nYou have entered: ";
for (n=0; n<i; n++){
cout << "\nWell slice number " << (n+1) << ":\n";
Well[n].print_values();
}
delete[] Well;
return 0;
}
|