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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstring>
#include "Point2D.h"
#include "Point3D.h"
#include "Line2D.h"
#include "Line3D.h"
#include <vector>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
using namespace std;
vector<Point2D>p2dList;
vector<Point3D>p3dList;
vector<Line2D>line2dList;
vector<Line3D>line3dList;
//void readData();
void readP2DData (string);
void readP3DData (string);
void readL2DData (string);
void readL3DData (string);
int main()
{
ifstream ifile;
ifile.open("data2.txt",ios::in);
string data;
int totalRecords=0;
while(getline(ifile,data))
{
istringstream iss (data);
string dType;
getline(iss, dType, '|');
string dVal;
cout<<dType<<": ";
if(dType=="Point2D")
readP2DData(data);
else if(dType=="Point3D")
readP3DData(data);
else if(dType=="Line2D")
readL2DData(data);
else if(dType=="Line3D")
readL3DData(data);
cout<<endl;
totalRecords++;
}
cout<<"Total records = "<<totalRecords<<endl;
ifile.close();
}
void readL2DData (string data)
{
istringstream iss(data);
string dType, dVal1, dX1, dY1, dVal2, dX2, dY2;
getline(iss, dType, '|');
getline(iss, dVal1, '[');
getline(iss, dX1, ',');
getline(iss, dY1, ']');
getline(iss, dVal2, '[');
getline(iss, dX2, ',');
getline(iss, dY2, ']');
cout<<"("<<dX1<<", "<<dY1<<"), ("<<dX2<<", "<<dY2<<")";
int x1 = stoi (dX1);
int y1 = stoi (dY1);
int x2 = stoi (dX2);
int y2 = stoi (dY2);
Point2D p2d1 (x1, y1) ;
Point2D p2d2 (x2, y2);
Line2D l2d (p2d1, p2d2);
// cout<<l2d;
}
void readL3DData (string data)
{
istringstream iss(data);
string dType, dVal1, dX1, dY1, dZ1, dVal2, dX2, dY2, dZ2;
getline(iss, dType, '|');
getline(iss, dVal1, '[');
getline(iss, dX1, ',');
getline(iss, dY1, ',');
getline(iss, dZ1, ']');
getline(iss, dVal2, '[');
getline(iss, dX2, ',');
getline(iss, dY2, ',');
getline(iss, dZ2, ']');
int x1 = stoi (dX1);
int y1 = stoi (dY1);
int z1 = stoi (dZ1);
int x2 = stoi (dX1);
int y2 = stoi (dY1);
int z2 = stoi (dZ1);
Point3D p3d1 (x1, y1, z1);
Point3D p3d2 (x2, y2, z2);
Line3D l3d (p3d1, p3d2);
}
|