Advertisement
randykaur

Untitled

Apr 23rd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. #include <iostream>
  2. #include "circulo.h"
  3.  
  4. using namespace std;
  5.  
  6. #define PI 3.1415
  7. #define MAXP 100000
  8.  
  9. int menu();
  10.  
  11. class Ponto
  12. {
  13. protected:
  14. double x, y, raio, altura;
  15. public:
  16. Ponto(double x = 0, double y = 0, double r = 0, double a = 0): x{x}, y{y}, raio{r}, altura{a} { }
  17. ~Ponto() {}
  18.  
  19. virtual void read() { cin >> x >> y; }
  20. virtual void print() const { cout << "C(" << x << "," << y << ")"; }
  21.  
  22. virtual double area() { return 0; }
  23. virtual double volume() { return 0; }
  24.  
  25. };
  26.  
  27. class Circulo: public Ponto
  28. {
  29. public:
  30. Circulo(double x = 0, double y = 0, double raio = 0, double altura = 0): Ponto{x, y, raio, altura} {}
  31. ~Circulo() {}
  32.  
  33. void read() { cin >> x >> y >> raio; }
  34. void print() const { Ponto::print(); cout << " RAIO = " << raio; }
  35.  
  36. double area() { return PI*raio*raio; }
  37. double volume() { return 0; }
  38.  
  39. };
  40.  
  41. class Cilindro: public Circulo
  42. {
  43. public:
  44. Cilindro(double x = 0, double y = 0, double raio = 0, double altura = 0): Circulo{x, y, raio, altura} {}
  45. ~Cilindro() {}
  46.  
  47. void read() { cin >> x >> y >> raio >> altura; }
  48. void print() const { Circulo::print(); cout << " ALTURA = " << altura; }
  49.  
  50. double area() { return (2*Circulo::area())+ 2*PI*raio*altura ; }
  51. double volume() { return (Circulo::area())*altura; }
  52.  
  53. };
  54.  
  55. istream& operator>>(istream& input, Ponto& in){
  56. in.read();
  57. return input;
  58. }
  59. ostream& operator<<(ostream& output, const Ponto& out){
  60. out.print();
  61. return output;
  62. }
  63. int menu(){
  64. int op;
  65. cout << "1 - Presidente" << endl;
  66. cout << "2 - Governador" << endl;
  67. cout << "3 - Prefeito" << endl;
  68. cout << "0 - Sair" << endl;
  69.  
  70. cout << "Digite opcao desejada para inserir: ";
  71.  
  72. while(cin >> op){
  73. if(op == 0 || op == 1 || op == 2 || op == 3)
  74. return op;
  75.  
  76. cout << "Digite uma das opcoes disponiveis" << endl;
  77. }
  78. }
  79. int main(){
  80.  
  81. int qtd;
  82. cout << "Informe quantidade formas: ";
  83. cin >> qtd; cout << endl;
  84.  
  85. try{
  86. if(qtd < 0 || qtd >= MAXP)
  87. throw "Please, input only valid numbers\n";
  88. }catch( const char *c ){
  89. cout << endl << "Invalid number!" << endl << c;
  90. }
  91.  
  92. Ponto* vet[ MAXP ];
  93.  
  94. cout << "Escolha " << qtd << " vezes qual o tipo que deseja criar" << endl;
  95.  
  96. for(int j = 0; j < qtd; j++){
  97.  
  98. cout << endl;
  99. int op = menu();
  100. if(op == 0)
  101. return 0;
  102.  
  103. switch( op ){
  104. case 1:
  105. vet[ j ] = new Ponto; cout << endl;
  106. cin >> *vet[ j ];
  107. break;
  108. case 2:
  109. vet[ j ] = new Circulo; cout << endl;
  110. cin >> *vet[ j ];
  111. break;
  112. case 3:
  113. vet[ j ] = new Cilindro; cout << endl;
  114. cin >> *vet[ j ];
  115. break;
  116. }
  117. }
  118.  
  119. cout << endl << "### MOSTRAR VETOR! ###" << endl << endl;
  120. for(int i = 0; i < qtd; i++)
  121. cout << *vet[ i ] << endl;
  122.  
  123. cout << endl << "#### FIM ####" << endl << endl;
  124.  
  125. return 0;
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement