Anda di halaman 1dari 12

Pais.

h
#pragma once
#include <string.h>
class Pais
{
private:
char *_Nombre, *_Continente;
int _Poblacion;

public:
char *get_Nombre();
char *get_Continente();
int get_Poblacion();
void set_Nombre(char *vNombre);
void set_Continente(char *vContinente);
void set_Poblacion(int vPoblacion);

Pais(char vNombre=' ',char vContinente=' ',int vPoblacion=0);


~Pais();
};
Pais::Pais(char vNombre,char vContinente,int vPoblacion)
{
_Nombre= new char[25];
_Continente= new char[25];
_Poblacion=vPoblacion;
}
Pais::~Pais(void)
{
delete _Nombre;
delete _Continente;
}
char *Pais::get_Nombre()
{
return _Nombre;
}
char *Pais::get_Continente()
{
return _Continente;
}
int Pais::get_Poblacion()
{
return _Poblacion;
}
void Pais::set_Nombre(char *vNombre)
{
strcpy(_Nombre,vNombre);
}
void Pais::set_Continente(char *vContinente)
{
strcpy(_Continente,vContinente);
}
void Pais::set_Poblacion(int vPoblacion)
{
_Poblacion=vPoblacion;
}
ArrPaises.h
#pragma once
#include "Pais.h"
class ArrPaises
{
int numPaises;
Pais **_pais;
public:
Pais **Crear_Arreglo();
bool Insertar_Pais(Pais *pais);
bool Eliminar_Pais();
int Retornar_NumPaises();
Pais* Retorna_dato_en_arreglo(int indice);
ArrPaises(void);
~ArrPaises(void);
};

ArrPaises::ArrPaises(void)
{
numPaises=0;
_pais= nullptr; //arreglo de paises
}

