Desenvolva uma classe chamada Cuboctahedron
para representar um cuboctaedro, ou seja, um poliedro semi-regular composto por oito faces triangulares e seis faces quadradas, considerado um dos treze Sólidos de Arquimedes. A classe possui um único atributo denominado edge
, do tipo double
, que representa a aresta do cuboctaedro e cujo valor deve ser maior ou igual a zero e menor ou igual a quarenta. A classe possui dois construtores: o primeiro configura a aresta do cuboctaedro com o valor padrão 1.0
, e o segundo recebe como parâmetro a aresta do cuboctaedro. A aresta do cuboctaedro 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 cuboctaedro, respectivamente. A área de um cuboctaedro de aresta a é obtida pela fórmula (6 + 2 * √3) * a2. O volume de um cuboctaedro de aresta a é obtido pela fórmula 5 / 3 * √2 * a3.
/*************************************************************************
* Copyright (C) 2009/2025 - 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.tutorial02.exercicio16;
/**
* Classe responsavel pela representacao de um cuboctaedro
*/
public class Cuboctahedron
{
/**
* Aresta do cuboctaedro
*/
private double edge;
/**
* Construtor para inicializar o cuboctaedro
*/
public Cuboctahedron()
{
this(1.0);
}
/**
* Construtor para inicializar a aresta do cuboctaedro
*
* @param edge aresta do cuboctaedro
*/
public Cuboctahedron(double edge)
{
setEdge(edge);
}
/**
* Retornar a aresta do cuboctaedro
*
* @return aresta do cuboctaedro
*/
public double getEdge()
{
return edge;
}
/**
* Configurar a aresta do cuboctaedro
*
* @param edge aresta do cuboctaedro
*/
public void setEdge(double edge)
{
if((edge >= 0.0) && (edge <= 40.0))
{
this.edge = edge;
}
else
{
if(edge > 40.0)
{
this.edge = 40.0;
}
else
{
this.edge = 0.0;
}
}
}
/**
* Retornar a area do cuboctaedro
*
* @return area do cuboctaedro
*/
public double area()
{
return (6.0 + 2.0 * Math.sqrt(3.0)) * Math.pow(edge, 2.0);
}
/**
* Retornar o volume do cuboctaedro
*
* @return volume do cuboctaedro
*/
public double volume()
{
return 5.0 / 3.0 * Math.sqrt(2.0) * Math.pow(edge, 3.0);
}
}
/*************************************************************************
* Copyright (C) 2009/2025 - 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.tutorial02.exercicio16;
import java.util.Scanner;
/**
* Classe responsavel pela execucao da classe Cuboctahedron
*/
public class Application
{
/**
* Construtor para inicializar a execucao da classe Cuboctahedron
*/
private 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 cuboctaedro: ");
double edge = scanner.nextDouble();
scanner.close();
Cuboctahedron cuboctahedron = new Cuboctahedron(edge);
System.out.print("A aresta do cuboctaedro é: ");
System.out.println(cuboctahedron.getEdge());
System.out.print("A área do cuboctaedro é: ");
System.out.println(cuboctahedron.area());
System.out.print("O volume do cuboctaedro é: ");
System.out.println(cuboctahedron.volume());
}
}
/*************************************************************************
* Copyright (C) 2009/2025 - 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 CUBOCTAHEDRON_HPP
#define CUBOCTAHEDRON_HPP
/**
* Classe responsavel pela representacao de um cuboctaedro
*/
class Cuboctahedron
{
public:
/**
* Construtor para inicializar o cuboctaedro
*/
Cuboctahedron();
/**
* Construtor para inicializar a aresta do cuboctaedro
*
* @param edge aresta do cuboctaedro
*/
Cuboctahedron(const double edge);
/**
* Retornar a aresta do cuboctaedro
*
* @return aresta do cuboctaedro
*/
double getEdge() const;
/**
* Configurar a aresta do cuboctaedro
*
* @param edge aresta do cuboctaedro
*/
void setEdge(const double edge);
/**
* Retornar a area do cuboctaedro
*
* @return area do cuboctaedro
*/
double area() const;
/**
* Retornar o volume do cuboctaedro
*
* @return volume do cuboctaedro
*/
double volume() const;
private:
/**
* Aresta do cuboctaedro
*/
double edge;
};
#endif
/*************************************************************************
* Copyright (C) 2009/2025 - 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 "Cuboctahedron.hpp"
/**
* Construtor para inicializar o cuboctaedro
*/
Cuboctahedron::Cuboctahedron()
{
setEdge(1.0);
}
/**
* Construtor para inicializar a aresta do cuboctaedro
*
* @param edge aresta do cuboctaedro
*/
Cuboctahedron::Cuboctahedron(const double edge)
{
setEdge(edge);
}
/**
* Retornar a aresta do cuboctaedro
*
* @return aresta do cuboctaedro
*/
double Cuboctahedron::getEdge() const
{
return edge;
}
/**
* Configurar a aresta do cuboctaedro
*
* @param edge aresta do cuboctaedro
*/
void Cuboctahedron::setEdge(const double edge)
{
if((edge >= 0.0) && (edge <= 40.0))
{
Cuboctahedron::edge = edge;
}
else
{
if(edge > 40.0)
{
Cuboctahedron::edge = 40.0;
}
else
{
Cuboctahedron::edge = 0.0;
}
}
}
/**
* Retornar a area do cuboctaedro
*
* @return area do cuboctaedro
*/
double Cuboctahedron::area() const
{
return (6.0 + 2.0 * sqrt(3.0)) * pow(edge, 2.0);
}
/**
* Retornar o volume do cuboctaedro
*
* @return volume do cuboctaedro
*/
double Cuboctahedron::volume() const
{
return 5.0 / 3.0 * sqrt(2.0) * pow(edge, 3.0);
}
/*************************************************************************
* Copyright (C) 2009/2025 - 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 "Cuboctahedron.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 cuboctaedro: ";
cin >> edge;
Cuboctahedron* cuboctahedron = new Cuboctahedron(edge);
cout << "A aresta do cuboctaedro é: "
<< cuboctahedron->getEdge() << endl;
cout << "A área do cuboctaedro é: "
<< cuboctahedron->area() << endl;
cout << "O volume do cuboctaedro é: "
<< cuboctahedron->volume() << endl;
delete cuboctahedron;
return 0;
}
##########################################################################
# Copyright (C) 2009/2025 - 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 Cuboctahedron.o -c Cuboctahedron.cpp
g++ -o Application.o -c Application.cpp
g++ -o application Cuboctahedron.o Application.o