Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3. #include <cstdlib>
  4. #include <ctime>
  5.  
  6. using namespace System;
  7. using namespace std;
  8.  
  9. #pragma region Esfera
  10. class Esfera
  11. {
  12. private:
  13. int radio;
  14. public:
  15. //Estableciomiento de constructores y metodos
  16. Esfera();
  17. Esfera(int radio);
  18.  
  19. void setradio(int rad);
  20. int getradio();
  21.  
  22. float volumen();
  23. float area();
  24.  
  25. ~Esfera();
  26. };
  27.  
  28. //Constructor
  29.  
  30. Esfera::Esfera()
  31. {
  32. this->radio = 0;
  33. }
  34.  
  35. Esfera::Esfera(int rad)
  36. {
  37. this->radio = rad;
  38. }
  39.  
  40. //Metodos GET & SET
  41.  
  42. void Esfera::setradio(int rad)
  43. {
  44. this->radio = rad;
  45. }
  46.  
  47. int Esfera::getradio()
  48. {
  49. return this->radio;
  50. }
  51.  
  52. float Esfera::volumen()
  53. {
  54. float volumen = (4 / 3) * 3.1416 * pow(radio, 3);
  55. return volumen;
  56. }
  57.  
  58. float Esfera::area()
  59. {
  60. float area = 3.1416 * pow(radio, 2);
  61. return area;
  62. }
  63.  
  64. void esfera()
  65. {
  66. Esfera *f;
  67. f = new Esfera(10);
  68. Esfera *f1 = new Esfera;
  69.  
  70. //usar metodo de servicio
  71. f1->setradio(10);
  72. cout << "Esfera 1: " << f1->getradio() << endl;
  73. cout << "Area de Esfera 1: " << f1->area() << endl;
  74. cout << "Volumen de Esfera 1: " << f1->volumen() << endl;
  75. cout << endl;
  76. }
  77.  
  78. Esfera::~Esfera() {}
  79. #pragma endregion
  80.  
  81. #pragma region Cono
  82. class Cono
  83. {
  84. private:
  85. int radio1;
  86. int generatriz;
  87. int altura;
  88. public:
  89. Cono();
  90. Cono(int radio1);
  91.  
  92. void setgen(int generatriz);
  93. int getgen();
  94. void setaltura(int altura);
  95. int getaltura();
  96. void setradio1(int rad1);
  97. int getradio1();
  98.  
  99. double vol();
  100. double are1();
  101. double are2();
  102. double aretot();
  103.  
  104. ~Cono();
  105. };
  106.  
  107. Cono::Cono()
  108. {
  109. this->radio1 = 0;
  110. }
  111.  
  112. Cono::Cono(int rad1)
  113. {
  114. this->radio1 = rad1;
  115. }
  116.  
  117. void Cono::setgen(int gen1)
  118. {
  119. this->generatriz = gen1;
  120. }
  121.  
  122. int Cono::getgen()
  123. {
  124. return this->generatriz;
  125. }
  126.  
  127. void Cono::setaltura(int alt)
  128. {
  129. this->altura = alt;
  130. }
  131.  
  132. int Cono::getaltura()
  133. {
  134. return this->altura;
  135. }
  136.  
  137. void Cono::setradio1(int rad1)
  138. {
  139. this->radio1 = rad1;
  140. }
  141.  
  142. int Cono::getradio1()
  143. {
  144. return this->radio1;
  145. }
  146.  
  147. double Cono::are1()
  148. {
  149. double ar = 3.1416 * pow(radio1, 2);
  150. return ar;
  151. }
  152.  
  153. double Cono::are2()
  154. {
  155. double are = 3.1416 * radio1 * generatriz;
  156. return are;
  157. }
  158.  
  159. double Cono::aretot()
  160. {
  161. double areatotal = are1() + are2();
  162. return areatotal;
  163. }
  164.  
  165. double Cono::vol()
  166. {
  167. double volum = (3.1416 * radio1 * altura) / 3;
  168. return volum;
  169. }
  170.  
  171. void cono()
  172. {
  173. Cono *c;
  174. c = new Cono(15);
  175. Cono *c1 = new Cono;
  176.  
  177. c1->setradio1(18);
  178. c1->setgen(16);
  179. c1->setaltura(20);
  180.  
  181. cout << "Cono: " << c1->getradio1() << endl;
  182. cout << "Area: " << c1->aretot() << endl;
  183. cout << "Volumen: " << c1->vol() << endl;
  184. cout << endl;
  185. }
  186.  
  187. Cono::~Cono() {}
  188. #pragma endregion
  189.  
  190. #pragma region movimiento
  191. class Ccaracter
  192. {
  193. private:
  194. int x; int y; int dx;
  195. int dy; char c; int coordX;
  196. int coordY;
  197. public:
  198. Ccaracter();
  199.  
  200. void set_x(int valor);
  201. int get_x();
  202. void set_y(int valor);
  203. int get_y();
  204. void set_dx(int valor);
  205. int get_dx();
  206. void set_dy(int valor);
  207. int get_dy();
  208. void set_c(char valor);
  209. char get_c();
  210.  
  211. void set_find(int coordX, int coordY);
  212. ~Ccaracter();
  213.  
  214. };
  215.  
  216. Ccaracter::Ccaracter()
  217. {
  218. this-> x = 0;
  219. this-> y = 0;
  220. this-> dx = 1;
  221. this-> dy = 1;
  222. this-> c = 219;
  223. this->coordX = 0;
  224. this->coordY = 0;
  225. }
  226.  
  227. void Ccaracter::set_x(int valor)
  228. {
  229. this-> x = valor;
  230. }
  231.  
  232. int Ccaracter::get_x()
  233. {
  234. return x;
  235. }
  236.  
  237. void Ccaracter::set_y(int valor)
  238. {
  239. this-> y = valor;
  240. }
  241.  
  242. int Ccaracter::get_y()
  243. {
  244. return y;
  245. }
  246.  
  247. void Ccaracter::set_dx(int valor)
  248. {
  249. this-> dx = valor;
  250. }
  251.  
  252. int Ccaracter::get_dx()
  253. {
  254. return dx;
  255. }
  256.  
  257. void Ccaracter::set_dy(int valor)
  258. {
  259. this-> dy = valor;
  260. }
  261.  
  262. int Ccaracter::get_dy()
  263. {
  264. return dy;
  265. }
  266.  
  267. void Ccaracter::set_c(char valor)
  268. {
  269. this-> c = valor;
  270. }
  271.  
  272. char Ccaracter::get_c()
  273. {
  274. return c;
  275. }
  276.  
  277. void Ccaracter::set_find(int coordX, int coordY)
  278. {
  279. Console::SetCursorPosition(coordX, coordY);
  280. }
  281.  
  282. void mover()
  283. {
  284. Console::SetCursorPosition(70, 20);
  285. Ccaracter *objeto = new Ccaracter();
  286. srand(time(NULL));
  287.  
  288. objeto->set_x(5 + rand() % 10 + 1 - 5);
  289. objeto->set_y(5 + rand() % 10 + 1 - 5);
  290. while (1)
  291. {
  292. objeto->set_find(objeto->get_x(), objeto-> get_y());
  293. cout << (char)objeto->get_c();
  294. _sleep(100);
  295. objeto->set_find(objeto->get_x(), objeto->get_y());
  296. cout << " ";
  297. if (objeto->get_x() > 78)
  298. {
  299. objeto->set_dx(objeto->get_dx()* -1);
  300. }
  301. if (objeto->get_x() == 1)
  302. {
  303. objeto->set_dx(objeto->get_dx()* -1);
  304. }
  305. objeto->set_x(objeto->get_x() + objeto->get_dx());
  306. }
  307. }
  308.  
  309. Ccaracter::~Ccaracter() {}
  310. #pragma endregion
  311.  
  312.  
  313. int main()
  314. {
  315. int c;
  316. cout << "Ingrese opcion: ";
  317. cin >> c;
  318. cout << endl;
  319. switch (c)
  320. {
  321. case 1: esfera();
  322. _getch();
  323. system("cls");
  324. return main();
  325. break;
  326. case 2: cono();
  327. _getch();
  328. system("cls");
  329. return main();
  330. break;
  331. case 3: mover();
  332. _getch();
  333. system("cls");
  334. return main();
  335. break;
  336. default:break;
  337. }
  338. _getch();
  339. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement