-
-
Save PedroHLC/46c9ec4286a2087edefd488545daead1 to your computer and use it in GitHub Desktop.
Cilindro - Herença # forked from https://gist.github.com/isagallerani/ed559aa0ec6324ecc98d4b78b96059df
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
#include "circulo.h" | |
using namespace::std; | |
ostream& operator<<(ostream &saida, const Cilindro& cl) { | |
saida << "Cilindro:" << endl << "\t(" << cl.getX() << ", " << cl.getY() << ")" << endl << "\tAltura: " << cl.getAltura() | |
<< endl << "\tVolume: " << cl.getVolume() << endl; | |
return saida; | |
} | |
Cilindro::Cilindro(int _x, int _y, double _raio, double _altura):Circulo(_x, _y, _raio) { | |
setAltura(_altura); | |
} | |
bool Cilindro::setAltura(double _altura) { | |
if (_altura > 0) { | |
altura = _altura; | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
double Cilindro::getAltura() const { | |
return altura; | |
} | |
double Cilindro::getVolume() const { | |
return M_PI*getRaio()*getRaio()*getAltura(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "circulo.h" | |
using namespace::std; | |
class Cilindro : public Circulo { | |
public: | |
Cilindro(int _x=1, int _y=1, double _raio=1, double _altura=1); | |
bool setAltura(double _altura); | |
double getAltura() const; | |
double getVolume() const; | |
friend ostream &operator<<(ostream &, const Cilindro&); | |
private: | |
double altura; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <math.h> | |
#include "circulo.h" | |
using namespace::std; | |
ostream& operator<<(ostream &saida, const Circulo& c) { | |
saida << "Circulo:" << endl << "\t(" << c.getX() << ", " << c.getY() << ")" << | |
endl << "\tRaio: " << c.getRaio() << endl | |
<< "\tArea: " << c.getArea() << endl << "\tDiametro: " << c.getDiametro() | |
<< endl << "\tCircunferencia: " << c.getCircunferencia() << endl; | |
return saida; | |
} | |
Circulo::Circulo(int _x, int _y, double _raio):Ponto(_x, _y) { | |
setRaio(_raio); | |
} | |
bool Circulo::setRaio(double _raio) { | |
if (_raio > 0) { | |
raio = _raio; | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
double Circulo::getRaio() const { | |
return raio; | |
} | |
double Circulo::getDiametro() const { | |
return 2*getRaio(); | |
} | |
double Circulo::getCircunferencia() const { | |
return M_PI*getDiametro(); | |
} | |
double Circulo::getArea() const { | |
return M_PI*getRaio()*getRaio(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "ponto.h" | |
using namespace::std; | |
class Circulo : public Ponto { | |
public: | |
Circulo(int _x=1, int _y=1, double raio=1); | |
bool setRaio(double _raio); | |
double getRaio() const; | |
double getDiametro() const; | |
double getCircunferencia() const; | |
double getArea() const; | |
friend ostream &operator<<(ostream &, const Circulo&); | |
private: | |
double raio; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "ponto.h" | |
#include "circulo.h" | |
#include "cilindro.h" | |
using namespace::std; | |
int main () { | |
Ponto p1(2, 5); | |
cout << p1 << endl; | |
p1.setX(1); | |
p1.setY(3); | |
cout << p1 << endl; | |
Circulo c1(1, 4, 2); | |
cout << c1 << endl; | |
c1.setX(3); | |
c1.setY(2); | |
c1.setRaio(6); | |
cout << c1 << endl; | |
Cilindro cl1(2, 3, 4, 5); | |
cout << cl1 << endl; | |
cl1.setX(1); | |
cl1.setY(2); | |
cl1.setRaio(3); | |
cl1.setAltura(4); | |
cout << cl1 << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include "ponto.h" | |
using namespace::std; | |
ostream& operator<<(ostream &saida, const Ponto& p) { | |
saida << "Ponto: " << endl << "\t(" << p.getX() << ", " << p.getY() << ")" << endl; | |
return saida; | |
} | |
Ponto::Ponto(int _x, int _y) { | |
setX(_x); | |
setY(_y); | |
} | |
void Ponto::setX(int _x) { | |
x = _x; | |
} | |
void Ponto::setY(int _y) { | |
y = _y; | |
} | |
int Ponto::getX() const { | |
return x; | |
} | |
int Ponto::getY() const { | |
return y; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace::std; | |
class Ponto{ | |
public: | |
Ponto(int _x=1, int _y=1); | |
void setX(int _x); | |
int getX() const; | |
void setY(int _y); | |
int getY() const; | |
friend ostream &operator<<(ostream &, const Ponto&); | |
private: | |
int x; | |
int y; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment