Mostrar Mensajes

Esta sección te permite ver todos los posts escritos por este usuario. Ten en cuenta que sólo puedes ver los posts escritos en zonas a las que tienes acceso en este momento.


Temas - Gabrield Marquez

Páginas: [1]
1
Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {int positivos = 0; int conta = 0; int numero;
Console.WriteLine("Introduce número ");
numero = Int32.Parse(Console.ReadLine());
while (numero != 999)
{
conta = conta + 1;
if (numero > 0) positivos = positivos + 1;
Console.WriteLine("Introduce número ");
numero = Int32.Parse(Console.ReadLine());
}
Console.WriteLine("Has introducido un total de {0}", conta);
Console.WriteLine("y son positivos {0}", positivos);
Console.ReadKey();
} //fin Main
       
        }
    }

2
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace ConsoleApplication1
{
    class Program
    {
       static void Main(string[] args)
       {   
           Console.WriteLine("Practica 1");
            int Saluda()
            {
            Console.WriteLine("Hola Mundo");
            return 1;
            }

        }   
}
        class ParámetrosEntrada
        {
            public int a = 1;
            public static void F(ParámetrosEntrada p)
        {
            p.a++;
        }
        public static void G(int p)
        {
            p++;
        }
        public static void Main()
        {
        int obj1 = 0;
        ParámetrosEntrada obj2 = new ParámetrosEntrada();
        G(obj1);
        F(obj2);
        Console.WriteLine("{0}, {1}", obj1, obj2.a);
        }
       }   


       
        public class Externo
        {
            [DllImport("kernel32")]
        public static extern void CopyFile(string fuente, string destino);
        public static void Main()
        {
         CopyFile("fuente.dat", "destino.dat");
        }
        }   
       
              class Prueba
            {
                Prueba(int x)
            {
                System.Console.Write("Creado objeto Prueba con x={0}",x);
            }
            public static void Main()
            {
                Prueba p = new Prueba(5);
            }
            }   
           
             class A
               {
            public static X (int  A){
            static A()
            {
            Console.WriteLine("Constructor de A");
            X=1;
             
                if (X == 1 = true)  {
                   
                    return X;
                }
               
             }
            class B:A
            {
            static B()
            {
            Console.WriteLine("Constructor de B");
            X=2;
            }
            public static void Main()
            {
            B b = new B();
            Console.WriteLine(B.X);
            }
            }
           
            class A
            {
            ~A()
            {
            Console.WriteLine("Destruido objeto de clase A");
            }
            }
            class B:A
             {
            ~B()
                {
            Console.WriteLine("Destruido objeto de clase B");
            }
            public static void Main()
            {
            new B();
            }
    }

3
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
 
    class Program
    {
        static void Main(string[] args)
        {
           /* int art1 = 0; int art2 = 0; int art3 = 0; int art4 = 0; int art5 = 0;*/ int PrecioM = 3000; int PrecioC = 4000; int PrecioB = 400; int PrecioT = 500;  int PrecioW = 1000; int sum = 0; int cant = 0; int importe = 0; int importe1 = 0; int importe2 = 0; int importe3 = 0; int importe4 = 0;


            Console.WriteLine("\tTodo Informatica .SA ");
            Console.WriteLine("\tVentas");

           
            Console.WriteLine("\n\nArticulo1");
            Console.WriteLine("\nMonitor :  ");
               //art1 = Int32.Parse(Console.ReadLine());

               
             Console.WriteLine("Precio Monitor : 3000 ");
                   

                   
             Console.WriteLine("Cantidad :  ");
             cant = Int32.Parse(Console.ReadLine());
                   
                   
             importe = cant * PrecioM;
             Console.WriteLine("Importe : {0}", importe);
                   
   
            Console.WriteLine("\n\nArticulo2");
            Console.WriteLine("\nCPU :  ");
          //  art2 = Int32.Parse(Console.ReadLine());

           
            Console.WriteLine("Precio CPU :4000 ");
               

             
            Console.WriteLine("Cantidad :  ");
            cant = Int32.Parse(Console.ReadLine());
               
               
            importe1 = cant * PrecioC;
            Console.WriteLine("Importe : {0}", importe1);
               
         
            Console.WriteLine("\n\nArticulo3");
            Console.WriteLine("\nBocina :  ");
               // art3 = Int32.Parse(Console.ReadLine());

               
            Console.WriteLine("Precio Bocina : 400 ");
                   

                   
            Console.WriteLine("Cantidad :  ");
            cant = Int32.Parse(Console.ReadLine());
                   
                   
            importe2 = cant * PrecioB;
            Console.WriteLine("Importe : {0}", importe2);
           
            Console.WriteLine("\n\nArticulo4");
            Console.WriteLine("\nTeclado :  ");
              //  art4 = Int32.Parse(Console.ReadLine());

               
            Console.WriteLine("Precio Teclado : 500 ");
                 

                   
            Console.WriteLine("Cantidad :  ");
            cant = Int32.Parse(Console.ReadLine());
                   
            importe3 = cant * PrecioT;
            Console.WriteLine("Importe : {0}", importe3);
                   
         
           
            Console.WriteLine("\n\nArticulo5");
            Console.WriteLine("\nWebcam :  ");
               // art5 = Int32.Parse(Console.ReadLine());

             
            Console.WriteLine("Precio Webcam : 500 ");
                   

            Console.WriteLine("Cantidad :  ");
            cant = Int32.Parse(Console.ReadLine());
                   
            importe4 = cant * PrecioW;
            Console.WriteLine("Importe : {0}", importe4);
             

            sum = importe + importe1 + importe2 + importe3 + importe4;
           
            Console.WriteLine("\n\n\tEl Total a Pagar es de : {0}", sum);
           
            Console.ReadKey();
        }
    }
}

4
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int positivos = 0; int conta = 0; int numero;
            Console.WriteLine("Introduce Numero");
            numero = Int32.Parse(Console.ReadLine());
            while (numero != 999) {
                conta = conta + 1;
                if (numero > 0) positivos = positivos + 1;
                Console.WriteLine("Introduce numero");
                numero = Int32.Parse(Console.ReadLine());
            }
            Console.WriteLine("Has introducido un total de {0}", conta);
            Console.WriteLine("y son positivos {0}", positivos);
           
           
        }//fin Main
    }
}

5
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hola Mundo");
            Console.ReadLine();
        }
    }
}

6
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace GestionPrimaSeguro
{
    class Program
    {
        static void Main(string[] args)
        {
            Lista listaPoliza = new Lista();
            ConsoleKeyInfo op;
            do
            {
                MenuPrincipal();
                op = Console.ReadKey(true);

                switch (op.Key)
                {
                    case ConsoleKey.E:
                        CargarPoliza(listaPoliza);
                        //Console.ReadKey();
                        break;

                    case ConsoleKey.G:
                        listaPoliza.Guardar();
                        Console.ReadKey();
                        break;

                    case ConsoleKey.V:
                        listaPoliza.VerArchivo();
                        Console.ReadKey();
                        break;

                    case ConsoleKey.Escape:

                        break;
                }

            } while (op.Key != ConsoleKey.Escape);

            Console.Clear();
            Console.Write("\t\t\tPolizas Emitidas");
            listaPoliza.MostrarPoliza();

            Console.ReadKey();
        }

        public static void CargarPoliza(Lista listaPoliza)
        {

            do
            {
                Console.Write("Emitir Poliza si/no: ");
                string respuesta = Console.ReadLine().ToUpper();
                try
                {
                    if (respuesta.Equals("SI"))
                    {

                        Console.Clear();
                        listaPoliza.AddPoliza(GetPoliza());
                    }
                    else
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                Console.WriteLine();

            } while (true);
        }
        public static Poliza GetPoliza()
        {
            SeguroVehiculo sv = new SeguroVehiculo();
            SeguroIncendio si = new SeguroIncendio();
            String nombre, primerApellido, segundoApellido, fechaNacimiento, ocupacion, estadoCivil, direccion, ciudad, estado, fechaEmision,
                marca = "N/A", modelo = "N/A", ubicacion = "N/A", categoria = "N/A", giro = "N/A";
            char sexo = '\u0000';
            int edad = 0, anno = 0;
            double montoAsegurado = 0.0, totalAsegurado = 0.0, sumaEdificio = 0.0, sumaMobiliario = 0.0, sumaMaquinaria = 0.0, sumaExistencia = 0.0;


            Console.Write("\n\t\t\tDatos Del Cliente\n");
            Console.Write("\nNombre: ");
            nombre = Console.ReadLine();
            Console.Write("1er Apellido: ");
            primerApellido = Console.ReadLine();
            Console.Write("2do Apellido: ");
            segundoApellido = Console.ReadLine();
            Console.Write("Fecha Nac: ");
            fechaNacimiento = Console.ReadLine();
            Console.Write("Ocupacion: ");
            ocupacion = Console.ReadLine();
            Console.Write("Estado Civil: ");
            estadoCivil = Console.ReadLine();

            do
            {
                Console.Write("Sexo M/F: ");
                try
                {
                    sexo = Char.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Introduzca Un Solo  Caracter", e);
                }
            } while (sexo.Equals('\u0000'));

            do
            {
                Console.Write("Edad: ");
                try
                {
                    edad = Int32.Parse(Console.ReadLine());
                }
                catch (Exception e)
                {
                    Console.WriteLine("Introduzca Un Valor Numerico", e);
                }
            } while (edad.Equals(0));

            Console.Write("Direccion: ");
            direccion = Console.ReadLine();
            Console.Write("Ciudad: ");
            ciudad = Console.ReadLine();

            Console.Write("\n\t\t\tDatos De La Poliza\n\n");
            Console.Write("Estado: ");
            estado = Console.ReadLine();

            Console.Write("Fecha Emision: ");
            fechaEmision = Console.ReadLine();

            ConsoleKeyInfo op;
            do
            {

                Console.Clear();
                Console.WriteLine("\t\t\tTipo De Seguro\n");
                Console.ForegroundColor = ConsoleColor.Green;
                Console.Write("\n[H]Vehiculo\t");
                Console.Write("\n[I]Incendio\t");
                Console.Write("\n[Esc]Salir\n");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Seleccione opcion...");
                op = Console.ReadKey(true);
                switch (op.Key)
                {
                    case ConsoleKey.H:
                        Console.Write("\n\t\t\tDatos Del Vehiculo\n");
                        Console.Write("\nMarca: ");
                        marca = Console.ReadLine();
                        Console.Write("Modelo: ");
                        modelo = Console.ReadLine();
                        do
                        {
                            Console.Write("Año: ");
                            try
                            {
                                anno = Int32.Parse(Console.ReadLine());
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Introduzca Un Valor Numerico", e);
                            }
                        } while (anno.Equals(0));
                        do
                        {
                            Console.Write("Valor Asegurado: ");
                            try
                            {
                                montoAsegurado = Double.Parse(Console.ReadLine());
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Introduzca Un Valor Numerico", e);
                            }
                        } while (montoAsegurado.Equals(0.0));

                        Console.ReadKey();
                        break;

                    case ConsoleKey.I:
                        Console.Write("\n\t\t\tDatos De La Propiedad\n");
                        Console.Write("\nUbicacion: ");
                        ubicacion = Console.ReadLine();
                        Console.Write("Categoria: ");
                        categoria = Console.ReadLine();
                        Console.Write("Giro: ");
                        giro = Console.ReadLine();
                        do
                        {
                            Console.Write("Suma Edificio: ");
                            try
                            {
                                sumaEdificio = Double.Parse(Console.ReadLine());
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Introduzca Un Valor Numerico", e);
                            }
                        } while (sumaEdificio.Equals(1));
                        do
                        {
                            Console.Write("Suma Mobiliario: ");
                            try
                            {
                                sumaMobiliario = Double.Parse(Console.ReadLine());
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Introduzca Un Valor Numerico", e);
                            }
                        } while (sumaMobiliario.Equals(1));
                        do
                        {
                            Console.Write("Suma Maquinaria: ");
                            try
                            {
                                sumaMaquinaria = Double.Parse(Console.ReadLine());
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Introduzca Un Valor Numerico", e);
                            }
                        } while (sumaMaquinaria.Equals(1));
                        do
                        {
                            Console.Write("Suma Existencia: ");
                            try
                            {
                                sumaExistencia = Double.Parse(Console.ReadLine());
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Introduzca Un Valor Numerico", e);
                            }
                        } while (sumaExistencia.Equals(1));

                        Console.ReadKey();
                        break;

                    case ConsoleKey.Escape:

                        break;
                }

                Console.Write("Otro Tipo De Seguro si/no: ");
                string respuesta = Console.ReadLine().ToUpper();
                try
                {
                    if (respuesta.Equals("SI"))
                    {
                        continue;
                    }
                    else
                    {
                        break;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

            } while (op.Key != ConsoleKey.Escape);

            totalAsegurado = sumaEdificio + sumaMobiliario + sumaMaquinaria + sumaExistencia;


            return new Poliza(estado, fechaEmision, nombre, primerApellido, segundoApellido, fechaNacimiento, ocupacion, estadoCivil, sexo, edad, direccion, ciudad, marca, modelo, anno, montoAsegurado, sv.calcularPrima(montoAsegurado), sv.calcularISC(/*sv.calcularPrima(montoAsegurado)*/), sv.calcularPrimaTotal(/*sv.calcularPrima(montoAsegurado), sv.calcularISC(montoAsegurado)*/), ubicacion, categoria, giro, sumaEdificio, sumaMobiliario, sumaMaquinaria, sumaExistencia, totalAsegurado, si.calcularPrima(totalAsegurado/*si.sumarMontoAsegurado(sumaEdificio, sumaMobiliario, sumaMaquinaria, sumaExistencia)*/), si.calcularISC(/*si.calcularPrima(si.sumarMontoAsegurado(sumaEdificio, sumaMobiliario, sumaMaquinaria, sumaExistencia))*/), si.calcularPrimaTotal(/*si.calcularPrima(si.sumarMontoAsegurado(sumaEdificio, sumaMobiliario, sumaMaquinaria, sumaExistencia)), si.calcularISC(si.calcularPrima(si.sumarMontoAsegurado(sumaEdificio, sumaMobiliario, sumaMaquinaria, sumaExistencia)))*/));

        }
        public static void MostrarPoliza(Poliza p)
        {
            Console.WriteLine(p.ToString());
        }
        public static void MenuPrincipal()
        {
            Console.Clear();
            Console.WriteLine("\t\t\tMenú - Gestion Prima Seguros\n");
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("\n[E]Emitir Poliza");
            Console.Write("\n[G]Guardar Poliza");
            Console.Write("\n[V]Ver Archivo");
            Console.Write("\n[Esc]Salir\n");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Seleccione opcion...");
        }

    }

7
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int edad1 = 0;

            Console.WriteLine("Intruduzca La Edad del Estudiante: ");
            edad1 = Int32.Parse(Console.ReadLine());

            if (edad1 <= 12 == true)
            {
                Console.WriteLine("Este estudiante esta en la seccion 1A");
            } else
                if (edad1 <= 13 == true)
                {
                    Console.WriteLine("Este estudiante esta en la seccion  1B");
                } else
                    if (edad1 >= 14 == true)
                    {
                        Console.WriteLine("Este estudiante esta en la seccion  1C");
                    }
            Console.ReadKey();
        }
    }
}

8
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int Metros = 0; int centimetros = 0;
            Console.Write("Introduzca La Cantidad de Metros a Calcular: ");
            Metros = Int32.Parse(Console.ReadLine());

            centimetros = Metros * 100;
            Console.WriteLine("La Cantidad de Centrimetros es: {0}", centimetros);
            Console.ReadKey();
        }
    }
}

