Descarga la aplicación para disfrutar aún más
Vista previa del material en texto
PROBLEMAS PROPUESTOS 1. Crear un array de x * y filas (cargar x, y por teclado) Imprimir el array completa y la última fila. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tarea { class Tarea { private int[,] cam; public void Cargar() { Console.Write("Indique numero de filas: "); string linea; linea = Console.ReadLine(); int filas = int.Parse(linea); Console.Write("Imdique número de columnas: "); linea = Console.ReadLine(); int columnas = int.Parse(linea); cam = new int[filas, columnas]; for (int f = 0; f < cam.GetLength(0); f++) { for (int c = 0; c < cam.GetLength(1); c++) { Console.Write("Ingrese valor: "); linea = Console.ReadLine(); cam[f, c] = int.Parse(linea); } } } public void Imprimir() { for (int f = 0; f < cam.GetLength(0); f++) { for (int c = 0; c < cam.GetLength(1); c++) { Console.Write(cam[f, c] + " "); } Console.WriteLine(); } } public void UltimaFila() { Console.WriteLine("****************************"); Console.WriteLine("Ultima fila: "); for (int c = 0; c < cam.GetLength(1); c++) { Console.Write(cam[cam.GetLength(0) - 1, c] + " "); } } static void Main(string[] args) { Tarea la= new Tarea(); la.Cargar(); la.Imprimir(); la.UltimaFila(); Console.ReadKey(); } } } 2. Crear un array de x * y filas (cargar x, y por teclado) Imprimir el mayor elemento y la fila y columna donde se almacena. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tarea2 { class Tarea2 { private int[,] cam; public void Cargar() { Console.Write("Ingrese cantidad de filas:"); string linea; linea = Console.ReadLine(); int filas = int.Parse(linea); Console.Write("Ingrese cantidad de columnas:"); linea = Console.ReadLine(); int colum = int.Parse(linea); cam = new int[filas, colum]; for(int f=0;f<cam.GetLength(0);f++) { for (int c = 0; c < cam.GetLength(1); c++) { Console.Write("Ingrese numero:"); linea = Console.ReadLine(); cam[f,c] = int.Parse(linea); } } } public void imprimirmayor() { int mayor = cam[0, 0]; int filma = 0; int colman = 0; for(int f=0;f<cam.GetLength(0);f++) { for(int c=0;c<cam.GetLength(1);c++) { if(cam[f,c]>mayor) { mayor = cam[f,c]; filma = f+1; colman = c+1; } } } Console.WriteLine("-------------------"); Console.WriteLine("El numero mayor es:" + mayor); Console.WriteLine("Se encuentra en la fila " + filma + " , columna " + colman); Console.ReadLine(); } static void Main(string[] args) { Tarea2 la = new Tarea2(); la.Cargar(); la.imprimirmayor(); } } } 3. Crear un array de x * y filas (cargar x, y por teclado) Intercambiar la primera fila con la segunda. Imprimir luego la matriz. using System; using System.Collections.Concurrent; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tarea3 { class Tarea3 { private int[,] cam; public void cargar() { Console.WriteLine("Indique cantidad de filas:"); string linea; linea = Console.ReadLine(); int fila = int.Parse(linea); Console.WriteLine("Indique cantidad de columnas:"); linea = Console.ReadLine(); int colum = int.Parse(linea); cam = new int[fila, colum]; for (int f = 0; f < cam.GetLength(0); f++) { for (int c = 0; c < cam.GetLength(1); c++) { Console.WriteLine("Ingrese número:"); linea = Console.ReadLine(); cam[f,c] = int.Parse(linea); } } } public void intercambio() { for (int c = 0; c < cam.GetLength(1); c++) { int a = cam[0, 0]; cam[0, c] = cam[1, c]; cam[1, c] = a; } } public void imprimir() { Console.WriteLine(); Console.WriteLine("El intercambio de primera fila por segunda es:"); for (int f=0; f < cam.GetLength(0); f++) { for (int c=0;c<cam.GetLength(1);c++) { Console.WriteLine(); Console.WriteLine(cam[f, c] + " "); } Console.WriteLine(); } Console.ReadKey(); } static void Main(string[] args) { Tarea3 la = new Tarea3(); la.cargar(); la.intercambio(); la.imprimir(); } } } 4. Crear un array de x * y filas (cargar x, y por teclado) Mostrar los índices y valores que cumplan con una condición especifica establecida por Ud. 5. Plantear una clase llamada Alumno y definir como atributos su nombre, apellido y su edad. En el constructor realizar la carga de datos. Definir otros dos métodos para imprimir los datos ingresados y un mensaje si es mayor o no de edad (edad >=18) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tarea5 { class Alumno { private string nombre; private string apellido; private int edad; public Alumno() { Console.WriteLine("Ingrese nombre:"); nombre = Console.ReadLine(); Console.WriteLine("Ingrese apellido:"); apellido = Console.ReadLine(); Console.WriteLine("Ingrese edad:"); string linea = Console.ReadLine(); edad = int.Parse(linea); } public void Imprimir() { Console.WriteLine("Nombre: " + nombre); Console.WriteLine("Apellido: " + apellido); Console.WriteLine("Edad: " + edad); } public void Mayoredad() { if(edad>=18) { Console.WriteLine(nombre + " " + apellido + " es mayor de edad con " + edad + " años"); } else { Console.WriteLine(nombre+ " NO ES MAYOR DE EDAD"); } } static void Main(string[] args) { Alumno alum = new Alumno(); alum.Imprimir(); alum.Mayoredad(); Console.ReadKey(); } } } 6. Plantear una clase que represente un empleado. Definir como atributos su nombre, apellido, estado civil y su sueldo. En el constructor cargar los atributos y luego en otro método imprimir sus datos, en otro métododefinir si recibe bono (5%) si es casado y por último uno que imprima un mensaje si se le hace retención de 7% (si el sueldo supera a 3200) using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tarea6 { class Empleado { private string nombre; private string apellido; private string civil; private int sueldo; private int bono; private double pago; public Empleado() { Console.WriteLine("Ingrese su nombre:"); nombre = Console.ReadLine(); Console.WriteLine("Ingrese su apellido:"); apellido = Console.ReadLine(); Console.WriteLine("Ingrese su estado civil(C/S):"); civil = Console.ReadLine(); Console.WriteLine("Ingrese su sueldo:"); string linea = Console.ReadLine(); sueldo = int.Parse(linea); } public void imprimir() { Console.WriteLine("Nombre: " + nombre); Console.WriteLine("Apellido: " + apellido); Console.WriteLine("Estado Civil: " + civil); Console.WriteLine("Sueldo: " + sueldo); } public void Bono() { Console.WriteLine(""); if (civil == "C"|| civil== "c") { Console.WriteLine("Empleado recibirá bono"); double bono = 0.07; pago = sueldo + (sueldo * bono); } else { Console.WriteLine("Empleado no recibirá bono"); } } public void impuesto() { if (sueldo > 3200) { Console.WriteLine("Se hará retención del 7%"); double imp = 0.07; pago= sueldo - (sueldo * imp); Console.WriteLine("El pago a abonar sería: " + pago); } else { Console.WriteLine("No tendrá retenciones"); } } static void Main(string[] args) { Empleado empl1; empl1 = new Empleado(); empl1.imprimir(); empl1.Bono(); empl1.impuesto(); } } } 7. Implementar la clase operaciones. Se deben cargar dos valores enteros en el constructor, calcular su suma, resta, multiplicación, división, residuo, potencia, y factorial, cada una en un método, imprimir dichos resultados. using System; using System.Collections.Generic; using System.Text; using System.Linq; using System.Threading.Tasks; namespace Tarea7 { class Operaciones { int num1, num2; public Operaciones() { Console.WriteLine("Ingrese primer numero"); string linea = Console.ReadLine(); num1 = int.Parse(linea); Console.WriteLine("Ingrese segundo numero"); string dos = Console.ReadLine(); num2 = int.Parse(dos); } public void sumar() { int suma; suma = num1 + num1; Console.WriteLine("La suma es: " + suma); } public void resta() { int resta; resta = num1 - num2; Console.WriteLine("La resta es: " + resta); } public void multiplicar() { int multi; multi = num1 * num2; Console.WriteLine("La multiplicacion es: " + multi); } public void division() { float div; div = num1 / num2; Console.WriteLine("La división es: " + div); } public void residuo() { int resi; resi = num1 % num2; Console.WriteLine("El residuo es: " + resi); } public void potencia() { double pot; pot = Math.Pow(num1, num2); Console.WriteLine("La potencia es: " + pot); } public void factorial() { long f = 1; for(int i=num1;i>=1;i--) { f = f * i; } Console.WriteLine("El factorial es: " + f); } static void Main(string[] args) { Operaciones opera = new Operaciones(); opera.sumar(); opera.resta(); opera.multiplicar(); opera.division(); opera.residuo(); opera.potencia(); opera.factorial(); Console.ReadKey(); } } } 8. Plantear un programa que permita jugar a la ruleta de números del 1 al 10. Las reglas de juego son: se gira tres veces a ruleta si en las tres oportunidades sale el numero 7 mostrar un mensaje que "gano", sino "perdió". using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tarea8 { class Ruleta { public void Tiros() { Random random = new Random(); int numero1 = random.Next(1, 11); Console.WriteLine("Primer giro: " + numero1); int numero2 = random.Next(1, 11); Console.WriteLine("Segundo giro: " + numero2); int numero3 = random.Next(1, 11); Console.WriteLine("Tercer giro: " + numero3); if (numero1 == 7 && numero2 == 7 && numero3 == 7) { Console.WriteLine("FELICIDADES!!! GANO LA RULETA"); } else { Console.WriteLine("VUELVA A INTENTARLO"); } } static void Main(string[] args) { Ruleta la = new Ruleta(); la.Tiros(); } } } 9. Plantear una clase Club y otra clase Socio. La clase Socio debe tener los siguientes atributos privados: nombre, categoría y la antigüedad en el club (en años). En el constructor pedir la carga del nombre y su antigüedad; la categoría se define según los años de antigüedad (‘Platinum’ más de 10 años, ‘Premium’ más de 7 y menos de 10, ‘Gold’ más de 5 y menos de 7, ‘Classic’ menos de 5 años. La clase Club debe tener como atributos 3 objetos de la clase Socio. Definir una responsabilidad para imprimir la info del socio (socios) con mayor antigüedad en el club. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Tarea9 { class Socio { private string nombre; private int anti; public Socio() { Console.Write("Ingrese el nombre del socio: "); nombre = Console.ReadLine(); ; Console.Write("Ingrese la antiguedad: "); string linea = Console.ReadLine(); anti = int.Parse(linea); } public void Imprimir() { Console.WriteLine(nombre + " ;tiene una antiguedad de " + anti + " años"); if (anti > 10) { Console.WriteLine("Socio pertenece a la categoria Platinum"); } else if (anti > 7 && anti < 10) { Console.WriteLine("Socio pertenece a la categoria Preminum"); } else if (anti > 5 && anti < 7) { Console.WriteLine("Socio pertenece a la categoria Gold"); } else if (anti < 5) { Console.WriteLine("Socio pertenece a la categoria Classic"); } } public int RetornarAntiguedad() { return anti; } } class Club { private Socio s1, s2, s3; public Club() { s1 = new Socio(); s2 = new Socio();s3 = new Socio(); } public void MayorAntiguedad() { Console.Write("Socio con mayor antiguedad: "); if (s1.RetornarAntiguedad() > s2.RetornarAntiguedad() && s1.RetornarAntiguedad() > s3.RetornarAntiguedad()) { s1.Imprimir(); } else { if (s2.RetornarAntiguedad() > s3.RetornarAntiguedad()) { s2.Imprimir(); } else { s3.Imprimir(); } } } static void Main(string[] args) { Club club1 = new Club(); club1.MayorAntiguedad(); Console.ReadKey(); } } } 10. Plantee una solución para el enunciado (usar POO): Se desea saber la temperatura media trimestral de cuatro países. Para ello se tiene como dato las temperaturas medias mensuales de dichos países. Se debe ingresar el nombre del país y seguidamente las tres temperaturas medias mensuales: a. Seleccionar las estructuras de datos adecuadas para el almacenamiento de los datos en memoria. b. Cargar por teclado los nombres de los países y las temperaturas medias mensuales. c. Imprimir los nombres de los países y las temperaturas medias mensuales de las mismas. d. Calcular la temperatura media trimestral de cada país. e. Imprimir los nombres de los países y las temperaturas medias trimestrales. f. Imprimir el nombre del país con la temperatura media trimestral mayor.
Compartir