Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<conio.h>
- #include <string.h>
- using namespace std;
- class Student
- {
- char *nume, *pren;
- int grupa, cod_postal;
- public:
- Student(){}
- Student(char *, char *, int, int);//Constructor
- ~Student();//Destructor
- void afisare_date();
- };
- //constructor
- Student::Student(char *nume, char *pren, int grupa, int cod_postal)
- {
- this->nume = new char[strlen(nume) + 1];
- strcpy(this->nume, nume);
- this->pren = new char[strlen(pren) + 1];
- strcpy(this->pren, pren);
- this->grupa = grupa;
- this->cod_postal = cod_postal;
- }
- //functie pentru afisarea datelor
- void Student::afisare_date()
- {
- cout << "Nume :" << nume << endl;
- cout << "Prenume:" << pren << endl;
- cout << "Grupa:" << grupa << endl;
- cout << "Cod postal :" << cod_postal;
- }
- //destructor
- Student :: ~Student()
- {
- delete nume;
- delete pren;
- }
- int main()
- {
- char nume[20], pren[20];
- int grupa, cod_postal;
- cout << "Nume:"; cin >> nume;
- cout << "Prenume:"; cin >> pren;
- cout << "Grupa:";cin >> grupa;
- cout << "Cod postal: "; cin >> cod_postal;
- //crearea unui obiect de tip Student
- Student s(nume, pren, grupa, cod_postal);
- //afisarea informatiilor
- s.afisare_date();
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment