Desenvolva uma classe abstrata chamada Triangle
para representar um triângulo, ou seja, uma figura geométrica composta por três arestas e três vértices. A quantidade de arestas e vértices do triângulo podem ser obtidos pelo usuário por meio dos métodos getEdges()
e getVertices()
, respectivamente. A classe também apresenta o método abstrato area()
que retorna a área do triângulo.
Estenda a classe Triangle
para implementar uma classe chamada EquilateralTriangle
para representar um triângulo equilátero. A classe possui um único atributo denominado edgeA
, que representa o comprimento da aresta do triângulo equilátero, do tipo double
e cujo valor deve ser maior que zero. A classe possui um construtor que recebe como parâmetro o comprimento da aresta do triângulo equilátero. O comprimento da aresta do triângulo equilátero pode ser obtido pelo usuário por meio do método getEdgeA()
. A área de um triângulo equilátero de aresta a é obtida pela fórmula √3 / 4 * a2.
Estenda a classe EquilateralTriangle
para implementar uma classe chamada IsoscelesTriangle
para representar um triângulo isósceles. A classe possui um único atributo denominado edgeB
, que representa o comprimento da base do triângulo isósceles, do tipo double
e cujo valor deve ser maior que zero. A classe possui um construtor que recebe como parâmetro o comprimento da aresta e da base do triângulo isósceles, lembrando que os valores fornecidos devem ser distintos. O comprimento da base do triângulo isósceles pode ser obtido pelo usuário por meio do método getEdgeB()
. A área de um triângulo isósceles de aresta a e base b é obtida pela fórmula b * h / 2, onde h é obtida pela fórmula √(a2 - (b2 / 4)).
Estenda a classe IsoscelesTriangle
para implementar uma classe chamada ScaleneTriangle
para representar um triângulo escaleno. A classe possui um único atributo denominado edgeC
, que representa o comprimento da terceira aresta do triângulo escaleno, do tipo double
e cujo valor deve ser maior que zero. A classe possui um construtor que recebe como parâmetro o comprimento das três arestas do triângulo escaleno, lembrando que os valores fornecidos devem ser distintos. O comprimento da terceira aresta do triângulo escaleno pode ser obtido pelo usuário por meio do método getEdgeC()
. A área de um triângulo escaleno de arestas a, b e c é obtida pela fórmula √(s * ((s - a) + (s - b) + (s - c))), onde s é obtida pela fórmula (a + b + c) / 2.
Desenvolva uma classe chamada Shapes
para representar um catálogo de figuras geométricas, implementando os métodos para inserção e apresentação das figuras geométricas cadastradas.
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
package com.ybadoo.tutoriais.poo;
/**
* Classe responsavel pela representacao de um triangulo
*/
public abstract class Triangle
{
/**
* Retornar a quantidade de arestas do triangulo
*
* @return quantidade de arestas do triangulo
*/
public int getEdges()
{
return 3;
}
/**
* Retornar a quantidade de vertices do triangulo
*
* @return quantidade de vertices do triangulo
*/
public int getVertices()
{
return 3;
}
/**
* Retornar a area do triangulo
*
* @return area do triangulo
*/
public abstract double area();
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
package com.ybadoo.tutoriais.poo;
/**
* Classe responsavel pela representacao de um triangulo equilatero
*/
public class EquilateralTriangle extends Triangle
{
/**
* Comprimento da aresta do triangulo equilatero
*/
private double edgeA;
/**
* Construtor para inicializar o triangulo equilatero
*
* @param edgeA comprimento da aresta do triangulo equilatero
*/
public EquilateralTriangle(double edgeA)
{
if(edgeA > 0.0)
{
this.edgeA = edgeA;
}
else
{
this.edgeA = 1.0;
}
}
/**
* Retornar o comprimento da aresta do triangulo equilatero
*
* @return comprimento da aresta do triangulo equilatero
*/
public double getEdgeA()
{
return edgeA;
}
/* (non-Javadoc)
* @see com.ybadoo.tutoriais.poo.Triangle#area()
*/
public double area()
{
return Math.sqrt(3.0) / 4.0 * Math.pow(getEdgeA(), 2.0);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
StringBuilder buffer = new StringBuilder();
buffer.append("Triângulo equilátero").append("\n")
.append("Arestas: ").append(getEdges()).append("\n")
.append("Vértices: ").append(getVertices()).append("\n")
.append("Comprimento da aresta: ").append(getEdgeA()).append("\n")
.append("Área: ").append(area()).append("\n");
return buffer.toString();
}
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
package com.ybadoo.tutoriais.poo;
/**
* Classe responsavel pela representacao de um triangulo isosceles
*/
public class IsoscelesTriangle extends EquilateralTriangle
{
/**
* Comprimento da base do triangulo isosceles
*/
private double edgeB;
/**
* Construtor para inicializar o triangulo isosceles
*
* @param edgeA comprimento da aresta do triangulo isosceles
* @param edgeB comprimento da base do triangulo isosceles
*/
public IsoscelesTriangle(double edgeA, double edgeB)
{
super(edgeA);
if(edgeB > 0.0)
{
this.edgeB = edgeB;
}
else
{
this.edgeB = 1.0;
}
if(getEdgeA() == getEdgeB())
{
this.edgeB = getEdgeA() + 1.0;
}
}
/**
* Retornar o comprimento da base do triangulo isosceles
*
* @return comprimento da base do triangulo isosceles
*/
public double getEdgeB()
{
return edgeB;
}
/* (non-Javadoc)
* @see com.ybadoo.tutoriais.poo.Triangle#area()
*/
public double area()
{
double h = Math.sqrt(Math.pow(getEdgeA(), 2.0)
- (Math.pow(getEdgeB(), 2.0) / 4.0));
return getEdgeB() * h / 2.0;
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
StringBuilder buffer = new StringBuilder();
buffer.append("Triângulo isósceles").append("\n")
.append("Arestas: ").append(getEdges()).append("\n")
.append("Vértices: ").append(getVertices()).append("\n")
.append("Comprimento da aresta: ").append(getEdgeA()).append("\n")
.append("Comprimento da base: ").append(getEdgeB()).append("\n")
.append("Área: ").append(area()).append("\n");
return buffer.toString();
}
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
package com.ybadoo.tutoriais.poo;
/**
* Classe responsavel pela representacao de um triangulo escaleno
*/
public class ScaleneTriangle extends IsoscelesTriangle
{
/**
* Comprimento da aresta C do triangulo escaleno
*/
private double edgeC;
/**
* Construtor para inicializar o triangulo escaleno
*
* @param edgeA comprimento da aresta A do triangulo escaleno
* @param edgeB comprimento da aresta B do triangulo escaleno
* @param edgeC comprimento da aresta C do triangulo escaleno
*/
public ScaleneTriangle(double edgeA, double edgeB, double edgeC)
{
super(edgeA, edgeB);
if(edgeC > 0.0)
{
this.edgeC = edgeC;
}
else
{
this.edgeC = 1.0;
}
if(getEdgeA() == getEdgeC())
{
this.edgeC = getEdgeA() + 1.0;
}
if(getEdgeB() == getEdgeC())
{
this.edgeC = getEdgeB() + 1.0;
}
if(getEdgeA() == getEdgeC())
{
this.edgeC = getEdgeA() + 1.0;
}
}
/**
* Retornar o comprimento da aresta C do triangulo escaleno
*
* @return comprimento da aresta C do triangulo escaleno
*/
public double getEdgeC()
{
return edgeC;
}
/* (non-Javadoc)
* @see com.ybadoo.tutoriais.poo.Triangle#area()
*/
public double area()
{
double s = (getEdgeA() + getEdgeB() + getEdgeC()) / 2.0;
return Math.sqrt(s * ((s - getEdgeA()) + (s - getEdgeB())
+ (s - getEdgeC())));
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
StringBuilder buffer = new StringBuilder();
buffer.append("Triângulo escaleno")
.append("\nArestas: ").append(getEdges())
.append("\nVértices: ").append(getVertices())
.append("\nComprimento da aresta A: ").append(getEdgeA())
.append("\nComprimento da aresta B: ").append(getEdgeB())
.append("\nComprimento da aresta C: ").append(getEdgeC())
.append("\nÁrea: ").append(area()).append("\n");
return buffer.toString();
}
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
package com.ybadoo.tutoriais.poo;
import java.util.ArrayList;
import java.util.List;
/**
* Classe responsavel pela representacao de um catalogo de figuras
* geometricas
*/
public class Shapes
{
/**
* Figuras geometricas
*/
private List<Triangle> geometricFigures;
/**
* Construtor padrao
*/
public Shapes()
{
geometricFigures = new ArrayList<Triangle>();
}
/**
* Adicionar a figura geometrica ao catalogo
*
* @param shape figura geometrica a ser adicionado ao catalogo
*/
public void add(Triangle shape)
{
geometricFigures.add(shape);
}
/**
* Remover a figura geometrica ao catalogo
*
* @param shape figura geometrica a ser removida do catalogo
*/
public void remove(Triangle shape)
{
geometricFigures.remove(shape);
}
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
public String toString()
{
StringBuilder buffer = new StringBuilder();
for(Triangle shape: geometricFigures)
{
buffer.append(shape).append("\n");
}
return buffer.toString();
}
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
package com.ybadoo.tutoriais.poo;
/**
* Classe responsavel pela execucao da classe Transport
*/
public class Application
{
/**
* Metodo principal da linguagem de programacao Java
*
* @param args argumentos da linha de comando (nao utilizado)
*/
public static void main(String[] args)
{
Shapes shape = new Shapes();
EquilateralTriangle equilateral = new EquilateralTriangle(3);
shape.add(equilateral);
IsoscelesTriangle isosceles = new IsoscelesTriangle(3, 4);
shape.add(isosceles);
ScaleneTriangle scalene = new ScaleneTriangle(3, 4, 5);
shape.add(scalene);
System.out.println(shape);
}
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include <string>
using namespace std;
#ifndef TRIANGLE_H
#define TRIANGLE_H
/**
* Classe responsavel pela representacao de um triangulo
*/
class Triangle
{
public:
/**
* Retornar a quantidade de arestas do triangulo
*
* @return quantidade de arestas do triangulo
*/
int getEdges();
/**
* Retornar a quantidade de vertices do triangulo
*
* @return quantidade de vertices do triangulo
*/
int getVertices();
/**
* Retornar a area do triangulo
*
* @return area do triangulo
*/
virtual double area() = 0;
/*
* Retornar o objeto Triangle como um texto
*
* @return objeto Triangle como um texto
*/
virtual string toString() = 0;
};
#endif
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include "Triangle.h"
/**
* Retornar a quantidade de arestas do triangulo
*
* @return quantidade de arestas do triangulo
*/
int Triangle::getEdges()
{
return 3;
}
/**
* Retornar a quantidade de vertices do triangulo
*
* @return quantidade de vertices do triangulo
*/
int Triangle::getVertices()
{
return 3;
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include <string>
#include "Triangle.h"
using namespace std;
#ifndef EQUILATERALTRIANGLE_H
#define EQUILATERALTRIANGLE_H
/**
* Classe responsavel pela representacao de um triangulo equilatero
*/
class EquilateralTriangle : public Triangle
{
private:
/**
* Comprimento da aresta do triangulo equilatero
*/
double edgeA;
public:
/**
* Construtor para inicializar o triangulo equilatero
*
* @param edgeA comprimento da aresta do triangulo equilatero
*/
EquilateralTriangle(double edgeA);
/**
* Retornar o comprimento da aresta do triangulo equilatero
*
* @return comprimento da aresta do triangulo equilatero
*/
double getEdgeA();
/*
* Retornar a area do triangulo equilatero
*
* @return area do triangulo equilatero
*/
double area();
/*
* Retornar o objeto EquilateralTriangle como um texto
*
* @return objeto EquilateralTriangle como um texto
*/
string toString();
};
#endif
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include <cmath>
#include <sstream>
#include "EquilateralTriangle.h"
using namespace std;
/**
* Construtor para inicializar o triangulo equilatero
*
* @param edgeA comprimento da aresta do triangulo equilatero
*/
EquilateralTriangle::EquilateralTriangle(double edgeA)
{
if(edgeA > 0.0)
{
EquilateralTriangle::edgeA = edgeA;
}
else
{
EquilateralTriangle::edgeA = 1.0;
}
}
/**
* Retornar o comprimento da aresta do triangulo equilatero
*
* @return comprimento da aresta do triangulo equilatero
*/
double EquilateralTriangle::getEdgeA()
{
return edgeA;
}
/*
* Retornar a area do triangulo equilatero
*
* @return area do triangulo equilatero
*/
double EquilateralTriangle::area()
{
return sqrt(3.0) / 4.0 * pow(getEdgeA(), 2.0);
}
/*
* Retornar o objeto EquilateralTriangle como um texto
*
* @return objeto EquilateralTriangle como um texto
*/
string EquilateralTriangle::toString()
{
stringstream buffer;
buffer << "Triângulo equilátero\n";
buffer << "Arestas: " << getEdges() << "\n";
buffer << "Vértices: " << getVertices() << "\n";
buffer << "Comprimento da aresta: " << getEdgeA() << "\n";
buffer << "Área: " << area() << "\n";
return buffer.str();
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include <string>
#include "EquilateralTriangle.h"
using namespace std;
#ifndef ISOSCELESTRIANGLE_H
#define ISOSCELESTRIANGLE_H
/**
* Classe responsavel pela representacao de um triangulo isosceles
*/
class IsoscelesTriangle : public EquilateralTriangle
{
private:
/**
* Comprimento da base do triangulo isosceles
*/
double edgeB;
public:
/**
* Construtor para inicializar o triangulo isosceles
*
* @param edgeA comprimento da aresta do triangulo isosceles
* @param edgeB comprimento da base do triangulo isosceles
*/
IsoscelesTriangle(double edgeA, double edgeB);
/**
* Retornar o comprimento da base do triangulo isosceles
*
* @return comprimento da base do triangulo isosceles
*/
double getEdgeB();
/*
* Retornar a area do triangulo isosceles
*
* @return area do triangulo isosceles
*/
double area();
/*
* Retornar o objeto IsoscelesTriangle como um texto
*
* @return objeto IsoscelesTriangle como um texto
*/
string toString();
};
#endif
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include <cmath>
#include <sstream>
#include "IsoscelesTriangle.h"
using namespace std;
/**
* Construtor para inicializar o triangulo isosceles
*
* @param edgeA comprimento da aresta do triangulo isosceles
* @param edgeB comprimento da base do triangulo isosceles
*/
IsoscelesTriangle::IsoscelesTriangle(double edgeA, double edgeB)
: EquilateralTriangle(edgeA)
{
if(edgeB > 0.0)
{
IsoscelesTriangle::edgeB = edgeB;
}
else
{
IsoscelesTriangle::edgeB = 1.0;
}
if(getEdgeA() == getEdgeB())
{
IsoscelesTriangle::edgeB = getEdgeA() + 1.0;
}
}
/**
* Retornar o comprimento da base do triangulo isosceles
*
* @return comprimento da base do triangulo isosceles
*/
double IsoscelesTriangle::getEdgeB()
{
return edgeB;
}
/*
* Retornar a area do triangulo isosceles
*
* @return area do triangulo isosceles
*/
double IsoscelesTriangle::area()
{
double h = sqrt(pow(getEdgeA(), 2.0) - (pow(getEdgeB(), 2.0) / 4.0));
return getEdgeB() * h / 2.0;
}
/*
* Retornar o objeto IsoscelesTriangle como um texto
*
* @return objeto IsoscelesTriangle como um texto
*/
string IsoscelesTriangle::toString()
{
stringstream buffer;
buffer << "Triângulo isósceles\n";
buffer << "Arestas: " << getEdges() << "\n";
buffer << "Vértices: " << getVertices() << "\n";
buffer << "Comprimento da aresta: " << getEdgeA() << "\n";
buffer << "Comprimento da base: " << getEdgeB() << "\n";
buffer << "Área: " << area() << "\n";
return buffer.str();
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include <string>
#include "IsoscelesTriangle.h"
using namespace std;
#ifndef SCALENETRIANGLE_H
#define SCALENETRIANGLE_H
/**
* Classe responsavel pela representacao de um triangulo escaleno
*/
class ScaleneTriangle : public IsoscelesTriangle
{
private:
/**
* Comprimento da aresta C do triangulo escaleno
*/
double edgeC;
public:
/**
* Construtor para inicializar o triangulo escaleno
*
* @param edgeA comprimento da aresta A do triangulo escaleno
* @param edgeB comprimento da aresta B do triangulo escaleno
* @param edgeC comprimento da aresta C do triangulo escaleno
*/
ScaleneTriangle(double edgeA, double edgeB, double edgeC);
/**
* Retornar o comprimento da aresta C do triangulo escaleno
*
* @return comprimento da aresta C do triangulo escaleno
*/
double getEdgeC();
/*
* Retornar a area do triangulo escaleno
*
* @return area do triangulo escaleno
*/
double area();
/*
* Retornar o objeto ScaleneTriangle como um texto
*
* @return objeto ScaleneTriangle como um texto
*/
string toString();
};
#endif
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include <cmath>
#include <sstream>
#include "ScaleneTriangle.h"
using namespace std;
/**
* Construtor para inicializar o triangulo escaleno
*
* @param edgeA comprimento da aresta A do triangulo escaleno
* @param edgeB comprimento da aresta B do triangulo escaleno
* @param edgeC comprimento da aresta C do triangulo escaleno
*/
ScaleneTriangle::ScaleneTriangle(double edgeA, double edgeB, double edgeC)
:IsoscelesTriangle(edgeA, edgeB)
{
if(edgeC > 0.0)
{
ScaleneTriangle::edgeC = edgeC;
}
else
{
ScaleneTriangle::edgeC = 1.0;
}
if(getEdgeA() == getEdgeC())
{
ScaleneTriangle::edgeC = getEdgeA() + 1.0;
}
if(getEdgeB() == getEdgeC())
{
ScaleneTriangle::edgeC = getEdgeB() + 1.0;
}
if(getEdgeA() == getEdgeC())
{
ScaleneTriangle::edgeC = getEdgeA() + 1.0;
}
}
/**
* Retornar o comprimento da aresta C do triangulo escaleno
*
* @return comprimento da aresta C do triangulo escaleno
*/
double ScaleneTriangle::getEdgeC()
{
return edgeC;
}
/*
* Retornar a area do triangulo escaleno
*
* @return area do triangulo escaleno
*/
double ScaleneTriangle::area()
{
double s = (getEdgeA() + getEdgeB() + getEdgeC()) / 2.0;
return sqrt(s * ((s - getEdgeA()) + (s - getEdgeB()) + (s - getEdgeC())));
}
/*
* Retornar o objeto ScaleneTriangle como um texto
*
* @return objeto ScaleneTriangle como um texto
*/
string ScaleneTriangle::toString()
{
stringstream buffer;
buffer << "Triângulo escaleno\n";
buffer << "Arestas: " << getEdges() << "\n";
buffer << "Vértices: " << getVertices() << "\n";
buffer << "Comprimento da aresta A: " << getEdgeA() << "\n";
buffer << "Comprimento da aresta B: " << getEdgeB() << "\n";
buffer << "Comprimento da aresta C: " << getEdgeC() << "\n";
buffer << "Área: " << area() << "\n";
return buffer.str();
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include "Triangle.h"
#ifndef NODE_H
#define NODE_H
/**
* Classe responsavel pela representacao de um nodo na lista
*/
class Node
{
private:
/**
* Elemento do nodo
*/
Triangle* element;
/**
* Proximo nodo da lista
*/
Node* next;
public:
/**
* Construtor para inicializar o elemento do nodo
*
* @param element elemento do nodo
*/
Node(Triangle* element);
/**
* Retornar o elemento do nodo
*
* @return elemento do nodo
*/
Triangle* getElement();
/**
* Retornar o proximo nodo da lista
*
* @return proximo nodo da lista
*/
Node* getNext();
/**
* Configurar o proximo nodo da lista
*
* @param next proximo nodo da lista
*/
void setNext(Node* next);
};
#endif
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include <cstdlib>
#include "Node.h"
/**
* Construtor para inicializar o elemento do nodo
*
* @param element elemento do nodo
*/
Node::Node(Triangle* element)
{
Node::element = element;
Node::next = NULL;
}
/**
* Retornar o elemento do nodo
*
* @return elemento do nodo
*/
Triangle* Node::getElement()
{
return element;
}
/**
* Retornar o proximo nodo da lista
*
* @return proximo nodo da lista
*/
Node* Node::getNext()
{
return next;
}
/**
* Configurar o proximo nodo da lista
*
* @param next proximo nodo da lista
*/
void Node::setNext(Node* next)
{
Node::next = next;
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include <string>
#include "Node.h"
using namespace std;
#ifndef SHAPES_H
#define SHAPES_H
/**
* Classe responsavel pela representacao de um catalogo de figuras
* geometricas
*/
class Shapes
{
private:
/**
* Figuras geometricas
*/
Node* geometricFigures;
public:
/**
* Construtor padrao
*/
Shapes();
/**
* Destrutor padrao
*/
~Shapes();
/**
* Adicionar a figura geometrica ao catalogo
*
* @param shape figura geometrica a ser adicionado ao catalogo
*/
void add(Triangle* shape);
/*
* Retornar o objeto Shapes como um texto
*
* @return objeto Shapes como um texto
*/
string toString();
};
#endif
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include <cstdlib>
#include <sstream>
#include "Shapes.h"
using namespace std;
/**
* Construtor padrao
*/
Shapes::Shapes()
{
geometricFigures = NULL;
}
/**
* Destrutor padrao
*/
Shapes::~Shapes()
{
while(geometricFigures != NULL)
{
Node* node = geometricFigures;
geometricFigures = geometricFigures->getNext();
free(node);
}
}
/**
* Adicionar a figura geometrica ao catalogo
*
* @param shape figura geometrica a ser adicionado ao catalogo
*/
void Shapes::add(Triangle* shape)
{
if(geometricFigures == NULL)
{
geometricFigures = new Node(shape);
}
else
{
Node* node = geometricFigures;
while(node->getNext() != NULL)
{
node = node->getNext();
}
node->setNext(new Node(shape));
}
}
/*
* Retornar o objeto Shapes como um texto
*
* @return objeto Shapes como um texto
*/
string Shapes::toString()
{
Node* node = geometricFigures;
stringstream buffer;
while(node != NULL)
{
string element = node->getElement()->toString();
buffer << element << "\n";
node = node->getNext();
}
return buffer.str();
}
/**
* Copyright (C) 2009/2023 - Cristiano Lehrer (cristiano@ybadoo.com.br)
* Ybadoo - Solucoes em Software Livre (www.ybadoo.com.br)
*
* Permission is granted to copy, distribute and/or modify this document
* under the terms of the GNU Free Documentation License, Version 1.3
* or any later version published by the Free Software Foundation; with
* no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
* A copy of the license is included in the section entitled "GNU
* Free Documentation License".
*/
#include <iostream>
#include "ScaleneTriangle.h"
#include "Shapes.h"
using namespace std;
/**
* Metodo principal da linguagem de programacao C++
*
* @param argc quantidade de argumentos na linha de comando (nao utilizado)
* @param argv argumentos da linha de comando (nao utilizado)
*/
int main(int argc, char** argv)
{
Shapes* shape = new Shapes();
EquilateralTriangle* equilateral = new EquilateralTriangle(3);
shape->add(equilateral);
IsoscelesTriangle* isosceles = new IsoscelesTriangle(3, 4);
shape->add(isosceles);
ScaleneTriangle* scalene = new ScaleneTriangle(3, 4, 5);
shape->add(scalene);
cout << shape->toString() << endl;
delete shape;
return 0;
}