Está en la página 1de 4

HERENCIA DE PRODUCTOS

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 HerenciaProducto
{
public partial class Form1 : Form
{
Bien[] B = new Bien[50];
Servicio[] S = new Servicio[50];
int Cb, Cs;

public Form1()
{
InitializeComponent();
}

public Producto Producto


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

private void radioButton2_CheckedChanged(object sender, EventArgs e)


{
if (radioButton2.Checked == true)
{
label6.Text = "DESCRIPCION ";
textBox5.Width = 305;
}
else
{
label6.Text = "STOCK ";
textBox5.Width = 100;
}
}

private void button1_Click(object sender, EventArgs e)


{
// guardar en obj BIEN o SERVICIO
if (radioButton2.Checked == true)
{
Cs++;
S[Cs] = new Servicio();
S[Cs].ingresar_datos(textBox1.Text, textBox2.Text,
textBox3.Text, textBox4.Text, textBox5.Text);
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox1.Focus();
listBox1.Items.Add(S[Cs].retornar_nombre()+" "+
S[Cs].retornar_precio());
}
else
{
Cb++;
B[Cb] = new Bien();
B[Cb].ingresar_datos(textBox1.Text, textBox2.Text,
textBox3.Text, textBox4.Text, textBox5.Text);
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox5.Clear();
textBox1.Focus();
listBox1.Items.Add(B[Cb].retornar_nombre() + " " +
B[Cb].retornar_precio()+" "+B[Cb].retornar_stock());

private void button2_Click(object sender, EventArgs e)


{
// valor alamc sumatoria ( precio*stock)
double valmac = 0;
for (int I = 1; I <= Cb; I++)
valmac += B[I].retornar_precio() * B[I].retornar_stock();
listBox1.Items.Add("El valor es " + valmac);
}

private void button3_Click(object sender, EventArgs e)


{
// serv mas caro
double pmax = 0; int imax = 1;
for (int I = 1; I <= Cs; I++)
if ((S[I].retornar_precio() > pmax) || (I == 1))
{ pmax = S[I].retornar_precio(); imax = I; }
listBox1.Items.Add("El servicio mas caro es " +
S[imax].retornar_nombre());

}
}
}
CLASE PRODUCTO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HerenciaProducto
{
public class Producto
{
protected string Codigo;
protected string Nombre;
protected string Unidad;
protected double Precio;
public void ingresar_datos()
{ }
public double retornar_precio()
{ return Precio; }
public string retornar_nombre()
{ return Nombre; }

protected double precio


{
get
{ return Precio;}
set
{ Precio=value;}
}
}
public class Bien:Producto
{
double Stock;
public void ingresar_datos(string c,string n,string u,string p,string s)
{
Codigo = c;
Nombre = n;
Unidad = u;
Precio = Convert.ToDouble(p);
Stock = Convert.ToDouble(s);
}
public double retornar_stock()
{ return Stock; }
}
public class Servicio : Producto
{
string Descripcion;
public void ingresar_datos(string c, string n,
string u, string p, string d)
{
Codigo = c;
Nombre = n;
Unidad = u;
Precio = Convert.ToDouble(p);
Descripcion = d;
}
public string retornar_desc()
{ return Descripcion; }
}

También podría gustarte