Registros PROF. LIZETTE
-
Upload
vfreddyantonio -
Category
Documents
-
view
213 -
download
0
description
Transcript of Registros PROF. LIZETTE
![Page 1: Registros PROF. LIZETTE](https://reader036.fdocuments.net/reader036/viewer/2022072002/563db96a550346aa9a9d1b4e/html5/thumbnails/1.jpg)
//Ejemplo de Registrousing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace registro{ class Program { public struct datos { public int id; public string na;
} static void Main(string[] args) { datos reg = new datos(); // Inicialización reg.id = 100; reg.na = "Lola Flores"; // Resultado Console.Write("Datos:\n"); Console.WriteLine("Id = {0} \nNombre y Apellido = {1}", reg.id, reg.na); // Pedir y resultado Console.WriteLine("\nDe el Id "); reg.id = int.Parse(Console.ReadLine()); Console.WriteLine("De el Nombre y Apellido "); reg.na = Console.ReadLine(); Console.Write("\nDatos:\n"); Console.WriteLine("Id = {0} \nNombre y Apellido = {1}", reg.id, reg.na); Console.ReadKey(); } }}
//Ejemplo Registro de Registro using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace registro{ class Program { public struct regp { public string n; public string a; } public struct rege { public int id; public regp na; }
![Page 2: Registros PROF. LIZETTE](https://reader036.fdocuments.net/reader036/viewer/2022072002/563db96a550346aa9a9d1b4e/html5/thumbnails/2.jpg)
static void Main(string[] args) { rege reg = new rege(); Console.Write("De el Id: "); reg.id = int.Parse(Console.ReadLine()); Console.Write("De el Nombre: "); reg.na.n = Console.ReadLine(); Console.Write("De el Apellido: "); reg.na.a = Console.ReadLine(); Console.WriteLine("\nId: " + reg.id); Console.WriteLine("Nombre: " + reg.na.n); Console.WriteLine("Apellido: " + reg.na.a); Console.ReadKey(); } }}
//Ejemplo Arreglo de Registro using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace registro{ class Program { const int N = 4; public struct reg { public int id; public string na; } static void Main(string[] args) { reg[] ar = new reg[N]; for (int i = 0; i < N; i++) { Console.WriteLine("De el Id "); ar[i].id = int.Parse(Console.ReadLine()); Console.WriteLine("De el Nombre y Apellido "); ar[i].na = Console.ReadLine(); } for (int i = 0; i < ar.Length; i++) { Console.WriteLine("De el Id " + ar[i].id); Console.WriteLine("De el Nombre y Apellido " + ar[i].na); } Console.ReadKey(); } }}
//Ejemplo con un campo de tipo arreglo.using System;using System.Collections.Generic;using System.Linq;
![Page 3: Registros PROF. LIZETTE](https://reader036.fdocuments.net/reader036/viewer/2022072002/563db96a550346aa9a9d1b4e/html5/thumbnails/3.jpg)
using System.Text;namespace campoarreglo{ class Program { public const int N = 3; public struct datos { public int id; public string na; public float[] sal; public void fsal() { sal = new float[N]; } } static void Main(string[] args) { // Inicialización datos r = new datos(); //Referencia a objeto como instancia de un objeto. r.fsal(); Console.WriteLine("De el Id "); r.id = int.Parse(Console.ReadLine()); Console.WriteLine("De el Nombre y Apellido "); r.na = Console.ReadLine(); for (int j = 0; j < N; j++) { Console.WriteLine("De el sal {0} ", j); r.sal[j] = float.Parse(Console.ReadLine()); } Console.WriteLine("Id "+ r.id); Console.WriteLine("Nombre y Apellido "+r.na); for (int j = 0; j < N; j++) Console.WriteLine("Sal {0} {1}",j,r.sal[j]); Console.ReadKey(); } }}
//Ejemplo con un campo de tipo arreglo Bidimensional.
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace campoarreglo{ class Program { public const int N = 2; public struct datos { public int id; public string na; public float[,] sal; public void fsal() {
![Page 4: Registros PROF. LIZETTE](https://reader036.fdocuments.net/reader036/viewer/2022072002/563db96a550346aa9a9d1b4e/html5/thumbnails/4.jpg)
sal = new float[N,N]; } } static void Main(string[] args) { // Inicialización datos r = new datos(); //Referencia a objeto como instancia de un objeto. r.fsal(); Console.WriteLine("De el Id "); r.id = int.Parse(Console.ReadLine()); Console.WriteLine("De el Nombre y Apellido "); r.na = Console.ReadLine(); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { Console.WriteLine("De el sal {0}{1} ", i, j); r.sal[i,j] = float.Parse(Console.ReadLine()); } Console.WriteLine("Id "+ r.id); Console.WriteLine("Nombre y Apellido "+r.na); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) Console.WriteLine("Sal {0} {1} {2}", i,j, r.sal[i,j]); Console.ReadKey(); } }}
//Ejemplo con un campo de tipo arreglo unidimensional con Bidimensional.
using System;using System.Collections.Generic;using System.Linq;using System.Text;
namespace campoarreglo{ class Program { public const int N = 2;
public struct matriz { public float[,] m; public void fm() { m = new float[N,N]; } }
public struct datos { public int id; public string na; public matriz[] sal;
![Page 5: Registros PROF. LIZETTE](https://reader036.fdocuments.net/reader036/viewer/2022072002/563db96a550346aa9a9d1b4e/html5/thumbnails/5.jpg)
public void fsal() { sal = new matriz[N]; } } static void Main(string[] args) { // Inicialización datos r = new datos(); //Referencia a objeto como instancia de un objeto. r.fsal(); Console.WriteLine("De el Id "); r.id = int.Parse(Console.ReadLine()); Console.WriteLine("De el Nombre y Apellido "); r.na = Console.ReadLine();
for (int i = 0; i < N; i++) { r.sal[i].fm(); Console.WriteLine("De el sal: {0}", i); for (int j = 0; j < N; j++) for (int k = 0; k < N; k++) { Console.WriteLine("De el sal: {0} {1}", j, k); r.sal[i].m[j, k] = float.Parse(Console.ReadLine()); } } Console.WriteLine("Id "+ r.id); Console.WriteLine("Nombre y Apellido "+r.na); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) for (int k = 0; k < N; k++) Console.WriteLine("Sal {0} {1} {2}: {3}", i, j, k, r.sal[i].m[j, k]); Console.ReadKey(); } }}
//Ejemplo Arreglo de Registro de Arreglo using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace registro{ class Program { const int N = 3; public struct regp { public int id; public string na; public float[] sal;
![Page 6: Registros PROF. LIZETTE](https://reader036.fdocuments.net/reader036/viewer/2022072002/563db96a550346aa9a9d1b4e/html5/thumbnails/6.jpg)
public void fs() { sal = new float[N]; } } public struct rege { public string nae; public regp[] rp; public void frp() { rp = new regp[N]; } } static void Main(string[] args) { rege[] ar = new rege[N]; for (int i = 0; i < N; i++) { Console.WriteLine("De el Nombre de la empresa "); ar[i].nae = Console.ReadLine(); ar[i].frp(); //Referencia a objeto como instancia de un objeto. for (int j = 0; j < N; j++) { Console.WriteLine("De el Id "); ar[i].rp[j].id = int.Parse(Console.ReadLine()); Console.WriteLine("De el Nombre y Apellido "); ar[i].rp[j].na = Console.ReadLine(); ar[i].rp[j].fs(); //Referencia a objeto como instancia de un objeto. for (int k = 0; k < N; k++) { Console.WriteLine("De el sal {0} ", k); ar[i].rp[j].sal[k] = float.Parse(Console.ReadLine()); } } } for (int i = 0; i < ar.Length; i++) { Console.WriteLine("Nombre de la empresa "+ ar[i].nae); for (int j = 0; j < N; j++) { Console.WriteLine("Id " + ar[i].rp[j].id); Console.WriteLine("Nombre y Apellido " + ar[i].rp[j].na); for (int k = 0; k < N; k++) Console.WriteLine("sal {0} {1} ", k, ar[i].rp[j].sal[k]); } } Console.ReadKey(); } }}//Ejemplo Arreglo de Registro de Arreglo Usando método using System;using System.Collections.Generic;using System.Linq;using System.Text;
![Page 7: Registros PROF. LIZETTE](https://reader036.fdocuments.net/reader036/viewer/2022072002/563db96a550346aa9a9d1b4e/html5/thumbnails/7.jpg)
namespace registro{ class Program { const int N = 3; public struct rege { public int id; public string na; public float sal; } public struct remp { public string nae; public int ruc; public int ce; public rege[] re; public void fre() { re = new rege[N]; } }
public static void Llenar(remp[] ar) { for (int i = 0; i < N; i++) { Console.WriteLine("De el Nombre de la empresa "); ar[i].nae = Console.ReadLine(); Console.WriteLine("De el númeo RUC de la empresa "); ar[i].ruc = int.Parse(Console.ReadLine()); Console.WriteLine("Cantidad de empleados de la empresa "); ar[i].ce = int.Parse(Console.ReadLine()); ar[i].fre(); //Referencia a objeto como instancia de un objeto. for (int j = 0; j < ar[i].ce; j++) { Console.WriteLine("De el Id "); ar[i].re[j].id = int.Parse(Console.ReadLine()); Console.WriteLine("De el Nombre y Apellido "); ar[i].re[j].na = Console.ReadLine(); Console.WriteLine("De el sal "); ar[i].re[j].sal= float.Parse(Console.ReadLine()); } } }
public static void Imp(remp[] ar) { for (int i = 0; i < ar.Length; i++) { Console.WriteLine("Empresa: " + ar[i].nae); Console.WriteLine("RUC de la Empresa: " + ar[i].ruc); for (int j = 0; j < ar[i].ce; j++) { Console.WriteLine("Id Empleado: " + ar[i].re[j].id); Console.WriteLine("Nombre Empleado: " + ar[i].re[j].na); Console.WriteLine("Sal Empleado: {0} ", ar[i].re[j].sal);
![Page 8: Registros PROF. LIZETTE](https://reader036.fdocuments.net/reader036/viewer/2022072002/563db96a550346aa9a9d1b4e/html5/thumbnails/8.jpg)
} } } static void menu() { Console.WriteLine("<<<<< MENU >>>>>"); Console.WriteLine("1. LLenar"); Console.WriteLine("2. Imprimir"); Console.WriteLine("3. Salir");
} static void pedir(string m, ref int op) { Console.WriteLine("{0}", m); op = int.Parse(Console.ReadLine());
}
public static void Ejecutar(remp[] ar) { int op = 0; do { menu(); do { pedir("Dar la opcion", ref op); } while (op < 1 || op > 3);
switch (op) { case 1: Llenar(ar); break; case 2: Imp(ar); break; case 3: Console.WriteLine("SALIENDO"); break; default: Console.WriteLine("ingrese una opcion dentro del rango"); break; } } while (op != 3); }
static void Main(string[] args) { remp[] ar = new remp[N]; Ejecutar(ar); Console.ReadKey(); } }}