9
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
   
//Nombre de la clase
    class Alimentos
    {
//Atributos de la clase
        private string manzana;
        private string pera;
        private string guineo;
        private string zapote;
        private string melon;

//Constructor de la clase
        public Alimentos(string manzana, string pera, string guineo, string zapote, string melon)
           
        {
            this.manzana = manzana;
            this.pera = pera;
            this.guineo = guineo;
            this.zapote = zapote;
            this.melon = melon;

        }
//Metodos get de la clase
        public string Getmanzana()
        {
            return manzana;
        }
        public string Getpera()
        {
            return pera;
        }
        public string Getguineo()
        {
            return guineo;
        }
        public string Getzapote()
        {
            return zapote;
        }
        public string Getmelon()
        {
            return melon;
        }   

    }
//Clase de Prueba
    class Prueba
    {
//Metodo Main
        public static void Main()
        {
//Llamada al constructor de la clase
           Alimentos op1 = new Alimentos("Manzana", "Pera", "Guineo", "Zapote", "Melon");
           
            MostrarAlimentos(op1);
           

            Console.ReadKey();
        }
        public static void MostrarAlimentos(Alimentos o)
        {
            System.Console.WriteLine("Alimento 1: {0}  Alimento 2: {1}  Alimento 3: {2} Alimento 4: {3}  Alimento 5: {4}",o.Getmanzana(),o.Getpera(),o.Getguineo(),  o.Getzapote(), o.Getmelon());
        }
    }


}

