Advertisement
frentzy

Bilet nr 3 POO partial nr 2

May 22nd, 2018
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.12 KB | None | 0 0
  1. /*
  2. Clasa de baza: articol
  3. atribute: titlul, cota(nr de identare)
  4. derivata: carte
  5. atribut: autor
  6.  
  7. constructor init, si copiere , get & set, citire & afisare, supra incarcarea lui =
  8.  
  9.  
  10. */
  11. #pragma warning(disable:4996)
  12. #include <conio.h>
  13. #include <iostream>
  14. #include <stdio.h>
  15. //#include <stdlib.h>
  16. using namespace std;
  17.  
  18. class articol{
  19. protected:
  20.     char titlu[50];
  21.     int cota;
  22. public:
  23.     articol(char titlu[], int cota) {
  24.         strcpy(this->titlu, titlu);
  25.         this->cota = cota;
  26.     }
  27.     articol(articol& random) {
  28.         this->cota = random.cota;
  29.         strcpy(this->titlu, random.titlu);
  30.     }
  31.     ~articol() {
  32.         cout << "\ndestructor articol activat \n";
  33.     }
  34.     char * getTitlu() {
  35.         return this->titlu;
  36.     }
  37.     int getCota() {
  38.         return this->cota;
  39.     }
  40.     void setTitlu(char random[50]){
  41.         strcpy(this->titlu, random);
  42.     }
  43.     void setCota(int random) {
  44.         this->cota = random;
  45.     }
  46.     void citire() {
  47.         cout << "\nNume Titlu:";gets_s(this->titlu);
  48.         cout << "\nCota: "; cin >> this->cota;
  49.     }
  50.     void afisare() {
  51.         cout << "\n\nNume Titlu articol: " << this->titlu;
  52.         cout << "\nCota: " << this->cota;
  53.     }
  54.     articol & operator = (articol random) {
  55.         this->cota = random.cota;
  56.         strcpy(this->titlu, random.titlu);
  57.         return *this;
  58.     }
  59. };
  60.  
  61. class carte: public articol {
  62. protected:
  63.     char autor[50];
  64. public:
  65.     carte(char titlu[], int cota,char autor[]):articol(titlu,cota) {
  66.         strcpy(this->autor, autor);
  67.     }
  68.     carte(carte& random):articol(random) {
  69.         strcpy(this->autor, random.autor);
  70.     }
  71.     ~carte() {
  72.         cout << "\ndestructor carte activat\n";
  73.     }
  74.     char * getAutor() {
  75.         return this->autor;
  76.     }
  77.  
  78.     void setAutor(char random[50]){
  79.         strcpy(this->autor, random);
  80.     }
  81.    
  82.     void citire() {
  83.         this->articol::citire();
  84.         //cout << "\nNume Titlu: ";gets_s(this->titlu);
  85.         //cout << "\nCota: "; cin >> this->cota;
  86.         cout << "\nNume Autor: "; gets_s(this->autor);
  87.     }
  88.     void afisare() {
  89.         this->articol::afisare();
  90.         //cout << "\n\nNume Titlu articol: " << this->titlu;
  91.         //cout << "\nCota: " << this->cota;
  92.         cout << "\nAutor: " << this->autor;
  93.     }
  94.     carte & operator = (carte random) {
  95.        
  96.         strcpy(this->autor, random.autor);
  97.         return *this;
  98.     }
  99. };
  100.  
  101.  
  102.  
  103. void main() {
  104.     articol Frentzy("Frentzy", 21);
  105.     Frentzy.afisare();
  106.     cout << endl;
  107.     cout << "getCota() = " << Frentzy.getCota() << endl;
  108.     cout << "getTitlu() = " << Frentzy.getTitlu() << endl;
  109.     Frentzy.setCota(20);cout << "getCota() = " << Frentzy.getCota() << endl;
  110.     Frentzy.setTitlu("Aleator");cout << "getTitlu() = " << Frentzy.getTitlu() << endl;
  111.     cout << endl << "citire:"<<endl;
  112.     Frentzy.citire();
  113.     Frentzy.afisare();
  114.  
  115.     articol Test1(Frentzy);
  116.     Test1.afisare();
  117.     articol Test2("Test2", 2);
  118.     Test2.afisare();
  119.     Test2 = Frentzy;
  120.     Test2.afisare();
  121.     cout << "\n////////////////////////////////////////////////\n";
  122.     cout << endl;
  123.     carte ceva("Frentzy", 21, "Profesor Zgarie-Branza");
  124.     ceva.afisare();
  125.     cout<<"\ngetAutor()="<<ceva.getAutor()<<endl;
  126.     ceva.setAutor("Autor");
  127.     carte ceva_temp(ceva);
  128.     cout << "\n\ncopierea lui ceva_temp cu ceva";
  129.     ceva_temp.afisare();
  130.     cout << "\n\n------------------\n";
  131.     carte etc("1", 1, "1");
  132.     etc.afisare();
  133.     etc = ceva;
  134.     etc.afisare();
  135.     _getch();
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement