Advertisement
Guest User

constructor copiere prin mostenire

a guest
May 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.74 KB | None | 0 0
  1. #pragma warning(disable: 4996)
  2. #include <iostream>
  3. #include <conio.h>
  4. #include<string.h>
  5. using namespace std;
  6.  
  7. class Persoana {
  8. protected:
  9.     char nume[20];
  10.     int varsta;
  11.  
  12. public:
  13.     Persoana() {
  14.  
  15.     }
  16.  
  17.  
  18. Persoana(char nume[20], int varsta) {
  19.     strcpy(this->nume, nume);
  20.     this->varsta = varsta;
  21.     cout << "Constructor class: Pesoana" << endl;
  22. }
  23.  
  24. ~Persoana() {
  25.  
  26. }
  27.  
  28. Persoana(Persoana &temp) {
  29.     strcpy(this->nume, temp.nume);
  30.     this->varsta = temp.varsta;
  31. }
  32.  
  33.  
  34. char* getNume() {
  35.     return nume;
  36. }
  37. int getVarsta() {
  38.     return varsta;
  39. }
  40. void Prints() {
  41.     cout << getNume() << endl << getVarsta();
  42. }
  43. char* setNume(char nume[20]) {
  44.     strcpy(this->nume, nume);
  45.     return nume;
  46. }
  47. int setVarsta(int varsta) {
  48.     this->varsta = varsta;
  49.     return varsta;
  50. }
  51.  
  52. };
  53.  
  54. class Student :public Persoana {
  55. protected:
  56.     char facultate[20];
  57.     Persoana test;
  58. public:
  59.  
  60.     Student(char facultate[20], char nume[20], int varsta,Persoana test) :Persoana(nume, varsta) {
  61.         strcpy(this->facultate, facultate);
  62.         cout << "Costructor  class: Student" << endl;
  63.     }
  64.     Student(Student &temp):test(temp) {
  65.         strcpy(this->facultate, temp.facultate);
  66.     }
  67.  
  68.    
  69.     ~Student() {
  70.  
  71.     };
  72.     char* getFacultate() {
  73.         return facultate;
  74.     }
  75.     void Printf() {
  76.         cout << getNume() << endl << getVarsta() << endl << getFacultate() << endl;
  77.     }
  78.  
  79.     char* setFacultate(char facultate[20]) {
  80.         strcpy(this->facultate, facultate);
  81.         return facultate;
  82.     }
  83.  
  84. };
  85.  
  86.  
  87.  
  88.  
  89. int main() {
  90.     Persoana pers("frentzy",20);
  91.     char a[20] = "Mihai";
  92.     char s[20] = "UCV";
  93.     char c[20] = "eo";
  94.     char n[20] = "sadad";
  95.     Student v(s, a, 23,pers);
  96.    
  97.  
  98.     v.Printf();
  99.     v.setVarsta(12);
  100.     v.Printf();
  101.     v.setNume(c);
  102.     cout << endl;
  103.     v.Printf();
  104.     cout << endl;
  105.     v.setFacultate(n);
  106.     v.Printf();
  107.  
  108.  
  109.     _getch();
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement