martes, 27 de marzo de 2012

SOMMAIRE du SGBD (systèmes de gestion de bases de données )

Pour donner une définition d'un gestionnaire de base du système doit être claire ce qu'est une base de données, qui peut être défini comme un ensemble de données stockées proprement sous certaines restrictions, qui permettent la saisie des données facile et un accès facile pour eux, les modifier, et de leur élimination dans un fichier. appropriée et facilement Restrictions et la structure d'une base de données sont réalisés à partir du problème à résoudre ou à la situation qui se pose. Pour créer une base de données qui a la structure qui est souhaité et peuvent inclure des restrictions pour résoudre les problèmes besoin d'un logiciel spécialisé pour effectuer cette tâche est alors de créer le SGBD (base de données de gestion des données des systèmes).

 
Le SGBD doit avoir certaines caractéristiques qui sont essentielles pour la gestion d'une base de données, dont certaines sont les suivants:
<-! [Si supportEmptyParas!] -> · <! - [Endif] -> la manipulation des données, ce qui signifie qu'ils peuvent effectuer des actions d'insertion, mise à jour et supprimer des données, ceci en un moyen simple pour l'utilisateur et le programmeur.
<-! [Si supportEmptyParas!] -> · <! - [Endif] -> Panneau de protection des données, c.-à-garder la nourriture saine au cours du stockage et de leurs relations les uns aux autres n'affecte pas la manipulation .
· <- [Endif] -> Sauvegarde et restauration <- - [Si supportEmptyParas!]!>: Il est nécessaire que si elles se produisent des données défauts avant l'heure de l'échec restent intacts et ont la capacité de générer des sauvegardes.
<-! [Si supportEmptyParas!] -> · <! - [Endif] -> Mise en œuvre de l'exhaustivité, quand nous insérer ou mettre à jour les données qu'ils doivent se conformer aux restrictions qui sont prévues pour créer la base de données le contraire serait possible de stocker un ensemble de données dont la longueur ou le type de données qui n'est pas réglé lors de la création de la base de données.
<-! [Si supportEmptyParas!] -> · <! - [Endif] -> Faire-il possible de définir des niveaux d'abstraction d'une base de données (physique, logique et vues).
<-! [Si supportEmptyParas!] -> · <! - [Endif] -> le contrôle de concurrence, il doit être possible pour plusieurs utilisateurs de mettre à jour la base de données en même temps sans perte de données ou organisation.
Initialement, dans les années 40, les systèmes de fichiers générés par les langages de programmation non-propriétaires comme Cobol et Fortran, vous permettent de stocker des données via des fichiers plats avec de base en lecture et en écriture à leur sujet. En 1964, a établi les gestionnaires de bases de données premiers initie ainsi la gestion des données d'une manière similaire à celle pratiquée actuellement.
Après l'apparition de langages de programmation orientée objet SGBD spécialiser davantage et de créer des bases de données Systems Management relationnelle (SGBDR) et Documentaires systèmes de base de données de gestion (SGBDD) pour répondre à cette la nouvelle façon de structurer les langues de programmation de données stockées et orientées objet.
Des exemples de SGBD sont Oracle, SQL Server, Sybase, DB2, MySQL, PostgreSQL, SQLite et beaucoup plus. Qui peut supporter de grandes quantités de données ou de petite et de s'adapter aux besoins des utilisateurs, tel n'est pas le même SGBD sur un appareil mobile qui exige une société pour gérer leurs informations.
Actuellement, toujours apparaître à la fois commercial et libre SGBD.
La structure de base d'un gestionnaire de base du système nécessite deux langues qui vous permettent de travailler sur la base de données. Ces langues standard sont:
· <- [Endif] -> DDL (Data Definition Language) <- - [Si supportEmptyParas!]!>: Data Definition Language. Grâce à ce SGBD identifie les descriptions des éléments de schémas et la description du schéma stockés dans le catalogue de SGBD.Grâce à ce SGBD spécifie le schéma conceptuel et interne (base de données stockée).
 
SDL (langage de définition de magasin): langage de définition de stockage. Est utilisé par le SGBD pour spécifier le schéma interne qui correspond à la base de données stockée.VDL (View Definition Language): langage de définition de vue. Il est utilisé par le SGBD pour spécifier des vues des utilisateurs et de leurs correspondances avec le schéma conceptuel.


Bibliographie.
Luque Ruiz Irene, Gómez Nieto Miguel Ángel, López Espinoza, Cerruela García Gonzalo (2002). Bases de Datos desde Chen hasta Codd con Oracle: Alfaomega Ra-Ma.
f. Korth Henry, Silverschatz Abraham (1995). Fundamentos de Bases de Datos (segunda edición): McGraw Hill

viernes, 23 de marzo de 2012

Postgresql


¿Qué es PostGreSQL?
Es un sistema de gestión de bases de datos objeto-relacional (ORDBMS) basado en el proyecto POSTGRES. Ya que es una derivación libre (OpenSource) de este proyecto, y utiliza el lenguaje SQL92/SQL99
Un poco de historia
*        Se inicia en la Universidad de Berkeley en 1977 bajo el nombre Ingres como un ejercicio de aplicación de las teorías de las RDBMS.
*         1986, cambia su nombre a Postgres con el objetivo de aplicar los conceptos de Objetos Relacionales.
*         1995, cambia su nombre a Postgres95 que luego derivaría a PostgreSQL
*         1996, el proyecto se integra al mundo del Open Source inicia en la versión 6.0
*         2004, PostgreSQL 8.0, adopción en el mundo comercial, se le califico como la 5ta DBMS mas popular en USA.
*         2005 Julio, PostgreSQL paso el test de Coverty Inspected encontrando solo 20 errores en 775,000 lineas de código.
*        Actuamente version 9.1
PostGreSQL y la orientación a objetos
El argumento a favor de las bases de datos objeto-relacionales sostiene que permite realizar una migración gradual de sistemas relacionales a los orientados y, en algunas circunstancias, coexistir ambos tipos de aplicaciones durante algún tiempo.
Características
*        Soporta distintos tipos de datos:
Ø  tipos base, fecha, monetarios, elementos gráficos, datos sobre redes (MAC, IP ...), cadenas de bits, etc.  También permite la creación de tipos propios.
*        Incorpora una estructura de datos array.
*        Soporte nativo para los lenguajes mas populares del medio : PHP, C, C++, Perl, Python, etc.
*        Incorpora funciones de diversa índole:
Ø  manejo de fechas, geométricas, orientadas a operaciones con redes, etc.
*        Permite la declaración de funciones propias, así como la definición de disparadores.
*        Soporta el uso de índices, reglas y vistas.
*        Incluye herencia entre tablas (aunque no entre objetos, ya que no existen), por lo que a este gestor de bases de datos se le incluye entre los gestores objeto-relacionales.
*        Permite la gestión de diferentes usuarios, como también los permisos asignados a cada uno de ellos.
*        PostGreSQL puede funcionar en múltiples plataformas (en general, en todas las modernas basadas en Unix) Linux, BSDs, Mac OS, Beos, Windows, etc.
*        Se distribuye bajo licencia BSD, lo que permite su uso, redistribución, modificación con la única restricción de mantener el copyright del software a sus autores, en concreto el PostGreSQL Global Development Group y la Universidad de California.
Sentencia insert, update y delete

Insert

INSERT INTO table_name (name_of_attr_1
[, name_of_attr_2 [,...]])
VALUES (val_attr_1
[, val_attr_2 [, ...]]);
Ejemplo:
INSERT INTO "Venta"("ID_Cliente", "ID_Producto", "Cantidad", "Total", "Fecha") VALUES ( 1,1 ,2 ,30 ,'15/03/2012');

Update

UPDATE table_name
SET name_of_attr_1 = value_1
[, ... [, name_of_attr_k = value_k]]
WHERE condition;
Ejemplo:
UPDATE “Producto“ SET “Costo_Unitario”=10 WHERE "ID_Producto " = 3 ;


Delete

DELETE FROM table_name
WHERE condition;
Ejemplo:
DELETE FROM “Producto“ WHERE "ID_Producto " = 3 ;
Select

El comando más usado en SQL es la instrucción SELECT, que se utiliza para recuperar datos. La sintaxis es:
SELECT [ALL|DISTINCT]
{ * | expr_1 [AS c_alias_1] [, ...
[, expr_k [AS c_alias_k]]]}
FROM table_name_1 [t_alias_1]
[, ... [, table_name_n [t_alias_n]]]
[WHERE condition]
[GROUP BY name_of_attr_i
[,... [, name_of_attr_j]] [HAVING condition]]
[{UNION [ALL] | INTERSECT | EXCEPT} SELECT ...]
[ORDER BY name_of_attr_i [ASC|DESC]
[, ... [, name_of_attr_j [ASC|DESC]]]];


Ejemplos:
SELECT *FROM "Producto";
SELECT "Descripcion" FROM "Producto" WHERE "Precio_Unitario" >'10';




Subconsulta

Ejemplo:
SELECT "Nombre“ AS  "NOMBRE DEL CLIENTE" FROM "Cliente" WHERE "ID_Cliente"=(SELECT "ID_Cliente" FROM "Venta" WHERE "ID_Venta"=1);

 


Funciones
La figura de PROCEDURE(store procedure, procedimiento almacenado) no existe como en ORACLE o SQL SERVER. En su defecto PostgreSQL tiene FUNCTION, estas funciones pueden o no devolver un valor, eso dependerá de lo que necesites hacer, bien pueden no devolver nada, simplemente ejecutan una acción, o pueden devolver hasta una tabla como resultado de algún proceso, eso el programador lo define.
La función tiene tres partes:
q  El encabezado que define el nombre de la función y el tipo de retorno.
q  El cuerpo de la función.
La especificación del lenguaje utilizado.

Sintaxis:

CREATE FUNCTION [nombre de la función] ([parámetros separados por comas]) RETURNS [el tipo de dato que regresa] AS
'DECLARE aquí se definen las variables que se usarán.
BEGIN indica el inicio de la función.
Cuerpo de la función.
RETURN Sale de la función y regresa el tipo de dato que se declaro después de la palabra RETURNS del CREATE FUNCTION
END indica el fin de la función
 LANGUAGE indica con que lenguaje esta escrita la función, puede ser un lenguaje de procedimiento (plpgsql) o de consulta (SQL).


Ejemplo:

Crearemos a tabla Venta sobre la cual crearemos una función para insertar sus campos Total y Fecha.


