Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <iostream>
- using namespace std;
- #define NR_MAX_OB 100
- #define MAX 40
- class ObiectCosmic {
- protected:
- char nume[MAX];
- double masa;
- public:
- ObiectCosmic(const char *nume = "", double masa = 0);
- void setNume(const char *nume);
- char* getNume();
- void setMasa(double masa);
- double getMasa();
- virtual void afisare();
- };
- ObiectCosmic::ObiectCosmic(const char *nume, double masa) {
- strncpy(this -> nume, nume, MAX);
- this -> masa = masa;
- }
- void ObiectCosmic::setNume(const char *nume) {
- strncpy(this -> nume, nume, MAX);
- }
- char* ObiectCosmic::getNume() {
- return nume;
- }
- void ObiectCosmic::setMasa(double masa) {
- this->masa = masa;
- }
- double ObiectCosmic::getMasa() {
- return masa;
- }
- void ObiectCosmic::afisare() {
- cout<<"Nume: "<<nume<<endl;
- cout<<"Masa: "<<masa<<endl;
- }
- ///*********************************************************************
- class Planeta: public ObiectCosmic {
- protected:
- int perRotatie;
- public:
- Planeta(const char *nume = " ", double masa = 0, int perRotatie=0);
- void setPerRotatie( int perRotatie){
- this->perRotatie=perRotatie;
- }
- int getPerRotatie(){
- return perRotatie;
- }
- void afisare();
- };
- Planeta::Planeta(const char *nume, double masa, int perRotatie ):ObiectCosmic(nume, masa){
- this->perRotatie=perRotatie;
- }
- void Planeta::afisare() {
- cout<<"Planeta"<<endl;
- cout<<"---------------------------------"<<endl;
- ObiectCosmic::afisare();
- cout<<"Perioada de rotatie: "<<perRotatie<<endl;
- cout<<"---------------------------------"<<endl;
- }
- ///*********************************************************************
- class Stea: public ObiectCosmic {
- protected:
- int magnitudine;
- public:
- Stea(const char *nume = "", double masa = 0, int magnitudine = 0);
- void setMagnitudine(int magnitudine){
- this->magnitudine=magnitudine;
- }
- int setMagnitudine(){
- return magnitudine;
- }
- void afisare();
- };
- Stea::Stea(const char *nume, double masa, int magnitudine):ObiectCosmic(nume, masa) {
- this->magnitudine = magnitudine;
- }
- void Stea::afisare() {
- cout<<"Stea"<<endl;
- cout<<"---------------------------------"<<endl;
- ObiectCosmic::afisare();
- cout<<"Magnitudine: "<<magnitudine<<endl;
- cout<<"---------------------------------"<<endl;
- }
- class Galaxie {
- char nume[MAX];
- ObiectCosmic *G[NR_MAX_OB];
- int nrObiecteCosmice;
- public:
- Galaxie(const char *nume = "");
- void adaugaObiecteCosmice(ObiectCosmic *p);
- void afisare();
- };
- Galaxie::Galaxie(const char *nume) {
- strncpy(this -> nume, nume, MAX);
- nrObiecteCosmice = 0 ;
- }
- void Galaxie::adaugaObiecteCosmice(ObiectCosmic *p) {
- if (nrObiecteCosmice < NR_MAX_OB) {
- G[nrObiecteCosmice]=p;
- nrObiecteCosmice++;
- } else {
- throw out_of_range("Depasire capacitate");
- }
- }
- void Galaxie::afisare() {
- cout<<"Galaxie: "<<nume<<endl;
- cout<<"================================="<<endl;
- for(int i=0; i<nrObiecteCosmice; i++) {
- G[i]->afisare();
- }
- }
- int main() {
- Galaxie galaxie("Calea Lactee");
- galaxie.adaugaObiecteCosmice(new Planeta("Marte", 100,687 ));
- galaxie.adaugaObiecteCosmice(new Stea("Sirius", 10, 1.5));
- galaxie.afisare();
- }
- ///judet-localitati.cpp
- ///Se afișează judet-localitati.cpp.
Advertisement
Add Comment
Please, Sign In to add comment