randykaur

ret.cpp

Mar 12th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. #include <iostream>
  2. #include "retangulo.h"
  3.  
  4. // ****BUILD*****//
  5. Retangulo::Retangulo(){
  6. this->largura = 1;
  7. this->comprimento = 1;
  8.  
  9. cout << endl;
  10. cout << "Foi criado um obj!" << endl;
  11. }
  12.  
  13. Retangulo::Retangulo(int c, int l){
  14. if(is_valid(c, l)){
  15. this->largura = l;
  16. this->comprimento = c;
  17. }
  18. else{
  19. this->largura = 1;
  20. this->comprimento = 1;
  21. }
  22.  
  23. cout << endl;
  24. cout << "Foi criado um obj!" << endl;
  25. }
  26. // ****GET*****//
  27. int Retangulo::getLarg(){
  28. return largura;
  29. }
  30. int Retangulo::getComp(){
  31. return comprimento;
  32. }
  33. // ****SET*****//
  34. void Retangulo::setComp(int c){
  35. if(c>=0 && c<=20)
  36. this->comprimento = c;
  37. else comprimento = 1;
  38. }
  39. void Retangulo::setLarg(int l){
  40. if(l>=0 && l<=20)
  41. this->largura = l;
  42. else largura = 1;
  43. }
  44. void Retangulo::imprime(){
  45. cout << "largura: " << largura << " comprimento: " << comprimento << endl;
  46. }
  47. void Retangulo::leitura(){
  48. int c, l;
  49. cout << "Digite um comp: "; cin >> c;
  50. cout << "Digite uma larg: "; cin >> l;
  51.  
  52. /*
  53. while(!is_valid(c, l)){
  54. cout << "Digite novamente um comp: "; cin >> c;
  55. cout << "Digite novamente uma larg: "; cin >> l;
  56. }
  57. */
  58. setLarg(l);
  59. setComp(c);
  60. }
  61. //****VALIDAR*****//
  62. bool Retangulo::is_valid(int c, int l){
  63. return (c>=0 && c<=20 && l>=0 && c<=20);
  64. }
  65. //****CALCULOS*****//
  66. int Retangulo::area(){
  67. int a = largura;
  68. int b = comprimento;
  69.  
  70. return a*b;
  71. }
  72. int Retangulo::perimetro(){
  73. int a = largura;
  74. int b = comprimento;
  75.  
  76. return 2*(a + b);
  77. }
  78. void Retangulo::isQuad(){
  79. int a = largura;
  80. int b = comprimento;
  81.  
  82. if(a == b)
  83. cout << "Yes, this is a 'QUADRADO'" << endl;
  84. else cout << "Sorry, but this is not a 'QUADRADO'" << endl;
  85.  
  86. }
  87. //****MATRIX*****//
  88. void Retangulo::matrix(char borda[], char preenchimento[]){
  89. int lin = largura;
  90. int col = comprimento;
  91.  
  92. for(int i=0; i<lin; i++){
  93. for(int j=0; j<col; j++){
  94. if(i == 0 || j == 0 || i == lin-1 || j == col-1)
  95. cout << borda[0];
  96. else cout << preenchimento[0];
  97. }
  98. cout << endl;
  99. }
  100. }
Add Comment
Please, Sign In to add comment