10
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int sum = 0;
            int numero1 = 0; int numero2 = 0; int numero3 = 0; int numero4 = 0;
           
            {
                Console.WriteLine("Primer Parcial");
                numero1 = Int32.Parse(Console.ReadLine());
            }
            if (numero1 > 15 == true)
            {
                Console.WriteLine("Calificacion Invalida");
                Console.WriteLine("Introduzca Nuevamente");
                numero1 = Int32.Parse(Console.ReadLine());
            }
           

            {
                Console.WriteLine("Segundo Parcial");
                numero2 = Int32.Parse(Console.ReadLine());
            }
            if (numero2 > 15 == true)
            {
                Console.WriteLine("Calificacion Invalida");
                Console.WriteLine("Introduzca Nuevamente");
                numero2 = Int32.Parse(Console.ReadLine());
            }
           
            {
                Console.WriteLine("Practica");
                numero3 = Int32.Parse(Console.ReadLine());
            }
            if (numero3 > 30 == true)
            {
                Console.WriteLine("Calificacion Invalida");
                Console.WriteLine("Introduzca Nuevamente");
                numero3 = Int32.Parse(Console.ReadLine());
            }
           
            {
                Console.WriteLine("Examen Final");
                numero4 = Int32.Parse(Console.ReadLine());
            }
            if (numero4 > 40 == true)
            {
                Console.WriteLine("Calificacion Invalida");
                Console.WriteLine("Introduzca Nuevamente");
                numero4 = Int32.Parse(Console.ReadLine());
            }

            {
                sum = numero1 + numero2 + numero3 + numero4;
                Console.WriteLine("Su Calificacion es : {0}", sum);
            }


            if (sum <= 60 == true)
            {
                Console.WriteLine("Reprobado ");
            }
            else
                if (sum <= 69 == true)
                {
                    Console.WriteLine("Extraordinario");
                }
                else
                   
                     if (sum <= 95 == true)
                            {
                                Console.WriteLine("Aprobado");
                            }
                            else
                                if (sum <= 100 == true)
                                {
                                    Console.WriteLine("Excelente");
                                }

            Console.ReadKey();

        }
    }
}

11
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
           

int sum = 0; int numero1 = 0; int numero2 = 0; int numero3 = 0; int numero4 = 0; int numero5 = 0; int promedio = 0;

 Console.WriteLine("Primer Numero");
 numero1 = Int32.Parse(Console.ReadLine());

Console.WriteLine("Segundo Numero");
 numero2 = Int32.Parse(Console.ReadLine());

Console.WriteLine("Tercer Numero");
 numero3 = Int32.Parse(Console.ReadLine());

Console.WriteLine("Cuarto Numero");
 numero4 = Int32.Parse(Console.ReadLine());

Console.WriteLine("Quinto Numero");
 numero5 = Int32.Parse(Console.ReadLine());

sum = numero1 + numero2 + numero3 + numero4 + numero5;
promedio = sum / 5;
                Console.WriteLine("El Promedio es  {0}", promedio);
                Console.ReadKey();
        }
    }
}

12
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace try_catch_1
{
    public class Matriz
    {
        private int cantFila;
        private int cantColumnas;

        private int[,] matriz;

        public Matriz(int nf, int nc)
        {
            cantFila = nf;
            cantColumnas = nc;
            matriz = new int[nf, nc];
        }

        public void CargarMatriz()
        {
            for (int i = 0; i < this.cantFila; ++i) {
                for (int j = 0; j < this.cantColumnas; ++j) {
                    bool hayError = true;

                    while (hayError) {
                        Console.Write(" Valor (  {0},  {1}) : ", i, j);
                        try
                        {
                            int valor = int.Parse(Console.ReadLine());
                            matriz[i, j] = valor;
                            hayError = false;
                        }
                        catch (Exception e) {
                            Console.WriteLine("Valor incorrecto,  verficar......");
                        }
                    }
                }
               

                }
            }   

        public int GetCantidadFilas()
        {
            return this.matriz.GetLength (0);
        }   

        public int GetCantidadColumnas ()
        {
            return this.matriz.GetLength (1);
        }   

        public static Matriz Sumar (Matriz matrizA, Matriz matrizB)
        {
            int cfA = matrizA.GetCantidadFilas ();
            int ccA = matrizA.GetCantidadColumnas ();

            int cfB = matrizB.GetCantidadFilas ();
            int ccB = matrizB.GetCantidadColumnas ();

            if ((cfA != cfB) || (ccA != ccB))   
            {
                throw new Exception ("Matrices incompatibles para la Suma.");
            }   

            Matriz r = new Matriz (cfA, ccA);

            for (int i = 0; i < cfA; ++i)   
            {
                for (int j = 0; j < ccA; ++j)   
                {
                    r.GetMatriz () [i,j] = matrizA.GetMatriz () [i,j] + matrizB.GetMatriz () [i,j];
                }
            }   

            return r;
        }   

        public static Matriz operator + (Matriz matrizA, Matriz matrizB)   
        {
            return Sumar (matrizA, matrizB);
        }   

        public int[,] GetMatriz ()
        {
            return this.matriz;
        }
        }
    }

13
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace try_catch_1
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int cfmA = GetCantidadFila("Cantidad Fila Matriz A");
            int ccmA = GetCantidadFila("Cantidad Columna Matriz A");

            int cfmB = GetCantidadFila("Cantidad Fila Matriz B");
            int ccmB = GetCantidadFila("Cantidad Columna Matriz B");

            Matriz omA = new Matriz(cfmA, ccmA);
            Matriz omB = new Matriz(cfmB, ccmB);
            Matriz omS;

            Console.WriteLine("Cargando Matriz A");
            omA.CargarMatriz();
            Console.WriteLine("-------------------");

            Console.WriteLine("Cargando Matriz B");
            omB.CargarMatriz();
            Console.WriteLine("------------------");

            Console.WriteLine("Matriz A");
            MostrarMatriz(omA.GetMatriz());
            Console.WriteLine("----------------");

            Console.WriteLine("Matriz B");
            MostrarMatriz(omB.GetMatriz());
            Console.WriteLine("-----------------");

            try
            {

                omS = omA + omB;

                Console.WriteLine("Matriz Suma");
                MostrarMatriz(omS.GetMatriz());
                Console.WriteLine("----------------");

            }
            catch (Exception e)
            {

                Console.WriteLine("Error : " + e.Message);
            }
        }

        public static void MostrarMatriz(int[,] m)
        {

            int f = m.GetLength(0);
            int c = m.GetLength(1);

            Console.WriteLine();

            for (int i = 0; i < f; ++i)
            {
                for (int j = 0; j < c; ++j)
                {
                    Console.Write(" {0} \t", m[i, j]);
                }
                Console.WriteLine();
            }
            Console.WriteLine();
        }

        public static int GetCantidadFila(string msg)
        {
            return GetValor(msg);
        }

        public static int GetCantidadColumna(string msg)
        {
            return GetValor(msg);
        }

        private static int GetValor(string msg)
        {
            Boolean valorCorrecto = true;
            int valor = 0;

            do
            {
                Console.Write("{0} : ", msg);
                try
                {
                    valor = int.Parse(Console.ReadLine());
                    valorCorrecto = true;
                }
                catch (Exception e)
                {
                    valorCorrecto = false;
                    Console.WriteLine("Error {0} : ", e.Message);
                }
            } while (!valorCorrecto);
            return valor;
        }
    }


    public class Matriz
    {
        private int cantFila;
        private int cantColumnas;

        private int[,] matriz;

        public Matriz(int nf, int nc)
        {
            cantFila = nf;
            cantColumnas = nc;
            matriz = new int[nf, nc];
        }

        public void CargarMatriz()
        {
            for (int i = 0; i < this.cantFila; ++i)
            {
                for (int j = 0; j < this.cantColumnas; ++j)
                {
                    bool hayError = true;

                    while (hayError)
                    {
                        Console.Write(" Valor (  {0},  {1}) : ", i, j);
                        try
                        {
                            int valor = int.Parse(Console.ReadLine());
                            matriz[i, j] = valor;
                            hayError = false;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Valor incorrecto,  verficar......");
                        }
                    }
                }


            }
        }

        public int GetCantidadFilas()
        {
            return this.matriz.GetLength(0);
        }

    }
}

14
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class A
    {
        private int i;

        public A(int i)
        {
            this.i = i;
        }
        public int GetI()
        {
        return i;
        }
    }
    class B:A
    {
    public B():base(10)
    {
   
    }
    }
    class Prueba
    {
    public static void Main()
    {
    B.ob = new B();

        System.Console.WriteLine(ob.GetI());
    }
    }
}

15
Código del ejemplo:

Código: [Seleccionar]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



    class Persona
    {
        private string cedula;
        private string nombre;
        private string apellido;

        public Persona(string cedula, string nombre, string apellido)
        {
            this.cedula = cedula;
            this.nombre = nombre;
            this.apellido = apellido;
        }
        public string Getcedula()
        {
         return cedula;
        }
        public string Getnombre()
        {
            return nombre;
        }
        public string Getapellido()
        {
            return apellido;
        }
    }
   
    class Estudiante:Persona
        {
        private string matricula;
        private string carrera;
       

        public Estudiante(string cedula, string nombre, string apellido, string matricula, string carrera):base(cedula,nombre,apellido)
        {
            this.matricula = matricula;
            this.carrera = carrera;
           
        }
        public string Getmatricula()
        {
            return matricula ;
        }
        public string Getcarrera()
        {
            return carrera;
        }
    }

    class Prueba
    {
    public static void Main ()
    {
    Estudiante op1 = new Estudiante ("123789001","Juan","Mendoza", "100044974", "Lic. Informatica");
    Estudiante op2 = new Estudiante("001476589002", "Maria", "Camela", "100044974", "Ing. Civil");
        MostrarEstudiante(op1);
        MostrarEstudiante(op2);

        Console.ReadKey();
    }
        public static void MostrarEstudiante (Estudiante o)
        {
            System.Console.WriteLine("Cedula {0}  Nombre {1}  Apellido {2} Matricula {3}  Carrera {4}", o.Getcedula(), o.Getnombre(), o.Getapellido(), o.Getmatricula(), o.Getcarrera());
        }
    }


Páginas: [1]

Sobre la educación, sólo puedo decir que es el tema más importante en el que nosotros, como pueblo, debemos involucrarnos.

Abraham Lincoln (1808-1865) Presidente estadounidense.

aprenderaprogramar.com: Desde 2006 comprometidos con la didáctica y divulgación de la programación

Preguntas y respuestas

¿Cómo establecer o cambiar la imagen asociada (avatar) de usuario?
  1. Inicia sesión con tu nombre de usuario y contraseña.
  2. Pulsa en perfil --> perfil del foro
  3. Elige la imagen personalizada que quieras usar. Puedes escogerla de una galería de imágenes o subirla desde tu ordenador.
  4. En la parte final de la página pulsa el botón "cambiar perfil".