Alx09

Lab2_POO_Ex5

Oct 5th, 2020
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.20 KB | None | 0 0
  1. #include<iostream>
  2. #include<conio.h>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. class Student
  7. {
  8.     char *nume, *pren;
  9.     int grupa, cod_postal;
  10. public:
  11.     Student(){}
  12.     Student(char *, char *, int, int);//Constructor
  13.     ~Student();//Destructor
  14.     void afisare_date();
  15. };
  16. //constructor
  17. Student::Student(char *nume, char *pren, int grupa, int cod_postal)
  18. {
  19.     this->nume = new char[strlen(nume) + 1];
  20.     strcpy(this->nume, nume);
  21.     this->pren = new char[strlen(pren) + 1];
  22.     strcpy(this->pren, pren);
  23.     this->grupa = grupa;
  24.     this->cod_postal = cod_postal;
  25. }
  26.  
  27. //functie pentru afisarea datelor
  28. void Student::afisare_date()
  29. {
  30.     cout << "Nume :" << nume << endl;
  31.     cout << "Prenume:" << pren << endl;
  32.     cout << "Grupa:" << grupa << endl;
  33.     cout << "Cod postal :" << cod_postal;
  34. }
  35. //destructor
  36. Student :: ~Student()
  37. {
  38. delete nume;
  39. delete pren;
  40. }
  41.  
  42. int main()
  43. {
  44.     char nume[20], pren[20];
  45.     int grupa, cod_postal;
  46.     cout << "Nume:"; cin >> nume;
  47.     cout << "Prenume:"; cin >> pren;
  48.     cout << "Grupa:";cin >> grupa;
  49.     cout << "Cod postal: "; cin >> cod_postal;
  50.     //crearea unui obiect de tip Student
  51.     Student s(nume, pren, grupa, cod_postal);
  52.  
  53.     //afisarea informatiilor
  54.     s.afisare_date();
  55.     getchar();
  56.     return 0;
  57. }
  58.  
Advertisement
Add Comment
Please, Sign In to add comment