Anda di halaman 1dari 7

Codificación

Clase Principal
Clase Estudiante
Ejecución del programa
Clase principal
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Estudiantes
{
class Program
{
static void Main(string[] args)
{
//AUTOR: JEISON LIDER VILLADA
List<Estudiante> estudiantes = new List<Estudiante>();//se crea la
lista de estudiantes (ARRAYS)
Console.Write("Ingrese la cantidad de estudiantes: ");
int nEstudiantes= int.Parse(Console.ReadLine()); //ingresamos la
cantidad de estudiantes que vamos a evaluar
Console.WriteLine();
for (int i =0; i< nEstudiantes; i++) {
Console.WriteLine();
Console.WriteLine("== Nuevo Estudiante ==");
Estudiante estudiante = new Estudiante();// creamos un objeto
tipo estudiante
Console.Write("Primera nota del estudiante No." +(i+1) + ": ");
estudiante.Nota1 = double.Parse(Console.ReadLine()); //Recibimos
el valor de la primera nota del estudiante
Console.Write("Segunda nota del estudiante No." + (i + 1) + ":
");
estudiante.Nota2 = double.Parse(Console.ReadLine());//Recibimos
el valor de la segunda nota del estudiante
Console.Write("Tercera nota del estudiante No." + (i + 1) + ":
");
estudiante.Nota3 = double.Parse(Console.ReadLine());//Recibimos
el valor de la tercera nota del estudiante
estudiantes.Add(estudiante);//agregamos el objeto estudiante a la
lista de estudiantes
}
int contador =1;
Console.WriteLine();
Console.WriteLine();
Console.WriteLine("---------------------------------------------");
foreach (Estudiante estudiante in estudiantes) {//Recorremos la lista
de estudiantes
Console.WriteLine("La nota final del estudiante No. " + contador + "
Es: " + estudiante.calcularNotaFinal());//calculamos la nota final de cada
estudiante en la lista
contador++;
}
Console.WriteLine("---------------------------------------------");
Console.ReadKey();

}
}
}
Clase estudiante

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Estudiantes
{
class Estudiante
{
//atributos de la clase estudiante
double nota1;
double nota2;
double nota3;
//accesores de los atributos de la clase estudiante
public double Nota1
{
get
{
return nota1;
}

set
{
nota1 = value;
}
}
public double Nota2
{
get
{
return nota2;
}

set
{
nota2 = value;
}
}
public double Nota3
{
get
{
return nota3;
}

set
{
nota3 = value;
}
}
//Metodo que me permite calcular la nota final del estudiante
public double calcularNotaFinal(){
double notaFinal =0;

notaFinal = (nota1* 0.3) +( Nota2 * 0.3) + (Nota3 * 0.4);

return notaFinal;
}
}
}

Anda mungkin juga menyukai