Advertisement
Guest User

newPaste

a guest
Jun 27th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.96 KB | None | 0 0
  1. #include "Header.h"
  2.  
  3. class CDetector
  4. {
  5. long long numero;
  6. std::string palabra;
  7. bool request;
  8. double doub;
  9.  
  10. std::string type;
  11. public:
  12. CDetector(std::string word)
  13. {
  14. type = detectar(word);
  15. if (type == "string")
  16. {
  17. palabra = word, numero = NULL, request = NULL, doub = NULL;
  18. }
  19. else if (type == "bool")
  20. {
  21. palabra = " ", numero = NULL, doub = NULL;
  22. if (word == "SI")
  23. request = true;
  24. else
  25. request = false;
  26. }
  27. else if (type == "long")
  28. {
  29. palabra = " ", doub = NULL, request = NULL;
  30. numero = std::stoll(word);
  31. }
  32. else if (type == "double")
  33. {
  34. palabra = " ", numero = NULL, request = NULL;
  35. doub = std::stod(word);
  36. }
  37. else if (type == "Desconocido")
  38. {
  39. palabra = " ", numero = NULL, doub = NULL, request = NULL;
  40. }
  41. else
  42. {
  43. palabra = "ERROR :(", numero = NULL, request = NULL, doub = NULL;
  44. }
  45. }
  46.  
  47. ~CDetector() {}
  48.  
  49. std::string getType()
  50. {
  51. return this->type;
  52. }
  53.  
  54. std::string detectar(std::string word)
  55. {
  56. if ((word[0] >= 65 && word[0] <= 122) && (word != "SI" && word != "NO"))
  57. return "string";
  58. else if (word == "SI" || word == "NO")
  59. return "bool";
  60. else if (word[0] >= 48 && word[0] <= 57)
  61. {
  62. if ((double)std::stoll(word) != std::stod(word))
  63. return "double";
  64. else if ((double)std::stoll(word) == std::stod(word))
  65. return "long";
  66. }
  67. else return "Desconocido";
  68. }
  69. };
  70.  
  71. class CColumna abstract
  72. {
  73.  
  74. public:
  75. CColumna() {}
  76. ~CColumna() {}
  77. virtual void mostrar() {}
  78.  
  79. };
  80.  
  81. class CColumnaString : public CColumna
  82. {
  83. CVector<std::string>* vec;
  84. public:
  85. CColumnaString() : CColumna()
  86. {
  87. vec = new CVector<std::string>();
  88. }
  89.  
  90. ~CColumnaString()
  91. {
  92. delete vec;
  93. }
  94.  
  95. void agregar(std::string elem)
  96. {
  97. vec->addToTree(elem);
  98. }
  99.  
  100. void mostrar(long long i)
  101. {
  102. std::cout << vec->getSafer()->at(i) << ',';
  103. }
  104.  
  105. CVector<std::string>* getVec() {
  106. return this->vec;
  107. }
  108. };
  109.  
  110. class CColumnaDouble : public CColumna
  111. {
  112. CVector<double>* vec;
  113. public:
  114. CColumnaDouble() : CColumna()
  115. {
  116. vec = new CVector<double>();
  117. }
  118.  
  119. ~CColumnaDouble()
  120. {
  121. delete vec;
  122. }
  123.  
  124. void agregar(double elem)
  125. {
  126. vec->addToTree(elem);
  127. }
  128.  
  129. void mostrar(long long i)
  130. {
  131. std::cout << vec->getSafer()->at(i) << ',';
  132. }
  133.  
  134. CVector<double>* getVec() {
  135. return this->vec;
  136. }
  137. };
  138.  
  139. class CColumnaBool : public CColumna
  140. {
  141. CVector<bool>* vec;
  142. public:
  143. CColumnaBool() : CColumna()
  144. {
  145. vec = new CVector<bool>();
  146. }
  147.  
  148. ~CColumnaBool()
  149. {
  150. delete vec;
  151. }
  152.  
  153. void agregar(bool elem)
  154. {
  155. vec->addToTree(elem);
  156. }
  157.  
  158. void mostrar(long long i)
  159. {
  160.  
  161. std::cout << vec->getSafer()->at(i) << ',';
  162. }
  163.  
  164. CVector<bool>* getVec() {
  165. return this->vec;
  166. }
  167. };
  168.  
  169. class CColumnaLong : public CColumna
  170. {
  171. CVector<long long>* vecx;
  172. public:
  173. CColumnaLong() : CColumna()
  174. {
  175. vecx = new CVector<long long>();
  176. }
  177.  
  178. ~CColumnaLong()
  179. {
  180. delete vecx;
  181. }
  182.  
  183. void agregar(long long elem)
  184. {
  185. vecx->addToTree(elem);
  186. }
  187.  
  188. void mostrar(long long i)
  189. {
  190. std::cout << vecx->getSafer()->at(i) << ',';
  191. }
  192.  
  193. CVector<long long>* getVec() {
  194. return this->vecx;
  195. }
  196. };
  197.  
  198. class CFila
  199. {
  200. private:
  201. std::vector<long long>* vecID;
  202. public:
  203. CFila()
  204. {
  205. vecID = new std::vector<long long>();
  206. }
  207. ~CFila() {
  208. delete vecID;
  209. }
  210.  
  211. void ordenarColumnas(long long i, std::vector<CColumnaLong*>*& vecLong, std::vector<CColumnaString*>*& vecString, std::vector<CColumnaDouble*>*& vecDouble, std::vector<CColumnaBool*>*& vecBool)
  212. {
  213. vecString->at(0)->getVec()->safe();
  214. }
  215.  
  216. std::vector<long long>* getVectorLong()
  217. {
  218. return this->vecID;
  219. }
  220.  
  221. };
  222.  
  223. class CArchivo
  224. {
  225. private:
  226. CDetector* det;
  227. long long contLon;
  228. long long contString;
  229. long long contDouble;
  230. long long contBool;
  231. bool filaInicial;
  232.  
  233. public:
  234. CArchivo()
  235. {
  236. filaInicial = true;
  237. contDouble = 0;
  238. contBool = 0;
  239. contLon = 0;
  240. contString = 0;
  241. }
  242. ~CArchivo() { delete det; }
  243.  
  244. void escribirArchivo()
  245. {
  246. std::ofstream archivoJoc("ArchivoJoc.txt", std::ios::out);
  247. if (!archivoJoc.is_open())
  248. {
  249. std::cout << "El archivo no se ha podido abrir, verifique el nombre del archivo." << std::endl;
  250. exit(1);
  251. }
  252. std::string linea;
  253. std::cout << "Ingrese lo que desea ingresar en el archivo: "; std::getline(std::cin, linea);
  254. archivoJoc << linea;
  255. archivoJoc.close();
  256. }
  257.  
  258. void leerArchivo(std::vector<CColumnaLong*>*& vecLong, std::vector<CColumnaString*>*& vecString, std::vector<CColumnaDouble*>*& vecDouble, std::vector<CColumnaBool*>*& vecBool, std::vector<long long>*& vec, long long& numFilas)
  259. {
  260. std::string nombreArchivo;
  261. std::cout << "Ingrese el nombre del archivo que desea abrir";
  262. std::cin >> nombreArchivo;
  263. std::ifstream archivoJoc(nombreArchivo.c_str(), std::ios::in);
  264. if (!archivoJoc.is_open())
  265. {
  266. std::cout << "El archivo no pudo abrirse, por favor verifique el nombre del archivo.";
  267. exit(1);
  268. }
  269. std::string linea, num;
  270. while (archivoJoc >> linea)
  271. {
  272. int numColumnas = 0;
  273. std::stringstream ss(linea);
  274. while (std::getline(ss, num, ','))
  275. {
  276. det = new CDetector(num);
  277. if (filaInicial)
  278. {
  279. if (det->getType() == "long")
  280. {
  281. vecLong->push_back(new CColumnaLong());
  282. vecLong->at(contLon)->agregar(std::stoll(num));
  283.  
  284. ++contLon;
  285. vec->push_back(1);
  286. }
  287. else if (det->getType() == "string")
  288. {
  289. vecString->push_back(new CColumnaString());
  290. vecString->at(contString)->agregar(num);
  291.  
  292. ++contString;
  293. vec->push_back(2);
  294. }
  295. else if (det->getType() == "double")
  296. {
  297. vecDouble->push_back(new CColumnaDouble());
  298. vecDouble->at(contDouble)->agregar(std::stod(num));
  299.  
  300. ++contDouble;
  301. vec->push_back(3);
  302. }
  303. else if (det->getType() == "bool")
  304. {
  305. vecBool->push_back(new CColumnaBool());
  306. if (num == "SI")
  307. {
  308. vecBool->at(contBool)->agregar(true);
  309. }else { vecBool->at(contBool)->agregar(false); }
  310.  
  311. ++contBool;
  312. vec->push_back(4);
  313. }
  314. }
  315. else {
  316. switch (vec->at(numColumnas))
  317. {
  318. case 1:
  319. vecLong->at(contLon)->agregar(std::stoll(num));
  320. ++contLon;
  321. break;
  322.  
  323. case 2:
  324. vecString->at(contString)->agregar(num);
  325. ++contString;
  326. break;
  327.  
  328. case 3:
  329. vecDouble->at(contDouble)->agregar(std::stod(num));
  330. ++contDouble;
  331. break;
  332.  
  333. case 4:
  334. if (num == "SI")
  335. {
  336. vecBool->at(contBool)->agregar(true);
  337. }
  338. else { vecBool->at(contBool)->agregar(false); }
  339. ++contBool;
  340. break;
  341. default:break;
  342. }
  343. ++numColumnas;
  344. }
  345.  
  346. }
  347. contLon = 0;
  348. contString = 0;
  349. contDouble = 0;
  350. contBool = 0;
  351. filaInicial = false;
  352. ++numFilas;
  353. }
  354. archivoJoc.close();
  355. }
  356.  
  357. };
  358.  
  359. class CDataFrame
  360. {
  361. private:
  362. std::vector<CColumnaLong*>* vecLong;
  363. std::vector<CColumnaString*>* vecString;
  364. std::vector<CColumnaDouble*>* vecDouble;
  365. std::vector<CColumnaBool*>* vecBool;
  366. long long numFilas;
  367. std::vector<long long>* vec;
  368. long long contLon;
  369. long long contString;
  370. long long contDouble;
  371. long long contBool;
  372. CArchivo* archivo;
  373. public:
  374. CDataFrame()
  375. {
  376. vecLong = new std::vector<CColumnaLong*>();
  377. vecString = new std::vector<CColumnaString*>();
  378. vecDouble = new std::vector<CColumnaDouble*>();
  379. vecBool = new std::vector<CColumnaBool*>();
  380. contDouble = 0;
  381. contBool = 0;
  382. contLon = 0;
  383. contString = 0;
  384. archivo = new CArchivo();
  385. numFilas = 0;
  386. vec = new std::vector<long long>();
  387. }
  388. ~CDataFrame()
  389. {
  390. delete vecLong;
  391. delete vecString;
  392. delete vecBool;
  393. delete vecDouble;
  394. delete archivo;
  395. delete vec;
  396. }
  397.  
  398. void leerArchivo()
  399. {
  400. archivo->leerArchivo(vecLong, vecString, vecDouble, vecBool, vec, numFilas);
  401. }
  402.  
  403. void mostrarColumnas()
  404. {
  405. for (long long Fila = 0; Fila < numFilas; ++Fila)
  406. {
  407. for (long long numColumnas = 0; numColumnas < vec->size(); ++numColumnas)
  408. {
  409. switch (vec->at(numColumnas))
  410. {
  411. case 1:
  412. vecLong->at(contLon)->mostrar(Fila);
  413. ++contLon;
  414. break;
  415.  
  416. case 2:
  417. vecString->at(contString)->mostrar(Fila);
  418. ++contString;
  419. break;
  420.  
  421. case 3:
  422. vecDouble->at(contDouble)->mostrar(Fila);
  423. ++contDouble;
  424. break;
  425.  
  426. case 4:
  427. vecBool->at(contBool)->mostrar(Fila);
  428. ++contBool;
  429. break;
  430. default:break;
  431. }
  432. }
  433. std::cout << std::endl;
  434. contLon = 0;
  435. contString = 0;
  436. contDouble = 0;
  437. contBool = 0;
  438. }
  439.  
  440. }
  441. };
  442.  
  443. int main()
  444. {
  445. /*std::map<long long, std::vector<CColumnaLong*>*> mpLong;
  446. std::map<long long, std::vector<CColumnaString*>*> mpString;
  447.  
  448. std::map<long long, std::vector<CColumnaDouble*>*> mpDouble;
  449. std::map<long long, std::vector<CColumnaBool*>*> mpBool;*/
  450. /*CArchivo* archivo = new CArchivo();
  451. archivo->leerArchivo();
  452. delete archivo;*/
  453.  
  454. CDataFrame* df = new CDataFrame();
  455. df->leerArchivo();
  456. df->mostrarColumnas();
  457.  
  458. std::cin.get();
  459. std::cin.get();
  460. delete df;
  461. return 0;
  462. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement