Solucao 2 Exercicio Retangulo: mudanças entre as edições
Ir para navegação
Ir para pesquisar
imported>Fargoud (Criou página com ' #include <iostream> #include <stdio.h> // using namespace std; // class Retangulo { private: int xi, yi, xs, ys; int Calcula_Perimetro(); int Calcula_Area()...') |
imported>Fargoud Sem resumo de edição |
||
| Linha 1: | Linha 1: | ||
CÓDIGO de Retangulo.h: | |||
#ifndef RETANGULO_H | |||
#define RETANGULO_H | |||
class Retangulo | |||
{ | |||
private: | |||
int xi, yi, xs, ys; | |||
int Calcula_Perimetro(); | |||
int Calcula_Area(); | |||
public: | |||
Retangulo(int x1, int y1, int x2, int y2); | |||
Retangulo(); | |||
~Retangulo(); | |||
void Desenha(); | |||
}; | |||
#endif // RETANGULO_H | |||
CÓDIGO de Retangulo.cpp: | |||
#include "Retangulo.h" | |||
#include <iostream> | #include <iostream> | ||
#include <stdio.h> | #include <stdio.h> | ||
| Linha 4: | Linha 25: | ||
using namespace std; | using namespace std; | ||
// | // | ||
// | |||
Retangulo::~Retangulo( ) | |||
{ | |||
cout<< "That's all folks!" << endl; | |||
} | |||
} | |||
// | // | ||
Retangulo::Retangulo(int x1, int y1, int x2, int y2) | Retangulo::Retangulo(int x1, int y1, int x2, int y2) | ||
{ | { | ||
xi= x1; | |||
xs = x2; | |||
yi = y1; | |||
ys = y2; | |||
} | |||
// | // | ||
Retangulo::Retangulo() | Retangulo::Retangulo() | ||
{ cout<< "Entre com a coordenada x canto superior esquerdo" << endl; | { | ||
cout<< "Entre com a coordenada x canto superior esquerdo" << endl; | |||
cin>>xi; | |||
cout<< "Entre com a coordenada y canto superior esquerdo" << endl; | |||
cin>> yi; | |||
cout<< "Entre com a coordenada x canto inferior direito" <<endl; | |||
cin>> xs; | |||
cout<< "Entre com a coordenada y canto inferior direito" <<endl; | |||
// | cin>> ys;} | ||
// | |||
int Retangulo::Calcula_Perimetro() | int Retangulo::Calcula_Perimetro() | ||
{ int perim; | { int perim; | ||
if((xs > xi)&&(ys > yi)) | if((xs > xi)&&(ys > yi)) | ||
perim = 2*(xs - xi) + 2*(ys - yi); | |||
return perim; | return perim; | ||
} | } | ||
| Linha 42: | Linha 60: | ||
int Retangulo::Calcula_Area() | int Retangulo::Calcula_Area() | ||
{ int area; | { int area; | ||
if((xs > xi)&&(ys > yi)) | |||
area = (xs - xi)*(ys - yi); | |||
} | } | ||
// | // | ||
void Retangulo::Desenha() | void Retangulo::Desenha() | ||
{ int i, j; | { int i, j; | ||
if(xs > xi) | |||
cout << "largura do retangulo = " << (xs - xi) << endl; | |||
if(ys > yi) | |||
cout << "altura do retangulo = " << (ys - yi) << endl; | |||
cout << "perimetro do retangulo =" << Calcula_Perimetro() << endl; | |||
cout << "area do retangulo = " << Calcula_Area() << "\n\n\n"<< endl; | |||
printf(" "); | |||
for(i = 1; i< (xs | for(i = 1; i< xi; i++) | ||
printf(" "); | |||
for(i = xi; i< xs; i++) | |||
printf("-"); | |||
for(j = 1;j < (ys - yi);j++) | |||
{ printf("\n"); | |||
for(i = 1; i< xi; i++) | |||
printf(" "); | |||
printf("|"); | printf("|"); | ||
for(i= xi; i< xs ; i++) | |||
printf(" "); | |||
for(i = 1; i< (xs | printf("|"); | ||
} | |||
printf("\n "); | |||
for(i = 1; i< xi; i++) | |||
printf(" "); | |||
for(i = xi; i< xs; i++) | |||
printf("-"); | |||
printf("\n\n"); | |||
} | } | ||
// | |||
CÓDIGO CLIENTE (main()): | |||
#include <iostream> | |||
#include "Retangulo.h" | |||
using namespace std; | |||
// | // | ||
int main() | int main() | ||
{ Retangulo r1(12, 14, 20, 18), r2; | { Retangulo r1(12, 14, 20, 18), r2; | ||
r2.Desenha(); | |||
r1.Desenha(); | r1.Desenha(); | ||
} | } | ||
Edição atual tal como às 16h18min de 14 de março de 2018
CÓDIGO de Retangulo.h:
#ifndef RETANGULO_H
#define RETANGULO_H
class Retangulo
{
private:
int xi, yi, xs, ys;
int Calcula_Perimetro();
int Calcula_Area();
public:
Retangulo(int x1, int y1, int x2, int y2);
Retangulo();
~Retangulo();
void Desenha();
};
#endif // RETANGULO_H
CÓDIGO de Retangulo.cpp:
#include "Retangulo.h"
#include <iostream>
#include <stdio.h>
//
using namespace std;
//
//
Retangulo::~Retangulo( )
{
cout<< "That's all folks!" << endl;
}
//
Retangulo::Retangulo(int x1, int y1, int x2, int y2)
{
xi= x1;
xs = x2;
yi = y1;
ys = y2;
}
//
Retangulo::Retangulo()
{
cout<< "Entre com a coordenada x canto superior esquerdo" << endl;
cin>>xi;
cout<< "Entre com a coordenada y canto superior esquerdo" << endl;
cin>> yi;
cout<< "Entre com a coordenada x canto inferior direito" <<endl;
cin>> xs;
cout<< "Entre com a coordenada y canto inferior direito" <<endl;
cin>> ys;}
//
int Retangulo::Calcula_Perimetro()
{ int perim;
if((xs > xi)&&(ys > yi))
perim = 2*(xs - xi) + 2*(ys - yi);
return perim;
}
//
int Retangulo::Calcula_Area()
{ int area;
if((xs > xi)&&(ys > yi))
area = (xs - xi)*(ys - yi);
}
//
void Retangulo::Desenha()
{ int i, j;
if(xs > xi)
cout << "largura do retangulo = " << (xs - xi) << endl;
if(ys > yi)
cout << "altura do retangulo = " << (ys - yi) << endl;
cout << "perimetro do retangulo =" << Calcula_Perimetro() << endl;
cout << "area do retangulo = " << Calcula_Area() << "\n\n\n"<< endl;
printf(" ");
for(i = 1; i< xi; i++)
printf(" ");
for(i = xi; i< xs; i++)
printf("-");
for(j = 1;j < (ys - yi);j++)
{ printf("\n");
for(i = 1; i< xi; i++)
printf(" ");
printf("|");
for(i= xi; i< xs ; i++)
printf(" ");
printf("|");
}
printf("\n ");
for(i = 1; i< xi; i++)
printf(" ");
for(i = xi; i< xs; i++)
printf("-");
printf("\n\n");
}
//
CÓDIGO CLIENTE (main()):
#include <iostream>
#include "Retangulo.h"
using namespace std;
//
int main()
{ Retangulo r1(12, 14, 20, 18), r2;
r2.Desenha();
r1.Desenha();
}