-------------
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
using System; using System.Collections.Generic; using System.Text; namespace tp1_6 { * *public class Vertice * *{ * * * *private int x; * * * *private int y; * * * *// constructor del vertice * * * *public Vertice(int n1, int n2) * * * *{ * * * * * *this.x = n1; * * * * * *this.y = n2; * * * *} * * * *// las propiedades X e Y * * * *public int X * * * *{ * * * * * *set { x = value; } * * * * * *get { return x; } * * * *} * * * *public int Y * * * *{ * * * * * *set { y = value; } * * * * * *get { return y; } * * * *} * *} }
clase rectangulo:
Código csharp:
Ver original
using System; using System.Collections.Generic; using System.Text; namespace tp1_6 { * *public class Rectangulo * *{ * * * *private Vertice a; * * * *private Vertice b; * * * *private Vertice c; * * * *private Vertice d; * * * *private int altura; * * * *private int bace; * * * *//constructor a partir de los 4 vertices * * * *public Rectangulo(Vertice v1, Vertice v2, Vertice v3, Vertice v4) * * * *{ * * * * * *this.A = v1; * * * * * *this.B = v2; * * * * * *this.c = v3; * * * * * *this.d = v4; * * * *} * * * * * *//constructor a partir de base y altura * * * *public Rectangulo(int ba,int alt) * * * *{ * * * *} * * * *//----------------propiedades de base y altura------------ * * * *public int Altura * * * *{ * * * * * *set { altura = value; } * * * * * *get { return altura; } * * * *} * * * *public int Bace * * * *{ * * * * * *set { bace = value; } * * * * * *get { return bace; } * * * *} * * * * * * * *//----------------propiedades de los vertices------------------------ * * * *public Vertice A * * * *{ * * * * * *set { a = value; } * * * * * *get { return a; } * * * *} * * * *public Vertice B * * * *{ * * * * * *set { b = value; } * * * * * *get { return b; } * * * *} * * * *public Vertice C * * * *{ * * * * * *set { c = value; } * * * * * *get { return c; } * * * *} * * * *public Vertice D * * * *{ * * * * * *set { d = value; } * * * * * *get { return d; } * * * *} * * * *//--------metodo q saca la superficie-------- * * * *public int Superficie() * * * *{ * * * * * *return (this.d.X - this.a.X) * (this.b.Y - this.a.Y); * * * *} * * * * * * * *//---------metodo perimetro---------- * * * *public int Perimetro() * * * *{ * * * * * *return (((this.d.X - this.a.X) * 2) + ((this.b.Y - this.a.Y) * 2)); * * * *} * * * * * * * *//-------metodo desplazar-------- * * * *public void Desplazar() * * * * *{ * * * * * * * * * *} * * * * * *} }
Program.cs:
Código csharp:
Ver original
using System; using System.Collections.Generic; using System.Text; namespace tp1_6 { * *class Program * *{ * * * *static void Main(string[] args) * * * *{ * * * * * *//creo los objetos vertice * * * * * *Console.WriteLine("vertices: a={0}, b={1}\n",rec1.A.X,rec1.B.X); * * * * * *Console.ReadLine(); * * * * * * * * *} * *} }