CREATE TABLE "Venta"
(
  "ID_Venta" serial NOT NULL PRIMARY KEY ,
  "ID_Cliente" integer NOT NULL ,
  "ID_Producto" integer NOT NULL  ,
  "Cantidad" integer NOT NULL,
  "Total" money NOT NULL,
  "Fecha" date NOT NULL,
  FOREIGN KEY ("ID_Cliente") REFERENCES  "Cliente" ("ID_Cliente"),
  FOREIGN KEY ("ID_Producto")REFERENCES "Producto" ("ID_Producto")
  );

Función que calculará los campos Total y Fecha para enseguida insertarlos en la tabla Venta:

CREATE OR REPLACE FUNCTION inserta_venta(ID_Cliente integer, ID_Producto integer, Cantidad integer)  RETURNS void AS   $$
declare Total money;
begin
 Total:=(select "Precio_Unitario" from "Producto"
where "ID_Producto"=ID_Cliente)*Cantidad;
INSERT INTO "Venta"("ID_Cliente", "ID_Producto", "Cantidad", "Total","Fecha")
VALUES ( ID_Cliente,ID_Producto ,Cantidad ,Total,NOW());
end
$$ language plpgsql;

Ejecución de la función inserta_venta:

select inserta_venta(1,1,2);





Desencadenador(trigger)


sintaxis

CREATE TRIGGER nombre { BEFORE | AFTER } { INSERT | UPDATE | DELETE [ OR ... ] } ON tabla [ FOR [ EACH ] { ROW | STATEMENT } ] EXECUTE PROCEDURE nombre de función ( argumentos )

Ejemplo de función y desencadenador:

Creamos la tabla números, con la cual se probará el desencadenador:

CREATE TABLE numeros(
numero bigint NOT NULL,
cuadrado bigint,
cubo bigint,
raiz2 real,
raiz3 real,
PRIMARY KEY (numero)
);

La siguiente function calculará los campos cuadrado, cubo, raiz2 y raiz3 a partir de una inserción o actualización en el campo numero:

CREATE OR REPLACE FUNCTION rellenar_datos() RETURNS TRIGGER AS $$
BEGIN
NEW.cuadrado := power(NEW.numero,2);
NEW.cubo := power(NEW.numero,3);
NEW.raiz2 := sqrt(NEW.numero);
NEW.raiz3 := cbrt(NEW.numero);
RETURN NEW;
END
$$ language plpgsql;

El siguiente Desencadenador ejecutará la function rellenar_datos antes de insertar o actualizar la tabla numeros:

CREATE TRIGGER rellenar_datos BEFORE INSERT OR UPDATE ON numeros FOR EACH ROW EXECUTE PROCEDURE rellenar_datos();

A continuación se realiza una inserción para probar el desencadenador:

INSERT INTO  numeros(numero) VALUES (8);


 

sábado, 3 de diciembre de 2011

Calculadora con programación híbrida: Visual C++ y ensamblador


#pragma once

namespace calculator {

       using namespace System;
       using namespace System::ComponentModel;
       using namespace System::Collections;
       using namespace System::Windows::Forms;
       using namespace System::Data;
       using namespace System::Drawing;

       //método operacion para sumar, restar y multiplicar.
       //Recibe ca (cantidad a), cb (cantidad b) y nop (numero de operación)
       int operacion(int ca,int cb,int nop)
                     {
                            //variable para almacenar el resultado
                            int resultado=0;
                            // si nop (numro de operacion es igual a 1 realizara la suma
                            if(nop==1)
                            {
                                   //inicio de bloque de código en ensamblador
                         _asm{
                                  //transfiere al registro ax extendido ca (cantidad a)
                                  mov eax,ca
                                  //suma al registro ax extendido cb (cantidad b)
                                  add eax,cb
                                  //transfiere a resultado el valor del registro ax extendido
                                        mov resultado,eax
                                   }
                            //fin de bloque de código en ensamblador
                            //retorna resultado
                             return resultado;
                           }
                            // si nop número de operación es iguala 2 realizará la resta
                            else if(nop==2)
                            {
                                   //inicio de bloque de código en ensamblador
                         _asm{
                                  //transfiere al registro ax extendido ca (cantidad a)
                                  mov eax,ca
                                  //resta al registro ax extendido cb (cantidad b)
                                  sub eax,cb
                                  //transfiere a resultado el valor del registro ax extendido
                                  mov resultado,eax
                                   }
                            //fin de bloque de código en ensamblador
                            //retorna resultado
                             return resultado;
                            }
                            // si nop (número de operación) es igual a 3 tres realizará la multiplicación
                           else if(nop==3)
                            {
                                   //inicia bloque de código ensamblador
                           _asm{
                                  //agrega a la pila el registro ax extendido
                                  push eax
                               //agrega a la pila el registro cx extendido
                                  push ecx
                                  //transfiere al registro cx extendido ca (cantidad a)
                                  mov ecx,ca
                                  //transfiere al registro ax extendido 0h
                                  mov eax,0h
                                  //transfiere al registro ax extendido cb (cantidad b)
                                  mov eax,cb
                                  //multiplica el registro cx extendido por el registro
                                  //ax entendido y almacena el resultado en el registro
                                  //ax extendido
                                  mul ecx
                                  //transfiere a resultado el registro ax extendido    
                                  mov resultado,eax
                                  //extrae de la pila el registro cx extendido
                                  pop ecx
                                  //extrae de la pila el registro ex extendido
                                  pop eax
                           }
                           //fin de bloque de código en ensamblador
                           //retorna resultado
                           return resultado;
                           }
                            //si nop(número de operación es 4 entonces
                            //realizará la división
                    else if(nop==4)
                            {
                                   //se declaran dos variables de tipo entero
                                   //llamadas n1 y n2
                                  int n1=0,n2=0;
                                  //inicia bloque de codigo ensamblador donde realizará
                                  //solo transferencias entre los registros pues la operación
                                  //div de ensamblador produce resultados que no pudimos convertir a
                                  //los resultados correctos de la división
                           _asm{
                                  //transferimos a los registros ax y dx extendidos el valor de 0000h
                                  mov eax,0000h
                                  mov edx,0000h
                                  //transferimos al registro dx extendido ca(cantidad a)
                                  mov edx,ca
                                  //transferimos al registro ax extendido cb(cantidad b)
                                  mov eax,cb
                                  //transferimos a la variable n1 el valor del  registro dx extendido
                                  mov n1,edx
                                  //transferimos a la variable n2 el valor del  registro ax extendido
                                  mov n2,eax
                           }
                           //fin del bloque de código en ensamblador
                           //resultado es igual a n1 dividido entre n2
                           resultado=n1/n2;
                           //retornamos el valor de resultado
                           return resultado;
                           }

       }

      
       /// <summary>
       /// Resumen de Form1
       /// </summary>
       public ref class Form1 : public System::Windows::Forms::Form
       {
       public:
       //declaramos variables globales de tipo entero
             //cant1(cantidad1),cant2(cantidad2),salida(resultado de la operación),
             //numcant(número de cantidad),numoper(número de operación)
             int cant1,cant2,salida,numcant,numoper;
//declaramos variables globales de tipo String
             // a(cantidad a), b(cantidad b),operador(para indicar la operación)
             String ^ a;
             String ^ b;
             String ^ operador;
             String ^ igual;
      
                     
             Form1(void)
             {
                    InitializeComponent();
                    //
                    //TODO: agregar código de constructor aquí
                    //
                    //inicialización de la variables globales
              cant1=0;
              cant2=0;
              salida=0;
              numcant=0;
              numoper=0;
              a = "";
              b = "";
              operador="";
              igual="=";
             }

       protected:
             /// <summary>
             /// Limpiar los recursos que se estén utilizando.
             /// </summary>
             ~Form1()
             {
                    if (components)
                    {
                           delete components;
                    }
             }
       private: System::Windows::Forms::Button^  btnclear;
       protected:
       private: System::Windows::Forms::TextBox^  txtdatos;
       private: System::Windows::Forms::Button^  btnigual;
       private: System::Windows::Forms::Button^  btndiv;
       private: System::Windows::Forms::Button^  btnres;
       private: System::Windows::Forms::Button^  btnsum;
       private: System::Windows::Forms::Button^  btnmul;
       private: System::Windows::Forms::Button^  btn1;
       private: System::Windows::Forms::Button^  btn3;
       private: System::Windows::Forms::Button^  btn4;
       private: System::Windows::Forms::Button^  btn7;
       private: System::Windows::Forms::Button^  btn5;
       private: System::Windows::Forms::Button^  btn8;
       private: System::Windows::Forms::Button^  btn9;
       private: System::Windows::Forms::Button^  btn6;
       private: System::Windows::Forms::Button^  btn0;
       private: System::Windows::Forms::Button^  btn2;
       private: System::Windows::Forms::GroupBox^  groupBox1;
       //public:
       private: System::Windows::Forms::GroupBox^  groupBox2;
       private:
             /// <summary>
             /// Variable del diseñador requerida.
             /// </summary>
             System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
             /// <summary>
             /// Método necesario para admitir el Diseñador. No se puede modificar
             /// el contenido del método con el editor de código.
             /// </summary>
             void InitializeComponent(void)
             {
                    this->btnclear = (gcnew System::Windows::Forms::Button());
                    this->txtdatos = (gcnew System::Windows::Forms::TextBox());
                    this->btnigual = (gcnew System::Windows::Forms::Button());
                    this->btndiv = (gcnew System::Windows::Forms::Button());
                    this->btnres = (gcnew System::Windows::Forms::Button());
                    this->btnsum = (gcnew System::Windows::Forms::Button());
                    this->btnmul = (gcnew System::Windows::Forms::Button());
                    this->btn1 = (gcnew System::Windows::Forms::Button());
                    this->btn3 = (gcnew System::Windows::Forms::Button());
                    this->btn4 = (gcnew System::Windows::Forms::Button());
                    this->btn7 = (gcnew System::Windows::Forms::Button());
                    this->btn5 = (gcnew System::Windows::Forms::Button());
                    this->btn8 = (gcnew System::Windows::Forms::Button());
                    this->btn9 = (gcnew System::Windows::Forms::Button());
                    this->btn6 = (gcnew System::Windows::Forms::Button());
                    this->btn0 = (gcnew System::Windows::Forms::Button());
                    this->btn2 = (gcnew System::Windows::Forms::Button());
                    this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
                    this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
                    this->groupBox1->SuspendLayout();
                    this->groupBox2->SuspendLayout();
                    this->SuspendLayout();
                    //
                    // btnclear
                    //
                    this->btnclear->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btnclear->Location = System::Drawing::Point(47, 155);
                    this->btnclear->Name = L"btnclear";
                    this->btnclear->Size = System::Drawing::Size(37, 37);
                    this->btnclear->TabIndex = 34;
                    this->btnclear->Text = L"C";
                    this->btnclear->UseVisualStyleBackColor = true;
                    this->btnclear->Click += gcnew System::EventHandler(this, &Form1::btnclear_Click);
                    //
                    // txtdatos
                    //
                    this->txtdatos->Location = System::Drawing::Point(18, 15);
                    this->txtdatos->Name = L"txtdatos";
                    this->txtdatos->Size = System::Drawing::Size(262, 20);
                    this->txtdatos->TabIndex = 33;
                    this->txtdatos->TextAlign = System::Windows::Forms::HorizontalAlignment::Right;
                    //
                    // btnigual
                    //
                    this->btnigual->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btnigual->Location = System::Drawing::Point(47, 69);
                    this->btnigual->Name = L"btnigual";
                    this->btnigual->Size = System::Drawing::Size(37, 37);
                    this->btnigual->TabIndex = 32;
                    this->btnigual->Text = L"=";
                    this->btnigual->UseVisualStyleBackColor = true;
                    this->btnigual->Click += gcnew System::EventHandler(this, &Form1::btnigual_Click);
                    //
                    // btndiv
                    //
                    this->btndiv->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btndiv->Location = System::Drawing::Point(90, 69);
                    this->btndiv->Name = L"btndiv";
                    this->btndiv->Size = System::Drawing::Size(37, 37);
                    this->btndiv->TabIndex = 31;
                    this->btndiv->Text = L"/";
                    this->btndiv->UseVisualStyleBackColor = true;
                    this->btndiv->Click += gcnew System::EventHandler(this, &Form1::btndiv_Click);
                    //
                    // btnres
                    //
                    this->btnres->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btnres->Location = System::Drawing::Point(47, 112);
                    this->btnres->Name = L"btnres";
                    this->btnres->Size = System::Drawing::Size(37, 37);
                    this->btnres->TabIndex = 30;
                    this->btnres->Text = L"-";
                    this->btnres->UseVisualStyleBackColor = true;
                    this->btnres->Click += gcnew System::EventHandler(this, &Form1::btnres_Click);
                    //
                    // btnsum
                    //
                    this->btnsum->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btnsum->Location = System::Drawing::Point(47, 26);
                    this->btnsum->Name = L"btnsum";
                    this->btnsum->Size = System::Drawing::Size(37, 37);
                    this->btnsum->TabIndex = 29;
                    this->btnsum->Text = L"+";
                    this->btnsum->UseVisualStyleBackColor = true;
                    this->btnsum->Click += gcnew System::EventHandler(this, &Form1::btnsum_Click);
                    //
                    // btnmul
                    //
                    this->btnmul->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btnmul->Location = System::Drawing::Point(4, 69);
                    this->btnmul->Name = L"btnmul";
                    this->btnmul->Size = System::Drawing::Size(37, 37);
                    this->btnmul->TabIndex = 28;
                    this->btnmul->Text = L"X";
                    this->btnmul->UseVisualStyleBackColor = true;
                    this->btnmul->Click += gcnew System::EventHandler(this, &Form1::btnmul_Click);
                    //
                    // btn1
                    //
                    this->btn1->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btn1->Location = System::Drawing::Point(6, 112);
                    this->btn1->Name = L"btn1";
                    this->btn1->Size = System::Drawing::Size(37, 37);
                    this->btn1->TabIndex = 27;
                    this->btn1->Text = L"1";
                    this->btn1->UseVisualStyleBackColor = true;
                    this->btn1->Click += gcnew System::EventHandler(this, &Form1::btn1_Click);
                    //
                    // btn3
                    //
                    this->btn3->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btn3->Location = System::Drawing::Point(92, 112);
                    this->btn3->Name = L"btn3";
                    this->btn3->Size = System::Drawing::Size(37, 37);
                    this->btn3->TabIndex = 26;
                    this->btn3->Text = L"3";
                    this->btn3->UseVisualStyleBackColor = true;
                    this->btn3->Click += gcnew System::EventHandler(this, &Form1::btn3_Click);
                    //
                    // btn4
                    //
                    this->btn4->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btn4->Location = System::Drawing::Point(6, 69);
                    this->btn4->Name = L"btn4";
                    this->btn4->Size = System::Drawing::Size(37, 37);
                    this->btn4->TabIndex = 25;
                    this->btn4->Text = L"4";
                    this->btn4->UseVisualStyleBackColor = true;
                    this->btn4->Click += gcnew System::EventHandler(this, &Form1::btn4_Click);
                    //
                    // btn7
                    //
                    this->btn7->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btn7->Location = System::Drawing::Point(6, 26);
                    this->btn7->Name = L"btn7";
                    this->btn7->Size = System::Drawing::Size(37, 37);
                    this->btn7->TabIndex = 24;
                    this->btn7->Text = L"7";
                    this->btn7->UseVisualStyleBackColor = true;
                    this->btn7->Click += gcnew System::EventHandler(this, &Form1::btn7_Click);
                    //
                    // btn5
                    //
                    this->btn5->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btn5->Location = System::Drawing::Point(49, 69);
                    this->btn5->Name = L"btn5";
                    this->btn5->Size = System::Drawing::Size(37, 37);
                    this->btn5->TabIndex = 23;
                    this->btn5->Text = L"5";
                    this->btn5->UseVisualStyleBackColor = true;
                    this->btn5->Click += gcnew System::EventHandler(this, &Form1::btn5_Click);
                    //
                    // btn8
                    //
                    this->btn8->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btn8->Location = System::Drawing::Point(49, 26);
                    this->btn8->Name = L"btn8";
                    this->btn8->Size = System::Drawing::Size(37, 37);
                    this->btn8->TabIndex = 22;
                    this->btn8->Text = L"8";
                    this->btn8->UseVisualStyleBackColor = true;
                    this->btn8->Click += gcnew System::EventHandler(this, &Form1::btn8_Click);
                    //
                    // btn9
                    //
                    this->btn9->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btn9->Location = System::Drawing::Point(92, 26);
                    this->btn9->Name = L"btn9";
                    this->btn9->Size = System::Drawing::Size(37, 37);
                    this->btn9->TabIndex = 21;
                    this->btn9->Text = L"9";
                    this->btn9->UseVisualStyleBackColor = true;
                    this->btn9->Click += gcnew System::EventHandler(this, &Form1::btn9_Click);
                    //
                    // btn6
                    //
                    this->btn6->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btn6->Location = System::Drawing::Point(92, 69);
                    this->btn6->Name = L"btn6";
                    this->btn6->Size = System::Drawing::Size(37, 37);
                    this->btn6->TabIndex = 20;
                    this->btn6->Text = L"6";
                    this->btn6->UseVisualStyleBackColor = true;
                    this->btn6->Click += gcnew System::EventHandler(this, &Form1::btn6_Click);
                    //
                    // btn0
                    //
                    this->btn0->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btn0->Location = System::Drawing::Point(49, 155);
                    this->btn0->Name = L"btn0";
                    this->btn0->Size = System::Drawing::Size(37, 37);
                    this->btn0->TabIndex = 19;
                    this->btn0->Text = L"0";
                    this->btn0->UseVisualStyleBackColor = true;
                    this->btn0->Click += gcnew System::EventHandler(this, &Form1::btn0_Click);
                    //
                    // btn2
                    //
                    this->btn2->Font = (gcnew System::Drawing::Font(L"Arial Black", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
                           static_cast<System::Byte>(0)));
                    this->btn2->Location = System::Drawing::Point(49, 112);
                    this->btn2->Name = L"btn2";
                    this->btn2->Size = System::Drawing::Size(37, 37);
                    this->btn2->TabIndex = 18;
                    this->btn2->Text = L"2";
                    this->btn2->UseVisualStyleBackColor = true;
                    this->btn2->Click += gcnew System::EventHandler(this, &Form1::btn2_Click);
                    //
                    // groupBox1
                    //
                    this->groupBox1->BackColor = System::Drawing::Color::Silver;
                    this->groupBox1->Controls->Add(this->btnigual);
                    this->groupBox1->Controls->Add(this->btnclear);
                    this->groupBox1->Controls->Add(this->btnmul);
                    this->groupBox1->Controls->Add(this->btnsum);
                    this->groupBox1->Controls->Add(this->btnres);
                    this->groupBox1->Controls->Add(this->btndiv);
                    this->groupBox1->Location = System::Drawing::Point(153, 50);
                    this->groupBox1->Name = L"groupBox1";
                    this->groupBox1->Size = System::Drawing::Size(134, 197);
                    this->groupBox1->TabIndex = 35;
                    this->groupBox1->TabStop = false;
                    this->groupBox1->Text = L"Operaciones:";
                    //
                    // groupBox2
                    //
                    this->groupBox2->BackColor = System::Drawing::Color::Silver;
                    this->groupBox2->Controls->Add(this->btn5);
                    this->groupBox2->Controls->Add(this->btn2);
                    this->groupBox2->Controls->Add(this->btn0);
                    this->groupBox2->Controls->Add(this->btn1);
                    this->groupBox2->Controls->Add(this->btn6);
                    this->groupBox2->Controls->Add(this->btn3);
                    this->groupBox2->Controls->Add(this->btn9);
                    this->groupBox2->Controls->Add(this->btn4);
                    this->groupBox2->Controls->Add(this->btn8);
                    this->groupBox2->Controls->Add(this->btn7);
                    this->groupBox2->Location = System::Drawing::Point(12, 50);
                    this->groupBox2->Name = L"groupBox2";
                    this->groupBox2->Size = System::Drawing::Size(135, 197);
                    this->groupBox2->TabIndex = 36;
                    this->groupBox2->TabStop = false;
                    this->groupBox2->Text = L"Datos:";
                    //
                    // Form1
                    //
                    this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
                    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
                    this->BackColor = System::Drawing::SystemColors::ControlLight;
                    this->ClientSize = System::Drawing::Size(300, 255);
                    this->Controls->Add(this->groupBox2);
                    this->Controls->Add(this->groupBox1);
                    this->Controls->Add(this->txtdatos);
                    this->Name = L"Form1";
                    this->Text = L"Calculadora";
                    this->groupBox1->ResumeLayout(false);
                    this->groupBox2->ResumeLayout(false);
                    this->ResumeLayout(false);
                    this->PerformLayout();

             }
#pragma endregion
       //programamos las acciones de cada botón

//boton de igual
private: System::Void btnigual_Click(System::Object^  sender, System::EventArgs^  e) {
                    //si las variables a y b son nulas
                     if(a==""&b=="")
                    {
                           //se mostrará un mensaje de advertencia
                           MessageBox::Show("No ha insertado cantidades");
                    }

                     //si la cantidad b no fue ingresada le asignará un cero     
                     else if(b==""){
                                               b="0";                    
                                               //asignamos a cant1 y cant2 los valores de a y b convertidos a tipo entero
                                               cant1=System::Int32::Parse(a);
                                               cant2=System::Int32::Parse(b);
                                               //salida será igual al valor retornado por el método operación,
                                               //enviamos por parámetros los valores de cant1(cantidad 1), cant2(cantidad 2)
                                               //y numoper(número de operación)
                                               salida=operacion(cant1,cant2,numoper);
                                               //mostramos en le textBox txtdatos la operación
                                               //la variable salida se convierte a string pues es de tipo entero
                                               txtdatos->Text=a+operador+b+"="+salida.ToString();
                                               }
                     //si no sucede
                             else{
                                               //asignamos a cant1 y cant2 los valores de a y b convertidos a tipo entero
                                               cant1=System::Int32::Parse(a);
                                               cant2=System::Int32::Parse(b);
                                               //salida será igual al valor retornado por el método operación,
                                               //enviamos por parámetros los valores de cant1(cantidad 1), cant2(cantidad 2)
                                               //y numoper(número de operación)
                                               salida=operacion(cant1,cant2,numoper);
                                               //mostramos en le textBox txtdatos la operación
                                               //la variable salida se convierte a string pues es de tipo entero
                                               txtdatos->Text=a+operador+b+"="+salida.ToString();
                             }
                     //}
              }
              //boton para sumar
private: System::Void btnsum_Click(System::Object^  sender, System::EventArgs^  e) {
                     //si la variable a no fue ingresada asignará un cero
                     if(a=="")
                           {
                                  a="0";
                           }
                     //si no a tomará su mismo valor
                           else
                           {
                                  a=a;
                           }
                     //numero de cantidad es 1
                     numcant=1;
                     //numero de operacion es 1 para indicar suma
                     numoper=1;
                     //operador tomará el valor de +
                     operador="+";
                     //el textBox txtdatos mostrará el valor de a y el operador arimético
                     txtdatos->Text=a+operador;
              }
private: System::Void btnres_Click(System::Object^  sender, System::EventArgs^  e) {
                     //si la variable a no fue ingresada asignará un cero
                     if(a=="")
                           {
                                  a="0";
                           }
                     //si no a tomará su mismo valor
                           else
                           {
                                  a=a;
                           }
                     //numero de cantidad es 1
                     numcant=1;
                     //numero de operacion es 2 para indicar resta
                     numoper=2;
                     //operador tomará el valor de -
                     operador="-";
                     //el textBox txtdatos mostrará el valor de a y el operador arimético
                     txtdatos->Text=a+operador;
              }

              //boton para multiplicar
private: System::Void btnmul_Click(System::Object^  sender, System::EventArgs^  e) {
                    //si la variable a no fue ingresada asignará un cero
                     if(a=="")
                           {
                                  a="0";
                           }
                     //si no a tomará su mismo valor
                           else
                           {
                                  a=a;
                           }
                     //numero de cantidad es 1
                     numcant=1;
                     //numero de operacion es 3 para indicar multiplicación
                     numoper=3;
                     //operador tomará el valor de x
                     operador="x";
                     //el textBox txtdatos mostrará el valor de a y el operador arimético
                     txtdatos->Text=a+operador;
              }
              //boton para resta
              //boton para division
private: System::Void btndiv_Click(System::Object^  sender, System::EventArgs^  e) {
                     //si la variable a no fue ingresada asignará un cero
                     if(a=="")
                           {
                                  a="0";
                           }
                     //si no a tomará su mismo valor
                           else
                           {
                                  a=a;
                           }
                     //numero de cantidad es 1
                     numcant=1;
                     //numero de operacion es 4 para indicar division
                     numoper=4;
                     //operador tomará el valor de /
                     operador="/";
                     //el textBox txtdatos mostrará el valor de a y el operador arimético
                     txtdatos->Text=a+operador;
              }
private: System::Void btn0_Click(System::Object^  sender, System::EventArgs^  e) {
                     //si numero de cantidad es cero
                     if(numcant==0)
                     {    
                            //a será iguala a a mas 0
                            a=a+"0";
                            //el textbox txtdatos mostrará el valor de a
                            txtdatos->Text=a;
                     }
                     //si no
                     else
                     {
                            //b es igual a b mas 0
                            b=b+"0";
                            //el textbox txtdatos mostrará la variable a, el operador y la variable b
                            txtdatos->Text=a+operador+b;
                     }
              }
private: System::Void btn1_Click(System::Object^  sender, System::EventArgs^  e) {
                    //si numero de cantidad es cero
                     if(numcant==0)
                     {    
                            //a será iguala a a mas 1
                            a=a+"1";
                            //el textbox txtdatos mostrará el valor de a
                            txtdatos->Text=a;
                     }
                     //si no
                     else
                     {
                            //b es igual a b mas 1
                            b=b+"1";
                            //el textbox txtdatos mostrará la variable a, el operador y la variable b
                            txtdatos->Text=a+operador+b;
                     }
              }
private: System::Void btn2_Click(System::Object^  sender, System::EventArgs^  e) {
                    //si numero de cantidad es cero
                     if(numcant==0)
                     {    
                            //a será iguala a a mas 2
                            a=a+"2";
                            //el textbox txtdatos mostrará el valor de a
                            txtdatos->Text=a;
                     }
                     //si no
                     else
                     {
                            //b es igual a b mas 2
                            b=b+"2";
                            //el textbox txtdatos mostrará la variable a, el operador y la variable b
                            txtdatos->Text=a+operador+b;
                     }
              }
private: System::Void btn3_Click(System::Object^  sender, System::EventArgs^  e) {
                     //si numero de cantidad es cero
                     if(numcant==0)
                     {    
                            //a será iguala a a mas 3
                            a=a+"3";
                            //el textbox txtdatos mostrará el valor de a
                            txtdatos->Text=a;
                     }
                     //si no
                     else
                     {
                            //b es igual a b mas 3
                            b=b+"3";
                            //el textbox txtdatos mostrará la variable a, el operador y la variable b
                            txtdatos->Text=a+operador+b;
                     }
              }
private: System::Void btn4_Click(System::Object^  sender, System::EventArgs^  e) {
                     //si numero de cantidad es cero
                     if(numcant==0)
                     {    
                            //a será iguala a a mas 4
                            a=a+"4";
                            //el textbox txtdatos mostrará el valor de a
                            txtdatos->Text=a;
                     }
                     //si no
                     else
                     {
                            //b es igual a b mas 4
                            b=b+"4";
                            //el textbox txtdatos mostrará la variable a, el operador y la variable b
                            txtdatos->Text=a+operador+b;
                     }
              }
private: System::Void btn5_Click(System::Object^  sender, System::EventArgs^  e) {
                     //si numero de cantidad es cero
                     if(numcant==0)
                     {    
                            //a será iguala a a mas 5
                            a=a+"5";
                            //el textbox txtdatos mostrará el valor de a
                            txtdatos->Text=a;
                     }
                     //si no
                     else
                     {
                            //b es igual a b mas 5
                            b=b+"5";
                            //el textbox txtdatos mostrará la variable a, el operador y la variable b
                            txtdatos->Text=a+operador+b;
                     }
              }
private: System::Void btn6_Click(System::Object^  sender, System::EventArgs^  e) {
                     //si numero de cantidad es cero
                     if(numcant==0)
                     {    
                            //a será iguala a a mas 6
                            a=a+"6";
                            //el textbox txtdatos mostrará el valor de a
                            txtdatos->Text=a;
                     }
                     //si no
                     else
                     {
                            //b es igual a b mas 6
                            b=b+"6";
                            //el textbox txtdatos mostrará la variable a, el operador y la variable b
                            txtdatos->Text=a+operador+b;
                     }
              }
private: System::Void btn7_Click(System::Object^  sender, System::EventArgs^  e) {
                     //si numero de cantidad es cero
                     if(numcant==0)
                     {    
                            //a será iguala a a mas 7
                            a=a+"7";
                            //el textbox txtdatos mostrará el valor de a
                            txtdatos->Text=a;
                     }
                     //si no
                     else
                     {
                            //b es igual a b mas 7
                            b=b+"7";
                            //el textbox txtdatos mostrará la variable a, el operador y la variable b
                            txtdatos->Text=a+operador+b;
                     }
              }
private: System::Void btn8_Click(System::Object^  sender, System::EventArgs^  e) {
                     //si numero de cantidad es cero
                     if(numcant==0)
                     {    
                            //a será iguala a a mas 8
                            a=a+"8";
                            //el textbox txtdatos mostrará el valor de a
                            txtdatos->Text=a;
                     }
                     //si no
                     else
                     {
                            //b es igual a b mas 8
                            b=b+"8";
                            //el textbox txtdatos mostrará la variable a, el operador y la variable b
                            txtdatos->Text=a+operador+b;
                     }
              }
private: System::Void btn9_Click(System::Object^  sender, System::EventArgs^  e) {
                     //si numero de cantidad es cero
                     if(numcant==0)
                     {    
                            //a será iguala a a mas 9
                            a=a+"9";
                            //el textbox txtdatos mostrará el valor de a
                            txtdatos->Text=a;
                     }
                     //si no
                     else
                     {
                            //b es igual a b mas 9
                            b=b+"9";
                            //el textbox txtdatos mostrará la variable a, el operador y la variable b
                            txtdatos->Text=a+operador+b;
                     }
              }

private: System::Void btnclear_Click(System::Object^  sender, System::EventArgs^  e) {
                     txtdatos->Text="";
                     numcant=0;
                     numoper=0;
                     a="";
                     b="";
                     operador="";
              }
};
}