ArrPaises::~ArrPaises(void)
{
for (int i = 0; i < numPaises; i++)
{
delete _pais[i];
}

bool ArrPaises::Insertar_Pais(Pais *pais)


{
Pais **AuxArrPais= Crear_Arreglo();
if(AuxArrPais!=nullptr)
{
for (int i = 0; i < numPaises; i++)
{
AuxArrPais[i]=_pais[i];
}
AuxArrPais[numPaises]=pais;
numPaises++;
if(_pais!=nullptr)
{
delete _pais;
}
_pais=AuxArrPais;
}

return true;
}
bool ArrPaises::Eliminar_Pais()
{

return true;
}
int ArrPaises::Retornar_NumPaises()
{
return numPaises;
}

Pais** ArrPaises::Crear_Arreglo(){
return new Pais*[numPaises+1];
}

Pais* ArrPaises::Retorna_dato_en_arreglo(int indice){


return _pais[indice];
}
MyForm.h
#pragma once

namespace POO1 {
#include "ArrPersonas.h"; //Un arreglo de Objetos Persona
#include "Persona.h"; //UN SOLO OBJETO PERSONA
#include "Pais.h";
#include "ArrPaises.h";

#include <stdio.h>;
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;

/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
objeto_ArrPersona=new ArrPersonas();
obj_ArrPaises= new ArrPaises();
}
protected:
~MyForm()
{
if (components)
{
delete components;
}
delete objeto_ArrPersona;
delete obj_ArrPaises;
}
private:
/// <summary>
/// Required designer variable.
/// </summary>

ArrPersonas *objeto_ArrPersona;
ArrPaises *obj_ArrPaises;
Persona *objeto_Persona;
Pais *obj_Pais;

private: System::Windows::Forms::Button^ btnCrear;

private: System::Windows::Forms::Label^ lblNombre;


private: System::Windows::Forms::Label^ lblEdad;
private: System::Windows::Forms::ListBox^ lstPais;

private: System::Windows::Forms::TextBox^ txtNombre;


private: System::Windows::Forms::TextBox^ txtPob;

private: System::Windows::Forms::Label^ lblPersonas;


private: System::Windows::Forms::GroupBox^ GBMayores25;

private: System::Windows::Forms::Button^ btnFiltrarMayores25;


private: System::Windows::Forms::ListBox^ lstMayorPoblacion;

private: System::Windows::Forms::GroupBox^ GBInicianConA;

private: System::Windows::Forms::Button^ btnFitrarInicianConA;


private: System::Windows::Forms::ListBox^ lstMenorPoblacion;

private: System::Windows::Forms::Button^ btnEliminar;


private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::TextBox^ txtContinente;

System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code


/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->btnCrear = (gcnew System::Windows::Forms::Button());
this->lblNombre = (gcnew System::Windows::Forms::Label());
this->lblEdad = (gcnew System::Windows::Forms::Label());
this->lstPais = (gcnew System::Windows::Forms::ListBox());
this->txtNombre = (gcnew System::Windows::Forms::TextBox());
this->txtPob = (gcnew System::Windows::Forms::TextBox());
this->lblPersonas = (gcnew System::Windows::Forms::Label());
this->GBMayores25 = (gcnew
System::Windows::Forms::GroupBox());
this->btnFiltrarMayores25 = (gcnew
System::Windows::Forms::Button());
this->lstMayorPoblacion = (gcnew
System::Windows::Forms::ListBox());
this->GBInicianConA = (gcnew
System::Windows::Forms::GroupBox());
this->btnFitrarInicianConA = (gcnew
System::Windows::Forms::Button());
this->lstMenorPoblacion = (gcnew
System::Windows::Forms::ListBox());
this->btnEliminar = (gcnew System::Windows::Forms::Button());
this->label1 = (gcnew System::Windows::Forms::Label());
this->txtContinente = (gcnew
System::Windows::Forms::TextBox());
this->GBMayores25->SuspendLayout();
this->GBInicianConA->SuspendLayout();
this->SuspendLayout();
//
// btnCrear
//
this->btnCrear->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->btnCrear->Location = System::Drawing::Point(37, 113);
this->btnCrear->Name = L"btnCrear";
this->btnCrear->Size = System::Drawing::Size(61, 30);
this->btnCrear->TabIndex = 0;
this->btnCrear->Text = L"Crear";
this->btnCrear->UseVisualStyleBackColor = true;
this->btnCrear->Click += gcnew System::EventHandler(this,
&MyForm::btnCrear_Click);
//
// lblNombre
//
this->lblNombre->AutoSize = true;
this->lblNombre->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->lblNombre->Location = System::Drawing::Point(5, 15);
this->lblNombre->Name = L"lblNombre";
this->lblNombre->Size = System::Drawing::Size(65, 20);
this->lblNombre->TabIndex = 1;
this->lblNombre->Text = L"Nombre";
//
// lblEdad
//
this->lblEdad->AutoSize = true;
this->lblEdad->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->lblEdad->Location = System::Drawing::Point(5, 52);
this->lblEdad->Name = L"lblEdad";
this->lblEdad->Size = System::Drawing::Size(78, 20);
this->lblEdad->TabIndex = 2;
this->lblEdad->Text = L"Poblacion";
//
// lstPais
//
this->lstPais->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->lstPais->FormattingEnabled = true;
this->lstPais->ItemHeight = 20;
this->lstPais->Location = System::Drawing::Point(12, 169);
this->lstPais->Name = L"lstPais";
this->lstPais->Size = System::Drawing::Size(214, 244);
this->lstPais->TabIndex = 3;
this->lstPais->SelectedIndexChanged += gcnew
System::EventHandler(this, &MyForm::lstPersonas_SelectedIndexChanged);
//
// txtNombre
//
this->txtNombre->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->txtNombre->Location = System::Drawing::Point(109, 14);
this->txtNombre->MaxLength = 99;
this->txtNombre->Name = L"txtNombre";
this->txtNombre->Size = System::Drawing::Size(117, 26);
this->txtNombre->TabIndex = 4;
//
// txtPob
//
this->txtPob->Font = (gcnew System::Drawing::Font(L"Microsoft
Sans Serif", 12, System::Drawing::FontStyle::Regular,
System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->txtPob->Location = System::Drawing::Point(109, 46);
this->txtPob->MaxLength = 2;
this->txtPob->Name = L"txtPob";
this->txtPob->Size = System::Drawing::Size(44, 26);
this->txtPob->TabIndex = 5;
//
// lblPersonas
//
this->lblPersonas->AutoSize = true;
this->lblPersonas->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->lblPersonas->Location = System::Drawing::Point(8, 146);
this->lblPersonas->Name = L"lblPersonas";
this->lblPersonas->Size = System::Drawing::Size(128, 20);
this->lblPersonas->TabIndex = 6;
this->lblPersonas->Text = L"Todas los Paises";
//
// GBMayores25
//
this->GBMayores25->Controls->Add(this->btnFiltrarMayores25);
this->GBMayores25->Controls->Add(this->lstMayorPoblacion);
this->GBMayores25->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->GBMayores25->Location = System::Drawing::Point(232,
13);
this->GBMayores25->Name = L"GBMayores25";
this->GBMayores25->Size = System::Drawing::Size(229, 400);
this->GBMayores25->TabIndex = 7;
this->GBMayores25->TabStop = false;
this->GBMayores25->Text = L"Mayor Poblacion";
//
// btnFiltrarMayores25
//
this->btnFiltrarMayores25->Location =
System::Drawing::Point(15, 357);
this->btnFiltrarMayores25->Name = L"btnFiltrarMayores25";
this->btnFiltrarMayores25->Size = System::Drawing::Size(208,
37);
this->btnFiltrarMayores25->TabIndex = 1;
this->btnFiltrarMayores25->Text = L"Filtrar";
this->btnFiltrarMayores25->UseVisualStyleBackColor = true;
this->btnFiltrarMayores25->Click += gcnew
System::EventHandler(this, &MyForm::btnFiltrarMayores25_Click);
//
// lstMayorPoblacion
//
this->lstMayorPoblacion->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->lstMayorPoblacion->FormattingEnabled = true;
this->lstMayorPoblacion->ItemHeight = 20;
this->lstMayorPoblacion->Location =
System::Drawing::Point(15, 27);
this->lstMayorPoblacion->Name = L"lstMayorPoblacion";
this->lstMayorPoblacion->Size = System::Drawing::Size(208,
324);
this->lstMayorPoblacion->TabIndex = 0;
//
// GBInicianConA
//
this->GBInicianConA->Controls->Add(this-
>btnFitrarInicianConA);
this->GBInicianConA->Controls->Add(this->lstMenorPoblacion);
this->GBInicianConA->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->GBInicianConA->Location = System::Drawing::Point(467,
13);
this->GBInicianConA->Name = L"GBInicianConA";
this->GBInicianConA->Size = System::Drawing::Size(229, 400);
this->GBInicianConA->TabIndex = 8;
this->GBInicianConA->TabStop = false;
this->GBInicianConA->Text = L"Menor Poblacion";
//
// btnFitrarInicianConA
//
this->btnFitrarInicianConA->Location =
System::Drawing::Point(9, 357);
this->btnFitrarInicianConA->Name = L"btnFitrarInicianConA";
this->btnFitrarInicianConA->Size = System::Drawing::Size(214,
37);
this->btnFitrarInicianConA->TabIndex = 1;
this->btnFitrarInicianConA->Text = L"Filtrar";
this->btnFitrarInicianConA->UseVisualStyleBackColor = true;
this->btnFitrarInicianConA->Click += gcnew
System::EventHandler(this, &MyForm::btnFitrarInicianConA_Click);
//
// lstMenorPoblacion
//
this->lstMenorPoblacion->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->lstMenorPoblacion->FormattingEnabled = true;
this->lstMenorPoblacion->ItemHeight = 20;
this->lstMenorPoblacion->Location = System::Drawing::Point(6,
25);
this->lstMenorPoblacion->Name = L"lstMenorPoblacion";
this->lstMenorPoblacion->Size = System::Drawing::Size(217,
324);
this->lstMenorPoblacion->TabIndex = 0;
//
// btnEliminar
//
this->btnEliminar->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->btnEliminar->Location = System::Drawing::Point(123,
113);
this->btnEliminar->Name = L"btnEliminar";
this->btnEliminar->Size = System::Drawing::Size(75, 30);
this->btnEliminar->TabIndex = 9;
this->btnEliminar->Text = L"Eliminar";
this->btnEliminar->UseVisualStyleBackColor = true;
this->btnEliminar->Click += gcnew System::EventHandler(this,
&MyForm::btnEliminar_Click);
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft
Sans Serif", 12, System::Drawing::FontStyle::Regular,
System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->Location = System::Drawing::Point(5, 87);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(87, 20);
this->label1->TabIndex = 10;
this->label1->Text = L"Continente";
//
// txtContinente
//
this->txtContinente->Font = (gcnew
System::Drawing::Font(L"Microsoft Sans Serif", 12,
System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->txtContinente->Location = System::Drawing::Point(109,
81);
this->txtContinente->MaxLength = 99;
this->txtContinente->Name = L"txtContinente";
this->txtContinente->Size = System::Drawing::Size(117, 26);
this->txtContinente->TabIndex = 11;
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode =
System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(699, 424);
this->Controls->Add(this->txtContinente);
this->Controls->Add(this->label1);
this->Controls->Add(this->btnEliminar);
this->Controls->Add(this->GBInicianConA);
this->Controls->Add(this->GBMayores25);
this->Controls->Add(this->lblPersonas);
this->Controls->Add(this->txtPob);
this->Controls->Add(this->txtNombre);
this->Controls->Add(this->lstPais);
this->Controls->Add(this->lblEdad);
this->Controls->Add(this->lblNombre);
this->Controls->Add(this->btnCrear);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->GBMayores25->ResumeLayout(false);
this->GBInicianConA->ResumeLayout(false);
this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
void Insertar_Datos_Persona_en_ListBox()
{ lstPais->Items->Clear();
if (obj_ArrPaises->Retornar_NumPaises()>0)
{ for (int i=0;i<obj_ArrPaises->Retornar_NumPaises();i++)
{ obj_Pais= obj_ArrPaises-
>Retorna_dato_en_arreglo(i);
//Convertimos de char* a String^
System::String ^nombre="Nombre : " +gcnew
System::String(obj_Pais->get_Nombre()) +
" Poblacion : " + obj_Pais-
>get_Poblacion().ToString() + "Continente : " +gcnew System::String(obj_Pais-
>get_Continente()) ;
lstPais->Items->Add(nombre);
}
}
}
private: System::Void btnCrear_Click(System::Object^ sender,
System::EventArgs^ e) {
if (txtNombre->Text->Length>0 && txtPob->Text-
>Length>0)
{ obj_Pais= new Pais();
int mipob=Convert::ToInt32(txtPob->Text);

obj_Pais->set_Poblacion(mipob);

char*minombre, *nomcont;

minombre=new char[100];
nomcont=new char[100];
sprintf(minombre,"%s",txtNombre-
>Text);//Convierte de St ring^ a char*
obj_Pais->set_Nombre(minombre);
sprintf(nomcont,"%s",txtContinente-
>Text);//Convierte de St ring^ a char*
obj_Pais->set_Continente(nomcont);
obj_ArrPaises->Insertar_Pais(obj_Pais);
txtNombre->Clear();
txtPob->Clear();
txtContinente->Clear();
}
else
obj_Pais= NULL;

Insertar_Datos_Persona_en_ListBox();
}
private: System::Void btnEliminar_Click(System::Object^ sender,
System::EventArgs^ e) {

if (lstPais->SelectedIndex!=-1)
{
objeto_ArrPersona->Eliminar(lstPais->SelectedIndex);
lstPais->SelectedIndex=-1;
Insertar_Datos_Persona_en_ListBox();
txtNombre->Clear();
txtPob->Clear();
txtContinente->Clear();
}
}
private: System::Void lstPersonas_SelectedIndexChanged(System::Object^ sender,
System::EventArgs^ e) {

if (lstPais->SelectedIndex!=-1)
{
obj_Pais=obj_ArrPaises-
>Retorna_dato_en_arreglo(lstPais->SelectedIndex);
txtNombre->Text= gcnew System::String(obj_Pais-
>get_Nombre());
txtContinente->Text= gcnew System::String(obj_Pais-
>get_Continente());
txtPob->Text= obj_Pais->get_Poblacion().ToString();

}
private: System::Void btnFiltrarMayores25_Click(System::Object^ sender,
System::EventArgs^ e) {

//int *cantidad;
// cantidad=new int;
// *cantidad=0;
// Persona** arr_masde25 = objeto_ArrPersona-
>Mayores25anios(cantidad);
// lstMayorPoblacion->Items->Clear();
// if (arr_masde25 !=NULL)
// {
// for (int i=0;i<*cantidad;i++)
// {
// System::String ^persona= "Nombre: " +gcnew
System::String(arr_masde25[i]->Retornar_Nombre());
// lstMayores25->Items->Add(persona);
// }
// }

}
private: System::Void btnFitrarInicianConA_Click(System::Object^ sender,
System::EventArgs^ e) {
/* int *cantidad;
cantidad=new int;
*cantidad=0;
Persona** arr_comienzanConA = objeto_ArrPersona-
>ConLetraAenelNombre(cantidad);
lstInicianConA->Items->Clear();
if (arr_comienzanConA !=NULL)
{
for (int i=0;i<*cantidad;i++)
{
System::String ^nombre= "Nombre: " +gcnew
System::String(arr_comienzanConA[i]->Retornar_Nombre());
lstInicianConA->Items->Add(nombre);
}
}*/

};
}
MyForm.cpp
#include "MyForm.h"
using namespace System;
using namespace System ::Windows::Forms;
[STAThread]
void main(array<String^>^ arg)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run( gcnew POO1::MyForm());
}