Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2014
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 49.45 KB | None | 0 0
  1. //#include "ArrPersonas.h"
  2. //#include <stdio.h>
  3. //
  4. //ArrPersonas::ArrPersonas(void)
  5. //{ arreglo=NULL;
  6. // N= new int;
  7. // *N=0;
  8. //}
  9. //ArrPersonas::~ArrPersonas(void)
  10. //{ //ELIMINAMOS CADA UNO DE LOS OBJETOS DEL ARREGLO
  11. // for (int i=0;i<*N;i++)
  12. // delete arreglo[i];
  13. //
  14. // delete N;
  15. //}
  16. //Persona** ArrPersonas::Crear_Arreglo()
  17. //{
  18. // return new Persona*[*N+1];
  19. //}
  20. //
  21. //void ArrPersonas::Agregar( Persona *Dato)
  22. //{
  23. // Persona** auxiliar=Crear_Arreglo();
  24. // if (auxiliar!=NULL)
  25. // {
  26. // for (int i=0;i<*N;i++)
  27. // auxiliar[i] = arreglo[i];
  28. //
  29. // auxiliar[*N]=Dato;
  30. // *N=*N+1;
  31. //
  32. // if (arreglo!=NULL)
  33. // delete arreglo;
  34. //
  35. // arreglo=auxiliar;
  36. //
  37. // }
  38. //}
  39. #pragma once
  40. #include <stdio.h>
  41. #include "Persona.h"
  42. class ArrPersonas
  43. {
  44. private:
  45. Persona **arreglo;
  46. int *N;
  47. public:
  48. ArrPersonas(void);
  49. ~ArrPersonas(void);
  50. Persona** Crear_Arreglo();
  51. void Agregar( Persona *Dato);
  52. void Eliminar(int indice);
  53.  
  54. Persona** Mayores25anhos(int *cantidad);
  55.  
  56. Persona** ConLetraAenelNombre(int *cantidad);
  57.  
  58. int Retornar_N();
  59. Persona* Retorna_dato_en_arreglo( int indice);
  60.  
  61. };
  62.  
  63. int ArrPersonas::Retornar_N()
  64. {
  65. return *N;
  66. }
  67.  
  68. Persona* ArrPersonas::Retorna_dato_en_arreglo( int indice)
  69. {
  70. return arreglo[indice];
  71. }
  72.  
  73.  
  74.  
  75. ArrPersonas::ArrPersonas(void)
  76. { arreglo=NULL;
  77. N= new int;
  78. *N=0;
  79. }
  80. ArrPersonas::~ArrPersonas(void)
  81. { //ELIMINAMOS CADA UNO DE LOS OBJETOS DEL ARREGLO
  82. for (int i=0;i<*N;i++)
  83. delete arreglo[i];
  84.  
  85. delete N;
  86. }
  87. Persona** ArrPersonas::Crear_Arreglo()
  88. {
  89. return new Persona*[*N+1];
  90. }
  91. void ArrPersonas::Agregar( Persona *Dato)
  92. {
  93. Persona** auxiliar=Crear_Arreglo();
  94. if (auxiliar!=NULL)
  95. {
  96. for (int i=0;i<*N;i++)
  97. auxiliar[i] = arreglo[i];
  98.  
  99. auxiliar[*N]=Dato;
  100. *N=*N+1;
  101.  
  102. if (arreglo!=NULL)
  103. delete arreglo;
  104. arreglo=auxiliar;
  105. }
  106.  
  107. }
  108. void ArrPersonas::Eliminar(int indice)
  109. {
  110. Persona** auxiliar =new Persona*[*N-1];
  111. if (auxiliar!=NULL)
  112. {
  113. //sobre la izquierda del indice a eliminar;
  114. for (int i=0;i<=indice-1;i++)
  115. auxiliar[i]=arreglo[i];
  116. //sobre la derecha del indice a eliminar;
  117. for (int i=indice+1;i<*N;i++)
  118. auxiliar[i-1]=arreglo[i];
  119.  
  120. *N=*N-1;
  121. if (arreglo!=NULL)
  122. delete arreglo;
  123.  
  124. arreglo=auxiliar;
  125. }
  126.  
  127. }
  128.  
  129. Persona** ArrPersonas::Mayores25anhos(int *cantidad)
  130. {
  131. for (int i=0;i<*N;i++)
  132. if (arreglo[i]->Retornar_Edad()>25)
  133. *cantidad=*cantidad+1;
  134.  
  135. if (*cantidad>0)
  136. { Persona** auxiliar=new Persona*[*cantidad];
  137. int h=0;
  138. for (int i=0;i<*N;i++)
  139. if (arreglo[i]->Retornar_Edad()>25)
  140. {
  141. auxiliar[h]=arreglo[i];
  142. h++;
  143. }
  144. return auxiliar;
  145. }
  146. else
  147. return NULL;
  148. /*for (int i=0;i<*N;i++)
  149. if (arreglo[i]->Retornar_Edad()>25)
  150. *cantidad=*cantidad+1;
  151.  
  152. if (*cantidad>0)
  153. { Persona** auxiliar=new Persona*[*cantidad];
  154. int h=0;
  155. for (int i=0;i<*N;i++)
  156. if (arreglo[i]->Retornar_Edad()>25)
  157. {
  158. auxiliar[h]=arreglo[i];
  159. h++;
  160. }
  161. return auxiliar;
  162. }
  163. else
  164. return NULL;*/
  165. }
  166.  
  167. Persona** ArrPersonas::ConLetraAenelNombre(int *cantidad)
  168. {
  169. for (int i=0;i<*N;i++)
  170. if (arreglo[i]->Retornar_Nombre()[0]=='A' || arreglo[i]->Retornar_Nombre()[0]=='a')
  171. *cantidad=*cantidad+1;
  172.  
  173. if (*cantidad>0)
  174. { Persona** auxiliar=new Persona*[*cantidad];
  175. int h=0;
  176. for (int i=0;i<*N;i++)
  177. if (arreglo[i]->Retornar_Nombre()[0]=='A' || arreglo[i]->Retornar_Nombre()[0]=='a')
  178. {
  179. auxiliar[h]=arreglo[i];
  180. h++;
  181. }
  182. return auxiliar;
  183. }
  184. else
  185. return NULL;
  186.  
  187.  
  188. }
  189. #include "MyForm.h"
  190. using namespace System;
  191. using namespace System ::Windows::Forms;
  192. [STAThread]
  193. void main(array<String^>^ arg)
  194. {
  195. Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false);
  196. Application::Run( gcnew POO1::MyForm());
  197. }
  198. #pragma once
  199.  
  200. namespace POO1 {
  201. #include "ArrPersonas.h"; //Un arreglo de Objetos Persona
  202. #include "Persona.h"; //UN SOLO OBJETO PERSONA
  203. #include <stdio.h>;
  204. using namespace System;
  205. using namespace System::ComponentModel;
  206. using namespace System::Collections;
  207. using namespace System::Windows::Forms;
  208. using namespace System::Data;
  209. using namespace System::Drawing;
  210.  
  211. /// <summary>
  212. /// Summary for MyForm
  213. /// </summary>
  214. public ref class MyForm : public System::Windows::Forms::Form
  215. {
  216. public:
  217. MyForm(void)
  218. {
  219. InitializeComponent();
  220. objeto_ArrPersona=new ArrPersonas();
  221. }
  222. protected:
  223. ~MyForm()
  224. {
  225. if (components)
  226. {
  227. delete components;
  228. }
  229. delete objeto_ArrPersona;
  230. }
  231. private:
  232. /// <summary>
  233. /// Required designer variable.
  234. /// </summary>
  235.  
  236. ArrPersonas *objeto_ArrPersona;
  237.  
  238. Persona *objeto_Persona;
  239.  
  240.  
  241. private: System::Windows::Forms::Button^ button1;
  242. private: System::Windows::Forms::Label^ label1;
  243. private: System::Windows::Forms::Label^ label2;
  244. private: System::Windows::Forms::ListBox^ listBox1;
  245. private: System::Windows::Forms::TextBox^ textBox1;
  246. private: System::Windows::Forms::TextBox^ textBox2;
  247. private: System::Windows::Forms::Label^ label3;
  248. private: System::Windows::Forms::GroupBox^ groupBox1;
  249. private: System::Windows::Forms::Button^ button2;
  250. private: System::Windows::Forms::ListBox^ listBox2;
  251. private: System::Windows::Forms::GroupBox^ groupBox2;
  252. private: System::Windows::Forms::Button^ button3;
  253. private: System::Windows::Forms::ListBox^ listBox3;
  254. private: System::Windows::Forms::Button^ button4;
  255.  
  256.  
  257. System::ComponentModel::Container ^components;
  258.  
  259. #pragma region Windows Form Designer generated code
  260. /// <summary>
  261. /// Required method for Designer support - do not modify
  262. /// the contents of this method with the code editor.
  263. /// </summary>
  264. void InitializeComponent(void)
  265. {
  266. this->button1 = (gcnew System::Windows::Forms::Button());
  267. this->label1 = (gcnew System::Windows::Forms::Label());
  268. this->label2 = (gcnew System::Windows::Forms::Label());
  269. this->listBox1 = (gcnew System::Windows::Forms::ListBox());
  270. this->textBox1 = (gcnew System::Windows::Forms::TextBox());
  271. this->textBox2 = (gcnew System::Windows::Forms::TextBox());
  272. this->label3 = (gcnew System::Windows::Forms::Label());
  273. this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
  274. this->button2 = (gcnew System::Windows::Forms::Button());
  275. this->listBox2 = (gcnew System::Windows::Forms::ListBox());
  276. this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
  277. this->button3 = (gcnew System::Windows::Forms::Button());
  278. this->listBox3 = (gcnew System::Windows::Forms::ListBox());
  279. this->button4 = (gcnew System::Windows::Forms::Button());
  280. this->groupBox1->SuspendLayout();
  281. this->groupBox2->SuspendLayout();
  282. this->SuspendLayout();
  283. //
  284. // button1
  285. //
  286. this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  287. static_cast<System::Byte>(0)));
  288. this->button1->Location = System::Drawing::Point(42, 99);
  289. this->button1->Name = L"button1";
  290. this->button1->Size = System::Drawing::Size(61, 30);
  291. this->button1->TabIndex = 0;
  292. this->button1->Text = L"Crear";
  293. this->button1->UseVisualStyleBackColor = true;
  294. this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
  295. //
  296. // label1
  297. //
  298. this->label1->AutoSize = true;
  299. this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  300. static_cast<System::Byte>(0)));
  301. this->label1->Location = System::Drawing::Point(5, 15);
  302. this->label1->Name = L"label1";
  303. this->label1->Size = System::Drawing::Size(65, 20);
  304. this->label1->TabIndex = 1;
  305. this->label1->Text = L"Nombre";
  306. //
  307. // label2
  308. //
  309. this->label2->AutoSize = true;
  310. this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  311. static_cast<System::Byte>(0)));
  312. this->label2->Location = System::Drawing::Point(8, 55);
  313. this->label2->Name = L"label2";
  314. this->label2->Size = System::Drawing::Size(47, 20);
  315. this->label2->TabIndex = 2;
  316. this->label2->Text = L"Edad";
  317. //
  318. // listBox1
  319. //
  320. this->listBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  321. static_cast<System::Byte>(0)));
  322. this->listBox1->FormattingEnabled = true;
  323. this->listBox1->ItemHeight = 20;
  324. this->listBox1->Location = System::Drawing::Point(12, 169);
  325. this->listBox1->Name = L"listBox1";
  326. this->listBox1->Size = System::Drawing::Size(214, 244);
  327. this->listBox1->TabIndex = 3;
  328. this->listBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &MyForm::listBox1_SelectedIndexChanged);
  329. //
  330. // textBox1
  331. //
  332. this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  333. static_cast<System::Byte>(0)));
  334. this->textBox1->Location = System::Drawing::Point(78, 14);
  335. this->textBox1->MaxLength = 99;
  336. this->textBox1->Name = L"textBox1";
  337. this->textBox1->Size = System::Drawing::Size(148, 26);
  338. this->textBox1->TabIndex = 4;
  339. this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox1_KeyPress);
  340. //
  341. // textBox2
  342. //
  343. this->textBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  344. static_cast<System::Byte>(0)));
  345. this->textBox2->Location = System::Drawing::Point(78, 55);
  346. this->textBox2->MaxLength = 2;
  347. this->textBox2->Name = L"textBox2";
  348. this->textBox2->Size = System::Drawing::Size(44, 26);
  349. this->textBox2->TabIndex = 5;
  350. this->textBox2->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox2_KeyPress);
  351. //
  352. // label3
  353. //
  354. this->label3->AutoSize = true;
  355. this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  356. static_cast<System::Byte>(0)));
  357. this->label3->Location = System::Drawing::Point(8, 146);
  358. this->label3->Name = L"label3";
  359. this->label3->Size = System::Drawing::Size(152, 20);
  360. this->label3->TabIndex = 6;
  361. this->label3->Text = L"Todas las Personas:";
  362. //
  363. // groupBox1
  364. //
  365. this->groupBox1->Controls->Add(this->button2);
  366. this->groupBox1->Controls->Add(this->listBox2);
  367. this->groupBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  368. static_cast<System::Byte>(0)));
  369. this->groupBox1->Location = System::Drawing::Point(232, 13);
  370. this->groupBox1->Name = L"groupBox1";
  371. this->groupBox1->Size = System::Drawing::Size(229, 400);
  372. this->groupBox1->TabIndex = 7;
  373. this->groupBox1->TabStop = false;
  374. this->groupBox1->Text = L"Mayores de 25 años";
  375. //
  376. // button2
  377. //
  378. this->button2->Location = System::Drawing::Point(15, 357);
  379. this->button2->Name = L"button2";
  380. this->button2->Size = System::Drawing::Size(208, 37);
  381. this->button2->TabIndex = 1;
  382. this->button2->Text = L"Filtrar";
  383. this->button2->UseVisualStyleBackColor = true;
  384. this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
  385. //
  386. // listBox2
  387. //
  388. this->listBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  389. static_cast<System::Byte>(0)));
  390. this->listBox2->FormattingEnabled = true;
  391. this->listBox2->ItemHeight = 20;
  392. this->listBox2->Location = System::Drawing::Point(15, 27);
  393. this->listBox2->Name = L"listBox2";
  394. this->listBox2->Size = System::Drawing::Size(208, 324);
  395. this->listBox2->TabIndex = 0;
  396. //
  397. // groupBox2
  398. //
  399. this->groupBox2->Controls->Add(this->button3);
  400. this->groupBox2->Controls->Add(this->listBox3);
  401. this->groupBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  402. static_cast<System::Byte>(0)));
  403. this->groupBox2->Location = System::Drawing::Point(467, 13);
  404. this->groupBox2->Name = L"groupBox2";
  405. this->groupBox2->Size = System::Drawing::Size(229, 400);
  406. this->groupBox2->TabIndex = 8;
  407. this->groupBox2->TabStop = false;
  408. this->groupBox2->Text = L"Nombre inicia con letra \"A\"";
  409. //
  410. // button3
  411. //
  412. this->button3->Location = System::Drawing::Point(9, 357);
  413. this->button3->Name = L"button3";
  414. this->button3->Size = System::Drawing::Size(214, 37);
  415. this->button3->TabIndex = 1;
  416. this->button3->Text = L"Filtrar";
  417. this->button3->UseVisualStyleBackColor = true;
  418. this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
  419. //
  420. // listBox3
  421. //
  422. this->listBox3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  423. static_cast<System::Byte>(0)));
  424. this->listBox3->FormattingEnabled = true;
  425. this->listBox3->ItemHeight = 20;
  426. this->listBox3->Location = System::Drawing::Point(6, 25);
  427. this->listBox3->Name = L"listBox3";
  428. this->listBox3->Size = System::Drawing::Size(217, 324);
  429. this->listBox3->TabIndex = 0;
  430. //
  431. // button4
  432. //
  433. this->button4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  434. static_cast<System::Byte>(0)));
  435. this->button4->Location = System::Drawing::Point(121, 99);
  436. this->button4->Name = L"button4";
  437. this->button4->Size = System::Drawing::Size(75, 30);
  438. this->button4->TabIndex = 9;
  439. this->button4->Text = L"Eliminar";
  440. this->button4->UseVisualStyleBackColor = true;
  441. this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click);
  442. //
  443. // MyForm
  444. //
  445. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  446. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  447. this->ClientSize = System::Drawing::Size(699, 424);
  448. this->Controls->Add(this->button4);
  449. this->Controls->Add(this->groupBox2);
  450. this->Controls->Add(this->groupBox1);
  451. this->Controls->Add(this->label3);
  452. this->Controls->Add(this->textBox2);
  453. this->Controls->Add(this->textBox1);
  454. this->Controls->Add(this->listBox1);
  455. this->Controls->Add(this->label2);
  456. this->Controls->Add(this->label1);
  457. this->Controls->Add(this->button1);
  458. this->Name = L"MyForm";
  459. this->Text = L"MyForm";
  460. this->groupBox1->ResumeLayout(false);
  461. this->groupBox2->ResumeLayout(false);
  462. this->ResumeLayout(false);
  463. this->PerformLayout();
  464.  
  465. }
  466. #pragma endregion
  467. void Insertar_Datos_Persona_en_ListBox()
  468. { listBox1->Items->Clear();
  469. if (objeto_ArrPersona->Retornar_N()>0)
  470. { for (int i=0;i<objeto_ArrPersona->Retornar_N();i++)
  471. { objeto_Persona= objeto_ArrPersona->Retorna_dato_en_arreglo(i);
  472. //Convertimos de char* a String^
  473. System::String ^nombre="Nombre : " +gcnew System::String(objeto_Persona->Retornar_Nombre()) +
  474. " Edad : " + objeto_Persona->Retornar_Edad().ToString() ;
  475. listBox1->Items->Add(nombre);
  476. }
  477. }
  478. }
  479. private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  480. if (textBox1->Text->Length>0 && textBox2->Text->Length>0)
  481. { objeto_Persona= new Persona();
  482. int miedad=Convert::ToInt32(textBox2->Text); objeto_Persona->Cambiar_Edad(miedad);
  483. char*minombre; minombre=new char[100];
  484. sprintf(minombre,"%s",textBox1->Text);//Convierte de St ring^ a char*
  485. objeto_Persona->Cambiar_Nombre(minombre);
  486. objeto_ArrPersona->Agregar(objeto_Persona);
  487. textBox1->Clear();
  488. textBox2->Clear();
  489. }
  490. else
  491. objeto_Persona= NULL;
  492.  
  493. Insertar_Datos_Persona_en_ListBox();
  494. }
  495. private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
  496.  
  497. if (listBox1->SelectedIndex!=-1)
  498. {
  499. objeto_ArrPersona->Eliminar(listBox1->SelectedIndex);
  500. listBox1->SelectedIndex=-1;
  501. Insertar_Datos_Persona_en_ListBox();
  502. textBox1->Clear();
  503. textBox2->Clear();
  504.  
  505. }
  506. }
  507. private: System::Void listBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
  508.  
  509. if (listBox1->SelectedIndex!=-1)
  510. {
  511. objeto_Persona=objeto_ArrPersona->Retorna_dato_en_arreglo(listBox1->SelectedIndex);
  512. textBox1->Text= gcnew System::String(objeto_Persona->Retornar_Nombre());
  513. textBox2->Text= objeto_Persona->Retornar_Edad().ToString();
  514.  
  515. }
  516.  
  517. }
  518. private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
  519.  
  520. int *cantidad;
  521. cantidad=new int;
  522. *cantidad=0;
  523. //int cantidad=0;
  524. Persona** arr_masde25 = objeto_ArrPersona->Mayores25anhos(cantidad);
  525. MessageBox::Show(""+*cantidad, "Advertencia", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
  526. listBox2->Items->Clear();
  527. if (arr_masde25 !=NULL)
  528. {
  529. //for (int i=0;i<*cantidad;i++)
  530. for (int i=0;i<*cantidad;i++)
  531. {
  532.  
  533. System::String ^nombre= "Nombre: " +gcnew System::String(arr_masde25[i]->Retornar_Nombre());
  534. listBox2->Items->Add(nombre);
  535. }
  536. }
  537.  
  538.  
  539. }
  540. private: System::Void textBox2_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
  541. if (!(Char::IsNumber(e->KeyChar)) && (e->KeyChar != char(Keys::Back)))
  542. {
  543. MessageBox::Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
  544. e->Handled = true;
  545. return;
  546. }
  547. }
  548. private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
  549. if (!(Char::IsLetter(e->KeyChar)) && (e->KeyChar != char(Keys::Back)) && !(Char::IsSeparator(e->KeyChar)))
  550. {
  551. MessageBox::Show("Solo se permiten letras", "Advertencia", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
  552. e->Handled = true;
  553. return;
  554. }
  555. }
  556. private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
  557. /* int *cantidad;
  558. cantidad=new int;
  559. *cantidad=0;
  560. Persona** arr_letraA = objeto_ArrPersona->ConLetraAenelNombre(cantidad);
  561. listBox3->Items->Clear();
  562. if (arr_letraA !=NULL)
  563. {
  564. for (int i=0;i<*cantidad;i++)
  565. {
  566. System::String ^nombre= "Nombre: " +gcnew System::String(arr_letraA[i]->Retornar_Nombre());
  567. listBox3->Items->Add(nombre);
  568. }
  569. }*/
  570.  
  571. }
  572. };
  573. }
  574. #pragma once
  575.  
  576. namespace POO1 {
  577. #include "ArrPersonas.h"; //Un arreglo de Objetos Persona
  578. #include "Persona.h"; //UN SOLO OBJETO PERSONA
  579. #include <stdio.h>;
  580. using namespace System;
  581. using namespace System::ComponentModel;
  582. using namespace System::Collections;
  583. using namespace System::Windows::Forms;
  584. using namespace System::Data;
  585. using namespace System::Drawing;
  586.  
  587. /// <summary>
  588. /// Summary for MyForm
  589. /// </summary>
  590. public ref class MyForm : public System::Windows::Forms::Form
  591. {
  592. public:
  593. MyForm(void)
  594. {
  595. InitializeComponent();
  596. objeto_ArrPersona=new ArrPersonas();
  597. }
  598. protected:
  599. ~MyForm()
  600. {
  601. if (components)
  602. {
  603. delete components;
  604. }
  605. delete objeto_ArrPersona;
  606. }
  607. private:
  608. /// <summary>
  609. /// Required designer variable.
  610. /// </summary>
  611.  
  612. ArrPersonas *objeto_ArrPersona;
  613.  
  614. Persona *objeto_Persona;
  615.  
  616.  
  617. private: System::Windows::Forms::Button^ button1;
  618. private: System::Windows::Forms::Label^ label1;
  619. private: System::Windows::Forms::Label^ label2;
  620. private: System::Windows::Forms::ListBox^ listBox1;
  621. private: System::Windows::Forms::TextBox^ textBox1;
  622. private: System::Windows::Forms::TextBox^ textBox2;
  623. private: System::Windows::Forms::Label^ label3;
  624. private: System::Windows::Forms::GroupBox^ groupBox1;
  625. private: System::Windows::Forms::Button^ button2;
  626. private: System::Windows::Forms::ListBox^ listBox2;
  627. private: System::Windows::Forms::GroupBox^ groupBox2;
  628. private: System::Windows::Forms::Button^ button3;
  629. private: System::Windows::Forms::ListBox^ listBox3;
  630. private: System::Windows::Forms::Button^ button4;
  631.  
  632.  
  633. System::ComponentModel::Container ^components;
  634.  
  635. #pragma region Windows Form Designer generated code
  636. /// <summary>
  637. /// Required method for Designer support - do not modify
  638. /// the contents of this method with the code editor.
  639. /// </summary>
  640. void InitializeComponent(void)
  641. {
  642. this->button1 = (gcnew System::Windows::Forms::Button());
  643. this->label1 = (gcnew System::Windows::Forms::Label());
  644. this->label2 = (gcnew System::Windows::Forms::Label());
  645. this->listBox1 = (gcnew System::Windows::Forms::ListBox());
  646. this->textBox1 = (gcnew System::Windows::Forms::TextBox());
  647. this->textBox2 = (gcnew System::Windows::Forms::TextBox());
  648. this->label3 = (gcnew System::Windows::Forms::Label());
  649. this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
  650. this->button2 = (gcnew System::Windows::Forms::Button());
  651. this->listBox2 = (gcnew System::Windows::Forms::ListBox());
  652. this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
  653. this->button3 = (gcnew System::Windows::Forms::Button());
  654. this->listBox3 = (gcnew System::Windows::Forms::ListBox());
  655. this->button4 = (gcnew System::Windows::Forms::Button());
  656. this->groupBox1->SuspendLayout();
  657. this->groupBox2->SuspendLayout();
  658. this->SuspendLayout();
  659. //
  660. // button1
  661. //
  662. this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  663. static_cast<System::Byte>(0)));
  664. this->button1->Location = System::Drawing::Point(42, 99);
  665. this->button1->Name = L"button1";
  666. this->button1->Size = System::Drawing::Size(61, 30);
  667. this->button1->TabIndex = 0;
  668. this->button1->Text = L"Crear";
  669. this->button1->UseVisualStyleBackColor = true;
  670. this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
  671. //
  672. // label1
  673. //
  674. this->label1->AutoSize = true;
  675. this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  676. static_cast<System::Byte>(0)));
  677. this->label1->Location = System::Drawing::Point(5, 15);
  678. this->label1->Name = L"label1";
  679. this->label1->Size = System::Drawing::Size(65, 20);
  680. this->label1->TabIndex = 1;
  681. this->label1->Text = L"Nombre";
  682. //
  683. // label2
  684. //
  685. this->label2->AutoSize = true;
  686. this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  687. static_cast<System::Byte>(0)));
  688. this->label2->Location = System::Drawing::Point(8, 55);
  689. this->label2->Name = L"label2";
  690. this->label2->Size = System::Drawing::Size(47, 20);
  691. this->label2->TabIndex = 2;
  692. this->label2->Text = L"Edad";
  693. //
  694. // listBox1
  695. //
  696. this->listBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  697. static_cast<System::Byte>(0)));
  698. this->listBox1->FormattingEnabled = true;
  699. this->listBox1->ItemHeight = 20;
  700. this->listBox1->Location = System::Drawing::Point(12, 169);
  701. this->listBox1->Name = L"listBox1";
  702. this->listBox1->Size = System::Drawing::Size(214, 244);
  703. this->listBox1->TabIndex = 3;
  704. this->listBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &MyForm::listBox1_SelectedIndexChanged);
  705. //
  706. // textBox1
  707. //
  708. this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  709. static_cast<System::Byte>(0)));
  710. this->textBox1->Location = System::Drawing::Point(78, 14);
  711. this->textBox1->MaxLength = 99;
  712. this->textBox1->Name = L"textBox1";
  713. this->textBox1->Size = System::Drawing::Size(148, 26);
  714. this->textBox1->TabIndex = 4;
  715. this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox1_KeyPress);
  716. //
  717. // textBox2
  718. //
  719. this->textBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  720. static_cast<System::Byte>(0)));
  721. this->textBox2->Location = System::Drawing::Point(78, 55);
  722. this->textBox2->MaxLength = 2;
  723. this->textBox2->Name = L"textBox2";
  724. this->textBox2->Size = System::Drawing::Size(44, 26);
  725. this->textBox2->TabIndex = 5;
  726. this->textBox2->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox2_KeyPress);
  727. //
  728. // label3
  729. //
  730. this->label3->AutoSize = true;
  731. this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  732. static_cast<System::Byte>(0)));
  733. this->label3->Location = System::Drawing::Point(8, 146);
  734. this->label3->Name = L"label3";
  735. this->label3->Size = System::Drawing::Size(152, 20);
  736. this->label3->TabIndex = 6;
  737. this->label3->Text = L"Todas las Personas:";
  738. //
  739. // groupBox1
  740. //
  741. this->groupBox1->Controls->Add(this->button2);
  742. this->groupBox1->Controls->Add(this->listBox2);
  743. this->groupBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  744. static_cast<System::Byte>(0)));
  745. this->groupBox1->Location = System::Drawing::Point(232, 13);
  746. this->groupBox1->Name = L"groupBox1";
  747. this->groupBox1->Size = System::Drawing::Size(229, 400);
  748. this->groupBox1->TabIndex = 7;
  749. this->groupBox1->TabStop = false;
  750. this->groupBox1->Text = L"Mayores de 25 años";
  751. //
  752. // button2
  753. //
  754. this->button2->Location = System::Drawing::Point(15, 357);
  755. this->button2->Name = L"button2";
  756. this->button2->Size = System::Drawing::Size(208, 37);
  757. this->button2->TabIndex = 1;
  758. this->button2->Text = L"Filtrar";
  759. this->button2->UseVisualStyleBackColor = true;
  760. this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
  761. //
  762. // listBox2
  763. //
  764. this->listBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  765. static_cast<System::Byte>(0)));
  766. this->listBox2->FormattingEnabled = true;
  767. this->listBox2->ItemHeight = 20;
  768. this->listBox2->Location = System::Drawing::Point(15, 27);
  769. this->listBox2->Name = L"listBox2";
  770. this->listBox2->Size = System::Drawing::Size(208, 324);
  771. this->listBox2->TabIndex = 0;
  772. //
  773. // groupBox2
  774. //
  775. this->groupBox2->Controls->Add(this->button3);
  776. this->groupBox2->Controls->Add(this->listBox3);
  777. this->groupBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  778. static_cast<System::Byte>(0)));
  779. this->groupBox2->Location = System::Drawing::Point(467, 13);
  780. this->groupBox2->Name = L"groupBox2";
  781. this->groupBox2->Size = System::Drawing::Size(229, 400);
  782. this->groupBox2->TabIndex = 8;
  783. this->groupBox2->TabStop = false;
  784. this->groupBox2->Text = L"Nombre inicia con letra \"A\"";
  785. //
  786. // button3
  787. //
  788. this->button3->Location = System::Drawing::Point(9, 357);
  789. this->button3->Name = L"button3";
  790. this->button3->Size = System::Drawing::Size(214, 37);
  791. this->button3->TabIndex = 1;
  792. this->button3->Text = L"Filtrar";
  793. this->button3->UseVisualStyleBackColor = true;
  794. this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
  795. //
  796. // listBox3
  797. //
  798. this->listBox3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  799. static_cast<System::Byte>(0)));
  800. this->listBox3->FormattingEnabled = true;
  801. this->listBox3->ItemHeight = 20;
  802. this->listBox3->Location = System::Drawing::Point(6, 25);
  803. this->listBox3->Name = L"listBox3";
  804. this->listBox3->Size = System::Drawing::Size(217, 324);
  805. this->listBox3->TabIndex = 0;
  806. //
  807. // button4
  808. //
  809. this->button4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  810. static_cast<System::Byte>(0)));
  811. this->button4->Location = System::Drawing::Point(121, 99);
  812. this->button4->Name = L"button4";
  813. this->button4->Size = System::Drawing::Size(75, 30);
  814. this->button4->TabIndex = 9;
  815. this->button4->Text = L"Eliminar";
  816. this->button4->UseVisualStyleBackColor = true;
  817. this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click);
  818. //
  819. // MyForm
  820. //
  821. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  822. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  823. this->ClientSize = System::Drawing::Size(699, 424);
  824. this->Controls->Add(this->button4);
  825. this->Controls->Add(this->groupBox2);
  826. this->Controls->Add(this->groupBox1);
  827. this->Controls->Add(this->label3);
  828. this->Controls->Add(this->textBox2);
  829. this->Controls->Add(this->textBox1);
  830. this->Controls->Add(this->listBox1);
  831. this->Controls->Add(this->label2);
  832. this->Controls->Add(this->label1);
  833. this->Controls->Add(this->button1);
  834. this->Name = L"MyForm";
  835. this->Text = L"MyForm";
  836. this->groupBox1->ResumeLayout(false);
  837. this->groupBox2->ResumeLayout(false);
  838. this->ResumeLayout(false);
  839. this->PerformLayout();
  840.  
  841. }
  842. #pragma endregion
  843. void Insertar_Datos_Persona_en_ListBox()
  844. { listBox1->Items->Clear();
  845. if (objeto_ArrPersona->Retornar_N()>0)
  846. { for (int i=0;i<objeto_ArrPersona->Retornar_N();i++)
  847. { objeto_Persona= objeto_ArrPersona->Retorna_dato_en_arreglo(i);
  848. //Convertimos de char* a String^
  849. System::String ^nombre="Nombre : " +gcnew System::String(objeto_Persona->Retornar_Nombre()) +
  850. " Edad : " + objeto_Persona->Retornar_Edad().ToString() ;
  851. listBox1->Items->Add(nombre);
  852. }
  853. }
  854. }
  855. private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  856. if (textBox1->Text->Length>0 && textBox2->Text->Length>0)
  857. { objeto_Persona= new Persona();
  858. int miedad=Convert::ToInt32(textBox2->Text); objeto_Persona->Cambiar_Edad(miedad);
  859. char*minombre; minombre=new char[100];
  860. sprintf(minombre,"%s",textBox1->Text);//Convierte de St ring^ a char*
  861. objeto_Persona->Cambiar_Nombre(minombre);
  862. objeto_ArrPersona->Agregar(objeto_Persona);
  863. textBox1->Clear();
  864. textBox2->Clear();
  865. }
  866. else
  867. objeto_Persona= NULL;
  868.  
  869. Insertar_Datos_Persona_en_ListBox();
  870. }
  871. private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
  872.  
  873. if (listBox1->SelectedIndex!=-1)
  874. {
  875. objeto_ArrPersona->Eliminar(listBox1->SelectedIndex);
  876. listBox1->SelectedIndex=-1;
  877. Insertar_Datos_Persona_en_ListBox();
  878. textBox1->Clear();
  879. textBox2->Clear();
  880.  
  881. }
  882. }
  883. private: System::Void listBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
  884.  
  885. if (listBox1->SelectedIndex!=-1)
  886. {
  887. objeto_Persona=objeto_ArrPersona->Retorna_dato_en_arreglo(listBox1->SelectedIndex);
  888. textBox1->Text= gcnew System::String(objeto_Persona->Retornar_Nombre());
  889. textBox2->Text= objeto_Persona->Retornar_Edad().ToString();
  890.  
  891. }
  892.  
  893. }
  894. private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
  895.  
  896. int *cantidad;
  897. cantidad=new int;
  898. *cantidad=0;
  899. //int cantidad=0;
  900. Persona** arr_masde25 = objeto_ArrPersona->Mayores25anhos(cantidad);
  901. MessageBox::Show(""+*cantidad, "Advertencia", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
  902. listBox2->Items->Clear();
  903. if (arr_masde25 !=NULL)
  904. {
  905. //for (int i=0;i<*cantidad;i++)
  906. for (int i=0;i<*cantidad;i++)
  907. {
  908.  
  909. System::String ^nombre= "Nombre: " +gcnew System::String(arr_masde25[i]->Retornar_Nombre());
  910. listBox2->Items->Add(nombre);
  911. }
  912. }
  913.  
  914.  
  915. }
  916. private: System::Void textBox2_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
  917. if (!(Char::IsNumber(e->KeyChar)) && (e->KeyChar != char(Keys::Back)))
  918. {
  919. MessageBox::Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
  920. e->Handled = true;
  921. return;
  922. }
  923. }
  924. private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
  925. if (!(Char::IsLetter(e->KeyChar)) && (e->KeyChar != char(Keys::Back)) && !(Char::IsSeparator(e->KeyChar)))
  926. {
  927. MessageBox::Show("Solo se permiten letras", "Advertencia", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
  928. e->Handled = true;
  929. return;
  930. }
  931. }
  932. private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
  933. /* int *cantidad;
  934. cantidad=new int;
  935. *cantidad=0;
  936. Persona** arr_letraA = objeto_ArrPersona->ConLetraAenelNombre(cantidad);
  937. listBox3->Items->Clear();
  938. if (arr_letraA !=NULL)
  939. {
  940. for (int i=0;i<*cantidad;i++)
  941. {
  942. System::String ^nombre= "Nombre: " +gcnew System::String(arr_letraA[i]->Retornar_Nombre());
  943. listBox3->Items->Add(nombre);
  944. }
  945. }*/
  946.  
  947. }
  948. };
  949. }
  950.  
  951.  
  952.  
  953.  
  954.  
  955.  
  956. #pragma once
  957.  
  958. namespace POO1 {
  959. #include "ArrPersonas.h"; //Un arreglo de Objetos Persona
  960. #include "Persona.h"; //UN SOLO OBJETO PERSONA
  961. #include <stdio.h>;
  962. using namespace System;
  963. using namespace System::ComponentModel;
  964. using namespace System::Collections;
  965. using namespace System::Windows::Forms;
  966. using namespace System::Data;
  967. using namespace System::Drawing;
  968.  
  969. /// <summary>
  970. /// Summary for MyForm
  971. /// </summary>
  972. public ref class MyForm : public System::Windows::Forms::Form
  973. {
  974. public:
  975. MyForm(void)
  976. {
  977. InitializeComponent();
  978. objeto_ArrPersona=new ArrPersonas();
  979. }
  980. protected:
  981. ~MyForm()
  982. {
  983. if (components)
  984. {
  985. delete components;
  986. }
  987. delete objeto_ArrPersona;
  988. }
  989. private:
  990. /// <summary>
  991. /// Required designer variable.
  992. /// </summary>
  993.  
  994. ArrPersonas *objeto_ArrPersona;
  995.  
  996. Persona *objeto_Persona;
  997.  
  998.  
  999. private: System::Windows::Forms::Button^ button1;
  1000. private: System::Windows::Forms::Label^ label1;
  1001. private: System::Windows::Forms::Label^ label2;
  1002. private: System::Windows::Forms::ListBox^ listBox1;
  1003. private: System::Windows::Forms::TextBox^ textBox1;
  1004. private: System::Windows::Forms::TextBox^ textBox2;
  1005. private: System::Windows::Forms::Label^ label3;
  1006. private: System::Windows::Forms::GroupBox^ groupBox1;
  1007. private: System::Windows::Forms::Button^ button2;
  1008. private: System::Windows::Forms::ListBox^ listBox2;
  1009. private: System::Windows::Forms::GroupBox^ groupBox2;
  1010. private: System::Windows::Forms::Button^ button3;
  1011. private: System::Windows::Forms::ListBox^ listBox3;
  1012. private: System::Windows::Forms::Button^ button4;
  1013.  
  1014.  
  1015. System::ComponentModel::Container ^components;
  1016.  
  1017. #pragma region Windows Form Designer generated code
  1018. /// <summary>
  1019. /// Required method for Designer support - do not modify
  1020. /// the contents of this method with the code editor.
  1021. /// </summary>
  1022. void InitializeComponent(void)
  1023. {
  1024. this->button1 = (gcnew System::Windows::Forms::Button());
  1025. this->label1 = (gcnew System::Windows::Forms::Label());
  1026. this->label2 = (gcnew System::Windows::Forms::Label());
  1027. this->listBox1 = (gcnew System::Windows::Forms::ListBox());
  1028. this->textBox1 = (gcnew System::Windows::Forms::TextBox());
  1029. this->textBox2 = (gcnew System::Windows::Forms::TextBox());
  1030. this->label3 = (gcnew System::Windows::Forms::Label());
  1031. this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
  1032. this->button2 = (gcnew System::Windows::Forms::Button());
  1033. this->listBox2 = (gcnew System::Windows::Forms::ListBox());
  1034. this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
  1035. this->button3 = (gcnew System::Windows::Forms::Button());
  1036. this->listBox3 = (gcnew System::Windows::Forms::ListBox());
  1037. this->button4 = (gcnew System::Windows::Forms::Button());
  1038. this->groupBox1->SuspendLayout();
  1039. this->groupBox2->SuspendLayout();
  1040. this->SuspendLayout();
  1041. //
  1042. // button1
  1043. //
  1044. this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1045. static_cast<System::Byte>(0)));
  1046. this->button1->Location = System::Drawing::Point(42, 99);
  1047. this->button1->Name = L"button1";
  1048. this->button1->Size = System::Drawing::Size(61, 30);
  1049. this->button1->TabIndex = 0;
  1050. this->button1->Text = L"Crear";
  1051. this->button1->UseVisualStyleBackColor = true;
  1052. this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
  1053. //
  1054. // label1
  1055. //
  1056. this->label1->AutoSize = true;
  1057. this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1058. static_cast<System::Byte>(0)));
  1059. this->label1->Location = System::Drawing::Point(5, 15);
  1060. this->label1->Name = L"label1";
  1061. this->label1->Size = System::Drawing::Size(65, 20);
  1062. this->label1->TabIndex = 1;
  1063. this->label1->Text = L"Nombre";
  1064. //
  1065. // label2
  1066. //
  1067. this->label2->AutoSize = true;
  1068. this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1069. static_cast<System::Byte>(0)));
  1070. this->label2->Location = System::Drawing::Point(8, 55);
  1071. this->label2->Name = L"label2";
  1072. this->label2->Size = System::Drawing::Size(47, 20);
  1073. this->label2->TabIndex = 2;
  1074. this->label2->Text = L"Edad";
  1075. //
  1076. // listBox1
  1077. //
  1078. this->listBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1079. static_cast<System::Byte>(0)));
  1080. this->listBox1->FormattingEnabled = true;
  1081. this->listBox1->ItemHeight = 20;
  1082. this->listBox1->Location = System::Drawing::Point(12, 169);
  1083. this->listBox1->Name = L"listBox1";
  1084. this->listBox1->Size = System::Drawing::Size(214, 244);
  1085. this->listBox1->TabIndex = 3;
  1086. this->listBox1->SelectedIndexChanged += gcnew System::EventHandler(this, &MyForm::listBox1_SelectedIndexChanged);
  1087. //
  1088. // textBox1
  1089. //
  1090. this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1091. static_cast<System::Byte>(0)));
  1092. this->textBox1->Location = System::Drawing::Point(78, 14);
  1093. this->textBox1->MaxLength = 99;
  1094. this->textBox1->Name = L"textBox1";
  1095. this->textBox1->Size = System::Drawing::Size(148, 26);
  1096. this->textBox1->TabIndex = 4;
  1097. this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox1_KeyPress);
  1098. //
  1099. // textBox2
  1100. //
  1101. this->textBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1102. static_cast<System::Byte>(0)));
  1103. this->textBox2->Location = System::Drawing::Point(78, 55);
  1104. this->textBox2->MaxLength = 2;
  1105. this->textBox2->Name = L"textBox2";
  1106. this->textBox2->Size = System::Drawing::Size(44, 26);
  1107. this->textBox2->TabIndex = 5;
  1108. this->textBox2->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox2_KeyPress);
  1109. //
  1110. // label3
  1111. //
  1112. this->label3->AutoSize = true;
  1113. this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1114. static_cast<System::Byte>(0)));
  1115. this->label3->Location = System::Drawing::Point(8, 146);
  1116. this->label3->Name = L"label3";
  1117. this->label3->Size = System::Drawing::Size(152, 20);
  1118. this->label3->TabIndex = 6;
  1119. this->label3->Text = L"Todas las Personas:";
  1120. //
  1121. // groupBox1
  1122. //
  1123. this->groupBox1->Controls->Add(this->button2);
  1124. this->groupBox1->Controls->Add(this->listBox2);
  1125. this->groupBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1126. static_cast<System::Byte>(0)));
  1127. this->groupBox1->Location = System::Drawing::Point(232, 13);
  1128. this->groupBox1->Name = L"groupBox1";
  1129. this->groupBox1->Size = System::Drawing::Size(229, 400);
  1130. this->groupBox1->TabIndex = 7;
  1131. this->groupBox1->TabStop = false;
  1132. this->groupBox1->Text = L"Mayores de 25 años";
  1133. //
  1134. // button2
  1135. //
  1136. this->button2->Location = System::Drawing::Point(15, 357);
  1137. this->button2->Name = L"button2";
  1138. this->button2->Size = System::Drawing::Size(208, 37);
  1139. this->button2->TabIndex = 1;
  1140. this->button2->Text = L"Filtrar";
  1141. this->button2->UseVisualStyleBackColor = true;
  1142. this->button2->Click += gcnew System::EventHandler(this, &MyForm::button2_Click);
  1143. //
  1144. // listBox2
  1145. //
  1146. this->listBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1147. static_cast<System::Byte>(0)));
  1148. this->listBox2->FormattingEnabled = true;
  1149. this->listBox2->ItemHeight = 20;
  1150. this->listBox2->Location = System::Drawing::Point(15, 27);
  1151. this->listBox2->Name = L"listBox2";
  1152. this->listBox2->Size = System::Drawing::Size(208, 324);
  1153. this->listBox2->TabIndex = 0;
  1154. //
  1155. // groupBox2
  1156. //
  1157. this->groupBox2->Controls->Add(this->button3);
  1158. this->groupBox2->Controls->Add(this->listBox3);
  1159. this->groupBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1160. static_cast<System::Byte>(0)));
  1161. this->groupBox2->Location = System::Drawing::Point(467, 13);
  1162. this->groupBox2->Name = L"groupBox2";
  1163. this->groupBox2->Size = System::Drawing::Size(229, 400);
  1164. this->groupBox2->TabIndex = 8;
  1165. this->groupBox2->TabStop = false;
  1166. this->groupBox2->Text = L"Nombre inicia con letra \"A\"";
  1167. //
  1168. // button3
  1169. //
  1170. this->button3->Location = System::Drawing::Point(9, 357);
  1171. this->button3->Name = L"button3";
  1172. this->button3->Size = System::Drawing::Size(214, 37);
  1173. this->button3->TabIndex = 1;
  1174. this->button3->Text = L"Filtrar";
  1175. this->button3->UseVisualStyleBackColor = true;
  1176. this->button3->Click += gcnew System::EventHandler(this, &MyForm::button3_Click);
  1177. //
  1178. // listBox3
  1179. //
  1180. this->listBox3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1181. static_cast<System::Byte>(0)));
  1182. this->listBox3->FormattingEnabled = true;
  1183. this->listBox3->ItemHeight = 20;
  1184. this->listBox3->Location = System::Drawing::Point(6, 25);
  1185. this->listBox3->Name = L"listBox3";
  1186. this->listBox3->Size = System::Drawing::Size(217, 324);
  1187. this->listBox3->TabIndex = 0;
  1188. //
  1189. // button4
  1190. //
  1191. this->button4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  1192. static_cast<System::Byte>(0)));
  1193. this->button4->Location = System::Drawing::Point(121, 99);
  1194. this->button4->Name = L"button4";
  1195. this->button4->Size = System::Drawing::Size(75, 30);
  1196. this->button4->TabIndex = 9;
  1197. this->button4->Text = L"Eliminar";
  1198. this->button4->UseVisualStyleBackColor = true;
  1199. this->button4->Click += gcnew System::EventHandler(this, &MyForm::button4_Click);
  1200. //
  1201. // MyForm
  1202. //
  1203. this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  1204. this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  1205. this->ClientSize = System::Drawing::Size(699, 424);
  1206. this->Controls->Add(this->button4);
  1207. this->Controls->Add(this->groupBox2);
  1208. this->Controls->Add(this->groupBox1);
  1209. this->Controls->Add(this->label3);
  1210. this->Controls->Add(this->textBox2);
  1211. this->Controls->Add(this->textBox1);
  1212. this->Controls->Add(this->listBox1);
  1213. this->Controls->Add(this->label2);
  1214. this->Controls->Add(this->label1);
  1215. this->Controls->Add(this->button1);
  1216. this->Name = L"MyForm";
  1217. this->Text = L"MyForm";
  1218. this->groupBox1->ResumeLayout(false);
  1219. this->groupBox2->ResumeLayout(false);
  1220. this->ResumeLayout(false);
  1221. this->PerformLayout();
  1222.  
  1223. }
  1224. #pragma endregion
  1225. void Insertar_Datos_Persona_en_ListBox()
  1226. { listBox1->Items->Clear();
  1227. if (objeto_ArrPersona->Retornar_N()>0)
  1228. { for (int i=0;i<objeto_ArrPersona->Retornar_N();i++)
  1229. { objeto_Persona= objeto_ArrPersona->Retorna_dato_en_arreglo(i);
  1230. //Convertimos de char* a String^
  1231. System::String ^nombre="Nombre : " +gcnew System::String(objeto_Persona->Retornar_Nombre()) +
  1232. " Edad : " + objeto_Persona->Retornar_Edad().ToString() ;
  1233. listBox1->Items->Add(nombre);
  1234. }
  1235. }
  1236. }
  1237. private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  1238. if (textBox1->Text->Length>0 && textBox2->Text->Length>0)
  1239. { objeto_Persona= new Persona();
  1240. int miedad=Convert::ToInt32(textBox2->Text); objeto_Persona->Cambiar_Edad(miedad);
  1241. char*minombre; minombre=new char[100];
  1242. sprintf(minombre,"%s",textBox1->Text);//Convierte de St ring^ a char*
  1243. objeto_Persona->Cambiar_Nombre(minombre);
  1244. objeto_ArrPersona->Agregar(objeto_Persona);
  1245. textBox1->Clear();
  1246. textBox2->Clear();
  1247. }
  1248. else
  1249. objeto_Persona= NULL;
  1250.  
  1251. Insertar_Datos_Persona_en_ListBox();
  1252. }
  1253. private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
  1254.  
  1255. if (listBox1->SelectedIndex!=-1)
  1256. {
  1257. objeto_ArrPersona->Eliminar(listBox1->SelectedIndex);
  1258. listBox1->SelectedIndex=-1;
  1259. Insertar_Datos_Persona_en_ListBox();
  1260. textBox1->Clear();
  1261. textBox2->Clear();
  1262.  
  1263. }
  1264. }
  1265. private: System::Void listBox1_SelectedIndexChanged(System::Object^ sender, System::EventArgs^ e) {
  1266.  
  1267. if (listBox1->SelectedIndex!=-1)
  1268. {
  1269. objeto_Persona=objeto_ArrPersona->Retorna_dato_en_arreglo(listBox1->SelectedIndex);
  1270. textBox1->Text= gcnew System::String(objeto_Persona->Retornar_Nombre());
  1271. textBox2->Text= objeto_Persona->Retornar_Edad().ToString();
  1272.  
  1273. }
  1274.  
  1275. }
  1276. private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
  1277.  
  1278. int *cantidad;
  1279. cantidad=new int;
  1280. *cantidad=0;
  1281. //int cantidad=0;
  1282. Persona** arr_masde25 = objeto_ArrPersona->Mayores25anhos(cantidad);
  1283. MessageBox::Show(""+*cantidad, "Advertencia", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
  1284. listBox2->Items->Clear();
  1285. if (arr_masde25 !=NULL)
  1286. {
  1287. //for (int i=0;i<*cantidad;i++)
  1288. for (int i=0;i<*cantidad;i++)
  1289. {
  1290.  
  1291. System::String ^nombre= "Nombre: " +gcnew System::String(arr_masde25[i]->Retornar_Nombre());
  1292. listBox2->Items->Add(nombre);
  1293. }
  1294. }
  1295.  
  1296.  
  1297. }
  1298. private: System::Void textBox2_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
  1299. if (!(Char::IsNumber(e->KeyChar)) && (e->KeyChar != char(Keys::Back)))
  1300. {
  1301. MessageBox::Show("Solo se permiten numeros", "Advertencia", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
  1302. e->Handled = true;
  1303. return;
  1304. }
  1305. }
  1306. private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
  1307. if (!(Char::IsLetter(e->KeyChar)) && (e->KeyChar != char(Keys::Back)) && !(Char::IsSeparator(e->KeyChar)))
  1308. {
  1309. MessageBox::Show("Solo se permiten letras", "Advertencia", MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
  1310. e->Handled = true;
  1311. return;
  1312. }
  1313. }
  1314. private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
  1315. /* int *cantidad;
  1316. cantidad=new int;
  1317. *cantidad=0;
  1318. Persona** arr_letraA = objeto_ArrPersona->ConLetraAenelNombre(cantidad);
  1319. listBox3->Items->Clear();
  1320. if (arr_letraA !=NULL)
  1321. {
  1322. for (int i=0;i<*cantidad;i++)
  1323. {
  1324. System::String ^nombre= "Nombre: " +gcnew System::String(arr_letraA[i]->Retornar_Nombre());
  1325. listBox3->Items->Add(nombre);
  1326. }
  1327. }*/
  1328.  
  1329. }
  1330. };
  1331. }
  1332. //#include "Persona.h"
  1333. //#include <string.h>
  1334. //
  1335. //Persona::Persona(void)
  1336. //{
  1337. // Edad=0;
  1338. // Nombre=new char[100];
  1339. //}
  1340. //Persona::~Persona(void)
  1341. //{
  1342. // delete[] Nombre;
  1343. //}
  1344. //void Persona::Cambiar_Edad(int nuevo_valor)
  1345. //{
  1346. // Edad=nuevo_valor;
  1347. //}
  1348. //int Persona::Retornar_Edad()
  1349. //{
  1350. // return Edad;
  1351. //}
  1352. //void Persona::Cambiar_Nombre(char* nuevo_valor)
  1353. //{
  1354. // strcpy(Nombre,nuevo_valor);
  1355. //}
  1356. //char* Persona::Retornar_Nombre()
  1357. //{
  1358. // return Nombre;
  1359. //}
  1360. #pragma once
  1361. #include <string.h>
  1362.  
  1363. class Persona
  1364. {
  1365. private:
  1366. char* Nombre;
  1367. int Edad;
  1368.  
  1369. public:
  1370. Persona(void); //Constructor
  1371. ~Persona(void); //Destructor
  1372.  
  1373. void Cambiar_Edad(int nuevo_valor);
  1374. int Retornar_Edad();
  1375.  
  1376. void Cambiar_Nombre(char* nuevo_valor);
  1377. char* Retornar_Nombre();
  1378. };
  1379.  
  1380.  
  1381. Persona::Persona(void)
  1382. {
  1383. Edad=0;
  1384. Nombre=new char[100];
  1385. }
  1386. Persona::~Persona(void)
  1387. {
  1388. delete[] Nombre;
  1389. }
  1390. void Persona::Cambiar_Edad(int nuevo_valor)
  1391. {
  1392. Edad=nuevo_valor;
  1393. }
  1394. int Persona::Retornar_Edad()
  1395. {
  1396. return Edad;
  1397. }
  1398. void Persona::Cambiar_Nombre(char* nuevo_valor)
  1399. {
  1400. strcpy(Nombre,nuevo_valor);
  1401. }
  1402. char* Persona::Retornar_Nombre()
  1403. {
  1404. return Nombre;
  1405. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement