Beruflich Dokumente
Kultur Dokumente
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);
ArrPaises::ArrPaises(void)
{
numPaises=0;
_pais= nullptr; //arreglo de paises
}
ArrPaises::~ArrPaises(void)
{
for (int i = 0; i < numPaises; i++)
{
delete _pais[i];
}
return true;
}
bool ArrPaises::Eliminar_Pais()
{
return true;
}
int ArrPaises::Retornar_NumPaises()
{
return numPaises;
}
Pais** ArrPaises::Crear_Arreglo(){
return new Pais*[numPaises+1];
}
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;
System::ComponentModel::Container ^components;
}
#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());
}