Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma warning(disable:4996)
- #include <conio.h>
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- using namespace std;
- class Planeta {
- protected:
- char *nume;
- int raza;
- int distantaS;
- int durata;
- int rotatie;
- public:
- Planeta() {
- //asta e doar un alt constructor de initializare, si e gol pentru ca
- //atunci cand creez vectorul Planeta *planete in cealalta clasa
- //nu te lasa sa creezi decat daca initializezi, de asta faci un
- //constructor Gol pentru ca uneori vrei "2" constructori
- //nu se stie cand vrei sa initializezi mai tarziu ceva(printr-o functie de initializare)
- }
- Planeta(char *nume, int raza, int distantaS, int durata, int rotatie) {
- this->nume = new char[30];
- this->nume = nume;
- this->raza = raza;
- this->distantaS = distantaS;
- this->durata = durata;
- this->rotatie = rotatie;
- }
- ~Planeta();
- Planeta(Planeta& v);
- void afisare();
- void setNume(char *p);
- void setRaza(int a);
- void setdistantaS(int a);
- void setdurata(int a);
- void setrotatie(int a);
- char * getNume();
- void citire();//asta am facut-o eu
- };
- char * Planeta::getNume() {
- return this->nume;
- }
- Planeta::~Planeta() {
- cout << "destructor";
- }
- Planeta::Planeta(Planeta& v) {
- nume = new char[20];
- this->nume = v.nume;
- this->raza = v.raza;
- this->distantaS = v.distantaS;
- this->durata = v.durata;
- this->rotatie = v.rotatie;
- }
- void Planeta::afisare() {
- cout << this->nume << ": \n";
- cout << "raza = " << this->raza << endl;
- cout << "distanta fata de soare = " << this->distantaS << endl;
- cout << "durata = " << this->durata << endl;
- cout << "perioada de rotatie = " << this->rotatie << endl;
- cout << " \n#####################\n";
- }
- void Planeta::setNume(char *p) {
- this->nume = p;
- }
- void Planeta::setRaza(int a) {
- this->raza = a;
- }
- void Planeta::setdistantaS(int a) {
- this->distantaS = a;
- }
- void Planeta::setdurata(int a) {
- this->durata = a;
- }
- void Planeta::setrotatie(int a) {
- this->rotatie = a;
- }
- void Planeta::citire() {
- cout << "\ndistantaS = "; cin >> this->distantaS;
- cout << "durata = "; cin >> this->durata;
- this->nume = new char[50];//aloc memorie pt nume planeta , ca e pointer
- char numeTemp[50]; // creez un vector de char (string) temporar ca sa pot folosii functia gets_s
- cout << "Nume Planeta = ";
- gets_s(numeTemp);//functia asta e ca sa citesti stringuri de la tastatura, merge si cin>>nume dar... e o mica problema
- //functia cin nu citeste "spatiu", daca scrii " Frentzy are mere", nu retine decat Frentzy
- // iar functia get_s retine toata propozitia, doar ca get_s nu merge pe pointeri =))))
- // trebuie folosit o variabila normala si fac un "temp" in care retin numele planetei
- gets_s(numeTemp);// de ce sunt 2 get_s? , pentru ca cel putin la mine ,compilatorul ignora pe primul ca si cum nu ar exista asa ca am pus 2
- strcpy(this->nume, numeTemp);// pun in pointer(this->nume) ce se afla in temp-ul respectiv(numeTemp)
- cout << "raza = "; cin >> this->raza;
- cout << "rotatie = "; cin >> this->rotatie;
- }
- class SistemSolar {
- protected:
- char *name;
- Planeta *planete;
- int nrPlanete;
- public:
- SistemSolar(char *name,int nrPlanete);
- ~SistemSolar();
- void afisare();
- void citire();
- };
- SistemSolar::SistemSolar(char *name, int nrPlanete) {
- this->nrPlanete = nrPlanete;
- this->name = name;
- /*sau mai poti face
- this->name = new char[strlen(name)+1];
- strcpy(this->name,name);
- */
- }
- SistemSolar::~SistemSolar() {
- cout << "\n apel destructor";
- }
- void SistemSolar::citire() {
- cout << "\nIntroducem date despre planetele astea: \n";
- this->planete = new Planeta[this->nrPlanete];
- for (int i = 0; i < this->nrPlanete; i++) {
- this->planete[i].citire();
- }
- }
- void SistemSolar::afisare() {
- cout << endl << "Nume Sistem Solar:" << this->name << endl;
- for (int i = 0; i < this->nrPlanete; i++) {
- this->planete[i].afisare();
- }
- }
- void main() {
- /*Planeta nr1("Pamant", 25, 123456, 24, 1456574);
- nr1.afisare();
- nr1.setNume("Marte");
- nr1.setdistantaS(1131241341);
- nr1.setdurata(12);
- nr1.setRaza(321434);
- nr1.setrotatie(4);
- nr1.afisare();
- */
- Planeta Frentzy;
- Frentzy.citire();
- //cout << Frentzy.getNume();
- cout << endl;
- Frentzy.afisare();
- cout << endl;
- SistemSolar hahalera("Jeg", 2);
- hahalera.citire();
- hahalera.afisare();
- _getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement