Ver Mensaje Individual
  #1 (permalink)  
Antiguo 13/06/2013, 17:44
Avatar de vicion
vicion
 
Fecha de Ingreso: noviembre-2011
Mensajes: 79
Antigüedad: 12 años, 6 meses
Puntos: 1
problema rectangulo c#

Ejercicio
-------------
Crea una clase Rectangulo que modele rectángulos por medio de cuatro
puntos (los vértices). Para ello crea la clase Punto.
· Dispondrá de dos constructores:
* - uno que cree un rectángulo partiendo de sus cuatro vértices
* - otro que cree un rectángulo partiendo de la base y la altura, de
* * forma que su vértice inferior izquierdo esté en (0,0).
· La clase también incluirá un método para calcular la superficie.
· Otro para desplazar el rectángulo en el plano.


hasta ahora ya arme bastantes cosas pero me falta el metodo desplazar.
saludos


clase vertice:
Código csharp:
Ver original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace tp1_6
  6. {
  7.  * *public class Vertice
  8.  * *{
  9.  * * * *private int x;
  10.  * * * *private int y;
  11.  
  12.  * * * *// constructor del vertice
  13.  * * * *public Vertice(int n1, int n2)
  14.  * * * *{
  15.  * * * * * *this.x = n1;
  16.  * * * * * *this.y = n2;
  17.  * * * *}
  18.  
  19.  * * * *// las propiedades X e Y
  20.  * * * *public int X
  21.  * * * *{
  22.  * * * * * *set { x = value; }
  23.  * * * * * *get { return x; }
  24.  * * * *}
  25.  
  26.  * * * *public int Y
  27.  * * * *{
  28.  * * * * * *set { y = value; }
  29.  * * * * * *get { return y; }
  30.  * * * *}
  31.  * *}
  32. }

clase rectangulo:
Código csharp:
Ver original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace tp1_6
  6. {
  7.  * *public class Rectangulo
  8.  * *{
  9.  * * * *private Vertice a;
  10.  * * * *private Vertice b;
  11.  * * * *private Vertice c;
  12.  * * * *private Vertice d;
  13.  * * * *private int altura;
  14.  * * * *private int bace;
  15.  
  16.  * * * *//constructor a partir de los 4 vertices
  17.  * * * *public Rectangulo(Vertice v1, Vertice v2, Vertice v3, Vertice v4)
  18.  * * * *{
  19.  * * * * * *this.A = v1;
  20.  * * * * * *this.B = v2;
  21.  * * * * * *this.c = v3;
  22.  * * * * * *this.d = v4;
  23.  * * * *} * *
  24.  * * * *//constructor a partir de base y altura
  25.  * * * *public Rectangulo(int ba,int alt)
  26.  * * * *{
  27.  * * * * * *this.A = new Vertice(0, 0);
  28.  * * * * * *this.B = new Vertice(this.a.X, ba);
  29.  * * * * * *this.C = new Vertice(alt, this.b.Y);
  30.  * * * * * *this.D = new Vertice(this.c.X, this.a.Y);    * * * * * * * * * *
  31.  * * * *}
  32.  * * * *//----------------propiedades de base y altura------------
  33.  * * * *public int Altura
  34.  * * * *{
  35.  * * * * * *set { altura = value; }
  36.  * * * * * *get { return altura; }
  37.  * * * *}
  38.  * * * *public int Bace
  39.  * * * *{
  40.  * * * * * *set { bace = value; }
  41.  * * * * * *get { return bace; }
  42.  * * * *}
  43.  * * * *
  44.  * * * *//----------------propiedades de los vertices------------------------
  45.  * * * *public Vertice A
  46.  * * * *{
  47.  * * * * * *set { a = value; }
  48.  * * * * * *get { return a; }
  49.  * * * *}
  50.  * * * *public Vertice B
  51.  * * * *{
  52.  * * * * * *set { b = value; }
  53.  * * * * * *get { return b; }
  54.  * * * *}
  55.  * * * *public Vertice C
  56.  * * * *{
  57.  * * * * * *set { c = value; }
  58.  * * * * * *get { return c; }
  59.  * * * *}
  60.  * * * *public Vertice D
  61.  * * * *{
  62.  * * * * * *set { d = value; }
  63.  * * * * * *get { return d; }
  64.  * * * *}
  65.  
  66.  * * * *//--------metodo q saca la superficie--------
  67.  * * * *public int Superficie()
  68.  * * * *{
  69.  * * * * * *return (this.d.X - this.a.X) * (this.b.Y - this.a.Y);
  70.  
  71.  * * * *}
  72.  * * * *
  73.  * * * *//---------metodo perimetro----------
  74.  * * * *public int Perimetro()
  75.  * * * *{
  76.  * * * * * *return (((this.d.X - this.a.X) * 2) + ((this.b.Y - this.a.Y) * 2));
  77.  * * * *}
  78.  * * * *
  79.  * * * *//-------metodo desplazar--------
  80.  * * * *public void Desplazar() *
  81.  * * * *{
  82.  
  83.  
  84.  * * * * * *
  85.  * * * *}
  86.  
  87.  
  88.  
  89.  * * * *
  90.  * *}
  91. }

Program.cs:
Código csharp:
Ver original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4.  
  5. namespace tp1_6
  6. {
  7.  * *class Program
  8.  * *{
  9.  * * * *static void Main(string[] args)
  10.  * * * *{
  11.  * * * * * *//creo los objetos vertice
  12.  * * * * * *Vertice ver1 = new Vertice(3, 6);
  13.  * * * * * *Vertice ver2 = new Vertice(3, 8);
  14.  * * * * * *Vertice ver3 = new Vertice(8, 8);
  15.  * * * * * *Vertice ver4 = new Vertice(8, 6);
  16.  
  17.  * * * * * *Rectangulo rec1 = new Rectangulo(ver1,ver2,ver3,ver4);
  18.  * * * * * *Rectangulo rec2 = new Rectangulo(9,8); * * * * *
  19.  
  20.  * * * * * *Console.WriteLine("vertices: a={0}, b={1}\n",rec1.A.X,rec1.B.X);
  21.  * * * * * *Console.ReadLine();
  22.  * * * * *
  23.  * * * *}
  24.  * *}
  25. }