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
|
#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,
rate;
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 =="rate1"){rate = value;}
}
void WellSlice::print_values (){
cout << x << ", " << y << ", " << pressure << ", " << rate;
}
int main(){
WellSlice * Well;
int i, n;
double x1, y1;
double pressure1;
//double flow1;
double rate1;
ifstream InputInfo ("InputInfo.txt");
char * TXTName;
x1 = 0; y1 = 0;
//flow1 = 0;
pressure1 = 0;
rate1 = 0;
if (InputInfo.is_open()){
while (!InputInfo.eof()){
InputInfo >> TXTName;
InputInfo >> i;
}
}
ifstream InputData (TXTName);
Well = new (nothrow) WellSlice[i];
if(Well == NULL){
cout << "\nError allocating memory\n";
return 0;
}
if (InputData.is_open()){
for (n=0; n<i; n++){
InputData >> x1;
InputData >> y1;
InputData >> pressure1;
InputData >> rate1;
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(rate1, "rate1");
}
}
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;
}
|