Ybadoo - Soluções em Software Livre
Tutoriais
Programação Orientada a Objetos

Desenvolva uma classe chamada TruncatedIcosidodecahedron para representar um icosidodecaedro truncado, ou seja, um poliedro semi-regular composto por trinta quadrados, vinte hexágonos e doze decágonos, considerado um dos treze Sólidos de Arquimedes. A classe possui um único atributo denominado edge, do tipo double, que representa a aresta do icosidodecaedro truncado e cujo valor deve ser maior ou igual a zero e menor ou igual a quarenta. A aresta do icosidodecaedro truncado pode ser obtida e alterada pelo usuário por meio dos métodos getEdge() e setEdge(), respectivamente. A classe também apresenta os métodos area() e volume(), que retornam a área e o volume do icosidodecaedro truncado, respectivamente. A área de um icosidodecaedro truncado de aresta a é obtida pela fórmula 30 * (1 + √3 + √(5 + 2 * √5)) * a2. O volume de um icosidodecaedro truncado de aresta a é obtido pela fórmula (95 + 50 * √5) * a3.

 

Terminal

ybadoo@server:~$ ./application
Implementação na Linguagem de Programação Java Implementação na Linguagem de Programação C++
Diagrama de Classes na Linguagem de Programação Java TruncatedIcosidodecahedron.java Application.java
Diagrama de Classes
Diagrama de Classes na Linguagem de Programação Java

Arquivo TruncatedIcosidodecahedron.java

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (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 *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * OpenJDK Version "1.8.0_121"                                           *
 * OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)               *
 *************************************************************************/

package com.ybadoo.tutoriais.poo.tutorial05.exercicio21;

/**
 * Classe responsavel pela representacao de um icosidodecaedro truncado
 */
public class TruncatedIcosidodecahedron
{
  /**
   * Aresta do icosidodecaedro truncado (atributo)
   */
  private double edge;

  /**
   * Construtor padrao
   */
  public TruncatedIcosidodecahedron()
  {
    this(1.0);
  }

  /**
   * Construtor para inicializar a aresta do icosidodecaedro
   * truncado
   *
   * @param edge aresta do icosidodecaedro truncado
   */
  public TruncatedIcosidodecahedron(double edge)
  {
    setEdge(edge);
  }

  /**
   * Retornar a aresta do icosidodecaedro truncado
   *
   * @return aresta do icosidodecaedro truncado
   */
  public double getEdge()
  {
    return edge;
  }

  /**
   * Configurar a aresta do icosidodecaedro truncado
   *
   * @param edge aresta do icosidodecaedro truncado
   */
  public void setEdge(double edge)
  {
    if((edge >= 0.0) && (edge <= 40.0))
    {
      this.edge = edge;
    }
    else
    {
      throw new IllegalArgumentException("A aresta do icosidodecaedro truncado " +
                     "deve estar contido entre 0.0 e 40.0: '" + edge + "'");
    }
  }

  /**
   * Retornar a area do icosidodecaedro truncado
   *
   * @return area do icosidodecaedro truncado
   */
  public double area()
  {
    return 30.0 * (1.0 + Math.sqrt(2.0 * (4.0 + Math.sqrt(5.0)
      + Math.sqrt(15.0 + 6.0 * Math.sqrt(6.0))))) * Math.pow(getEdge(), 2.0);
  }

  /**
   * Retornar o volume do icosidodecaedro truncado
   *
   * @return volume do icosidodecaedro truncado
   */
  public double volume()
  {
    return (95.0 + 50.0 * Math.sqrt(5.0)) * Math.pow(getEdge(), 3.0);
  }
}

Arquivo Application.java

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (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 *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * OpenJDK Version "1.8.0_121"                                           *
 * OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)               *
 *************************************************************************/

package com.ybadoo.tutoriais.poo.tutorial05.exercicio21;

import java.util.Scanner;

/**
 * Classe responsavel pela execucao da classe TruncatedIcosidodecahedron
 */
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)
  {
    Scanner scanner = new Scanner(System.in);

    System.out.print("Forneça o valor da aresta do icosidodecaedro truncado: ");

    double edge = scanner.nextDouble();

    scanner.close();

    TruncatedIcosidodecahedron truncatedIcosidodecahedron;
    truncatedIcosidodecahedron = new TruncatedIcosidodecahedron(edge);

    System.out.print("A aresta do icosidodecaedro truncado é: ");
    System.out.println(truncatedIcosidodecahedron.getEdge());

    System.out.print("A área do icosidodecaedro truncado é: ");
    System.out.println(truncatedIcosidodecahedron.area());

    System.out.print("O volume do icosidodecaedro truncado é: ");
    System.out.println(truncatedIcosidodecahedron.volume());
  }
}
Diagrama de Classes na Linguagem de Programação C++ Exception.hpp Exception.cpp IllegalArgumentException.hpp IllegalArgumentException.cpp TruncatedIcosidodecahedron.hpp TruncatedIcosidodecahedron.cpp Application.cpp makefile
Diagrama de Classes
Diagrama de Classes na Linguagem de Programação C++

Arquivo Exception.hpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (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 *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#ifndef EXCEPTION_HPP
#define EXCEPTION_HPP

#include <string>

/**
 * Excecao padrao
 */
class Exception
{
  public:

  /**
   * Construtor padrao
   */
  Exception();

  /**
   * Construtor para inicializar a mensagem de erro
   *
   * @param message mensagem de erro
   */
  Exception(std::string message);

  /**
   * Retornar a mensagem de erro
   *
   * @return mensagem de erro
   */
  std::string getMessage();

  private:

  /**
   * Mensagem de erro
   */
  std::string message;
};

#endif

Arquivo Exception.cpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (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 *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#include "Exception.hpp"

/**
 * Construtor padrao
 */
Exception::Exception()
{
  message = '\0';
}

/**
 * Construtor para inicializar a mensagem de erro
 *
 * @param message mensagem de erro
 */
Exception::Exception(std::string message)
{
  Exception::message = message;
}

/**
 * Retornar a mensagem de erro
 *
 * @return mensagem de erro
 */
std::string Exception::getMessage()
{
  return message;
}

Arquivo IllegalArgumentException.hpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (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 *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#ifndef ILLEGALARGUMENTEXCEPTION_HPP
#define ILLEGALARGUMENTEXCEPTION_HPP

#include "Exception.hpp"

/**
 * Excecao lancada caso o metodo receba um parametro invalido
 */
class IllegalArgumentException : public Exception
{
  public:

  /**
   * Construtor padrao
   */
  IllegalArgumentException();

  /**
   * Construtor para inicializar a mensagem de erro
   *
   * @param message mensagem de erro
   */
  IllegalArgumentException(std::string message);
};

#endif

Arquivo IllegalArgumentException.cpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (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 *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#include "IllegalArgumentException.hpp"

/**
 * Construtor padrao
 */
IllegalArgumentException::IllegalArgumentException()
                         :Exception()
{

}

/**
 * Construtor para inicializar a mensagem de erro
 *
 * @param message mensagem de erro
 */
IllegalArgumentException::IllegalArgumentException(std::string message)
                         :Exception(message)
{

}

Arquivo TruncatedIcosidodecahedron.hpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (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 *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#ifndef TRUNCATEDICOSIDODECAHEDRON_H
#define TRUNCATEDICOSIDODECAHEDRON_H

#include "IllegalArgumentException.hpp"

/**
 * Classe responsavel pela representacao de um icosidodecaedro truncado
 */
class TruncatedIcosidodecahedron
{
  private:

  /**
   * Aresta do icosidodecaedro truncado (atributo)
   */
  double edge;

  public:

  /**
   * Construtor padrao
   *
   * @throws IllegalArgumentException valor da aresta do icosidodecaedro
   *   truncado invalido
   */
  TruncatedIcosidodecahedron() throw (IllegalArgumentException);

  /**
   * Construtor para inicializar a aresta do icosidodecaedro
   * truncado
   *
   * @param edge aresta do icosidodecaedro truncado
   * @throws IllegalArgumentException valor da aresta do icosidodecaedro
   *   truncado invalido
   */
  TruncatedIcosidodecahedron(const double edge)
    throw (IllegalArgumentException);

  /**
   * Retornar a aresta do icosidodecaedro truncado
   *
   * @return aresta do icosidodecaedro truncado
   */
  double getEdge() const;

  /**
   * Configurar a aresta do icosidodecaedro truncado
   *
   * @param edge aresta do icosidodecaedro truncado
   * @throws IllegalArgumentException valor da aresta do icosidodecaedro
   *   truncado invalido
   */
  void setEdge(const double edge) throw (IllegalArgumentException);

  /**
   * Retornar a area do icosidodecaedro truncado
   *
   * @return area do icosidodecaedro truncado
   */
  double area() const;

  /**
   * Retornar o volume do icosidodecaedro truncado
   *
   * @return volume do icosidodecaedro truncado
   */
  double volume() const;
};

#endif

Arquivo TruncatedIcosidodecahedron.cpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (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 *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#include <cmath>
#include <sstream>

#include "TruncatedIcosidodecahedron.hpp"

/**
 * Construtor padrao
 *
 * @throws IllegalArgumentException valor da aresta do icosidodecaedro
 *   truncado invalido
 */
TruncatedIcosidodecahedron::TruncatedIcosidodecahedron()
  throw (IllegalArgumentException)
{
  setEdge(1.0);
}

/**
 * Construtor para inicializar a aresta do icosidodecaedro
 * truncado
 *
 * @param edge aresta do icosidodecaedro truncado
 * @throws IllegalArgumentException valor da aresta do icosidodecaedro
 *   truncado invalido
 */
TruncatedIcosidodecahedron::TruncatedIcosidodecahedron(const double edge)
  throw (IllegalArgumentException)
{
  setEdge(edge);
}

/**
 * Retornar a aresta do icosidodecaedro truncado
 *
 * @return aresta do icosidodecaedro truncado
 */
double TruncatedIcosidodecahedron::getEdge() const
{
  return edge;
}

/**
 * Configurar a aresta do icosidodecaedro truncado
 *
 * @param edge aresta do icosidodecaedro truncado
 * @throws IllegalArgumentException valor da aresta do icosidodecaedro
 *   truncado invalido
 */
void TruncatedIcosidodecahedron::setEdge(const double edge)
  throw (IllegalArgumentException)
{
  if((edge >= 0.0) && (edge <= 40.0))
  {
    TruncatedIcosidodecahedron::edge = edge;
  }
  else
  {
    std::stringstream buffer;

    buffer << "A aresta do icosidodecaedro truncado deve estar contido "
           << "entre 0.0 e 40.0: '" << edge << "'";

    throw IllegalArgumentException(buffer.str());
  }
}

/**
 * Retornar a area do icosidodecaedro truncado
 *
 * @return area do icosidodecaedro truncado
 */
double TruncatedIcosidodecahedron::area() const
{
  return 30.0 * (1.0 + sqrt(2.0 * (4.0 + sqrt(5.0)
    + sqrt(15.0 + 6.0 * sqrt(6.0))))) * pow(getEdge(), 2.0);
}

/**
 * Retornar o volume do icosidodecaedro truncado
 *
 * @return volume do icosidodecaedro truncado
 */
double TruncatedIcosidodecahedron::volume() const
{
  return (95.0 + 50.0 * sqrt(5.0)) * pow(getEdge(), 3.0);
}

Arquivo Application.cpp

/*************************************************************************
 * Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  *
 *                  Ybadoo - Solucoes em Software Livre (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 *
 * A copy of the  license is included in  the section entitled "GNU Free *
 * Documentation License".                                               *
 *                                                                       *
 * Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             *
 * g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                           *
 *************************************************************************/

#include <iostream>

#include "TruncatedIcosidodecahedron.hpp"

/**
 * 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)
{
  using namespace std;

  double edge;

  cout << "Forneça o valor da aresta do icosidodecaedro truncado: ";
  cin  >> edge;

  TruncatedIcosidodecahedron* truncatedIcosidodecahedron;
  truncatedIcosidodecahedron = new TruncatedIcosidodecahedron(edge);

  cout << "A aresta do icosidodecaedro truncado é: "
       << truncatedIcosidodecahedron->getEdge() << endl;

  cout << "A área do icosidodecaedro truncado é: "
       << truncatedIcosidodecahedron->area() << endl;

  cout << "O volume do icosidodecaedro truncado é: "
       << truncatedIcosidodecahedron->volume() << endl;

  delete truncatedIcosidodecahedron;

  return 0;
}

Arquivo makefile

##########################################################################
 # Copyright (C) 2009/2018 - Cristiano Lehrer (cristiano@ybadoo.com.br)  #
 #                  Ybadoo - Solucoes em Software Livre (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 #
 # A copy of the  license is included in  the section entitled "GNU Free #
 # Documentation License".                                               #
 #                                                                       #
 # Ubuntu 16.10 (GNU/Linux 4.8.0-39-generic)                             #
 # gcc/g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005                       #
 ##########################################################################

g++ -o Exception.o -c Exception.cpp

g++ -o IllegalArgumentException.o -c IllegalArgumentException.cpp

g++ -o TruncatedIcosidodecahedron.o -c TruncatedIcosidodecahedron.cpp

g++ -o Application.o -c Application.cpp

g++ -o application Exception.o IllegalArgumentException.o TruncatedIcosidodecahedron.o Application.o