Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "retangulo.h"
- // ****BUILD*****//
- Retangulo::Retangulo(){
- this->largura = 1;
- this->comprimento = 1;
- cout << endl;
- cout << "Foi criado um obj!" << endl;
- }
- Retangulo::Retangulo(int c, int l){
- if(is_valid(c, l)){
- this->largura = l;
- this->comprimento = c;
- }
- else{
- this->largura = 1;
- this->comprimento = 1;
- }
- cout << endl;
- cout << "Foi criado um obj!" << endl;
- }
- // ****GET*****//
- int Retangulo::getLarg(){
- return largura;
- }
- int Retangulo::getComp(){
- return comprimento;
- }
- // ****SET*****//
- void Retangulo::setComp(int c){
- if(c>=0 && c<=20)
- this->comprimento = c;
- else comprimento = 1;
- }
- void Retangulo::setLarg(int l){
- if(l>=0 && l<=20)
- this->largura = l;
- else largura = 1;
- }
- void Retangulo::imprime(){
- cout << "largura: " << largura << " comprimento: " << comprimento << endl;
- }
- void Retangulo::leitura(){
- int c, l;
- cout << "Digite um comp: "; cin >> c;
- cout << "Digite uma larg: "; cin >> l;
- /*
- while(!is_valid(c, l)){
- cout << "Digite novamente um comp: "; cin >> c;
- cout << "Digite novamente uma larg: "; cin >> l;
- }
- */
- setLarg(l);
- setComp(c);
- }
- //****VALIDAR*****//
- bool Retangulo::is_valid(int c, int l){
- return (c>=0 && c<=20 && l>=0 && c<=20);
- }
- //****CALCULOS*****//
- int Retangulo::area(){
- int a = largura;
- int b = comprimento;
- return a*b;
- }
- int Retangulo::perimetro(){
- int a = largura;
- int b = comprimento;
- return 2*(a + b);
- }
- void Retangulo::isQuad(){
- int a = largura;
- int b = comprimento;
- if(a == b)
- cout << "Yes, this is a 'QUADRADO'" << endl;
- else cout << "Sorry, but this is not a 'QUADRADO'" << endl;
- }
- //****MATRIX*****//
- void Retangulo::matrix(char borda[], char preenchimento[]){
- int lin = largura;
- int col = comprimento;
- for(int i=0; i<lin; i++){
- for(int j=0; j<col; j++){
- if(i == 0 || j == 0 || i == lin-1 || j == col-1)
- cout << borda[0];
- else cout << preenchimento[0];
- }
- cout << endl;
- }
- }
Add Comment
Please, Sign In to add comment