Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <cstdlib>
- #include <ctime>
- using namespace System;
- using namespace std;
- #pragma region Esfera
- class Esfera
- {
- private:
- int radio;
- public:
- //Estableciomiento de constructores y metodos
- Esfera();
- Esfera(int radio);
- void setradio(int rad);
- int getradio();
- float volumen();
- float area();
- ~Esfera();
- };
- //Constructor
- Esfera::Esfera()
- {
- this->radio = 0;
- }
- Esfera::Esfera(int rad)
- {
- this->radio = rad;
- }
- //Metodos GET & SET
- void Esfera::setradio(int rad)
- {
- this->radio = rad;
- }
- int Esfera::getradio()
- {
- return this->radio;
- }
- float Esfera::volumen()
- {
- float volumen = (4 / 3) * 3.1416 * pow(radio, 3);
- return volumen;
- }
- float Esfera::area()
- {
- float area = 3.1416 * pow(radio, 2);
- return area;
- }
- void esfera()
- {
- Esfera *f;
- f = new Esfera(10);
- Esfera *f1 = new Esfera;
- //usar metodo de servicio
- f1->setradio(10);
- cout << "Esfera 1: " << f1->getradio() << endl;
- cout << "Area de Esfera 1: " << f1->area() << endl;
- cout << "Volumen de Esfera 1: " << f1->volumen() << endl;
- cout << endl;
- }
- Esfera::~Esfera() {}
- #pragma endregion
- #pragma region Cono
- class Cono
- {
- private:
- int radio1;
- int generatriz;
- int altura;
- public:
- Cono();
- Cono(int radio1);
- void setgen(int generatriz);
- int getgen();
- void setaltura(int altura);
- int getaltura();
- void setradio1(int rad1);
- int getradio1();
- double vol();
- double are1();
- double are2();
- double aretot();
- ~Cono();
- };
- Cono::Cono()
- {
- this->radio1 = 0;
- }
- Cono::Cono(int rad1)
- {
- this->radio1 = rad1;
- }
- void Cono::setgen(int gen1)
- {
- this->generatriz = gen1;
- }
- int Cono::getgen()
- {
- return this->generatriz;
- }
- void Cono::setaltura(int alt)
- {
- this->altura = alt;
- }
- int Cono::getaltura()
- {
- return this->altura;
- }
- void Cono::setradio1(int rad1)
- {
- this->radio1 = rad1;
- }
- int Cono::getradio1()
- {
- return this->radio1;
- }
- double Cono::are1()
- {
- double ar = 3.1416 * pow(radio1, 2);
- return ar;
- }
- double Cono::are2()
- {
- double are = 3.1416 * radio1 * generatriz;
- return are;
- }
- double Cono::aretot()
- {
- double areatotal = are1() + are2();
- return areatotal;
- }
- double Cono::vol()
- {
- double volum = (3.1416 * radio1 * altura) / 3;
- return volum;
- }
- void cono()
- {
- Cono *c;
- c = new Cono(15);
- Cono *c1 = new Cono;
- c1->setradio1(18);
- c1->setgen(16);
- c1->setaltura(20);
- cout << "Cono: " << c1->getradio1() << endl;
- cout << "Area: " << c1->aretot() << endl;
- cout << "Volumen: " << c1->vol() << endl;
- cout << endl;
- }
- Cono::~Cono() {}
- #pragma endregion
- #pragma region movimiento
- class Ccaracter
- {
- private:
- int x; int y; int dx;
- int dy; char c; int coordX;
- int coordY;
- public:
- Ccaracter();
- void set_x(int valor);
- int get_x();
- void set_y(int valor);
- int get_y();
- void set_dx(int valor);
- int get_dx();
- void set_dy(int valor);
- int get_dy();
- void set_c(char valor);
- char get_c();
- void set_find(int coordX, int coordY);
- ~Ccaracter();
- };
- Ccaracter::Ccaracter()
- {
- this-> x = 0;
- this-> y = 0;
- this-> dx = 1;
- this-> dy = 1;
- this-> c = 219;
- this->coordX = 0;
- this->coordY = 0;
- }
- void Ccaracter::set_x(int valor)
- {
- this-> x = valor;
- }
- int Ccaracter::get_x()
- {
- return x;
- }
- void Ccaracter::set_y(int valor)
- {
- this-> y = valor;
- }
- int Ccaracter::get_y()
- {
- return y;
- }
- void Ccaracter::set_dx(int valor)
- {
- this-> dx = valor;
- }
- int Ccaracter::get_dx()
- {
- return dx;
- }
- void Ccaracter::set_dy(int valor)
- {
- this-> dy = valor;
- }
- int Ccaracter::get_dy()
- {
- return dy;
- }
- void Ccaracter::set_c(char valor)
- {
- this-> c = valor;
- }
- char Ccaracter::get_c()
- {
- return c;
- }
- void Ccaracter::set_find(int coordX, int coordY)
- {
- Console::SetCursorPosition(coordX, coordY);
- }
- void mover()
- {
- Console::SetCursorPosition(70, 20);
- Ccaracter *objeto = new Ccaracter();
- srand(time(NULL));
- objeto->set_x(5 + rand() % 10 + 1 - 5);
- objeto->set_y(5 + rand() % 10 + 1 - 5);
- while (1)
- {
- objeto->set_find(objeto->get_x(), objeto-> get_y());
- cout << (char)objeto->get_c();
- _sleep(100);
- objeto->set_find(objeto->get_x(), objeto->get_y());
- cout << " ";
- if (objeto->get_x() > 78)
- {
- objeto->set_dx(objeto->get_dx()* -1);
- }
- if (objeto->get_x() == 1)
- {
- objeto->set_dx(objeto->get_dx()* -1);
- }
- objeto->set_x(objeto->get_x() + objeto->get_dx());
- }
- }
- Ccaracter::~Ccaracter() {}
- #pragma endregion
- int main()
- {
- int c;
- cout << "Ingrese opcion: ";
- cin >> c;
- cout << endl;
- switch (c)
- {
- case 1: esfera();
- _getch();
- system("cls");
- return main();
- break;
- case 2: cono();
- _getch();
- system("cls");
- return main();
- break;
- case 3: mover();
- _getch();
- system("cls");
- return main();
- break;
- default:break;
- }
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement