Sei sulla pagina 1di 4

HERENCIA DE CLASES

FORM1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ClsProductos
{
public partial class Form1 : Form
{
Bien[] B = new Bien[50];
Servicio[] S = new Servicio[50];
int I, K;
public Form1()
{
InitializeComponent();
}

private void button3_Click(object sender, EventArgs e)


{
if (radioButton1.Checked == true)
{
I++;
B[I] = new Bien();
B[I].ingreso_datos(textBox1.Text, textBox2.Text, textBox3.Text);
listBox1.Items.Add("Bien " + B[I].retornarPrecio());
}
else
{
K++;
S[K] = new Servicio();
S[K].ingreso_datos(textBox1.Text, textBox2.Text, textBox3.Text);
listBox1.Items.Add("Servicio " + S[K].retornarPrecio());
}
}

private void button1_Click(object sender, EventArgs e)


{
float prom=0;
for (int i=1;i<=I;i++)
prom += B[i].retornarPrecio();
prom = prom/I;
listBox1.Items.Add("Prom bienes " + prom);
}

private void button2_Click(object sender, EventArgs e)


{
float prom=0;
for (int i=1;i<=I;i++)
prom += S[i].retornarPrecio();
prom = prom/K;
listBox1.Items.Add("Prom servicio " + prom);
}

private void panel1_Paint(object sender, PaintEventArgs e)


{

}
}
}

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

namespace ClsProductos
{
public class Producto
{
protected string cod;
protected string nom;
protected float precio;

public Form1 Form1


{
get
{
throw new System.NotImplementedException();
}
set
{
}
}

public float retornarPrecio()


{ return precio; }
public void ingreso_datos()
{ }

}
public class Bien:Producto
{
public void ingreso_datos(string c, string n, string p)
{
cod = c;
nom = n;
precio = Convert.ToSingle(p);
}
}
public class Servicio:Producto
{
public void ingreso_datos(string c, string n, string p)
{
cod = c;
nom = n;
precio = Convert.ToSingle(p);

}
}

Potrebbero piacerti anche