0% found this document useful (0 votes)
11 views3 pages

Sem 6

The document defines a Student class with private and public members. It includes a default constructor, parameterized constructor, copy constructor, overloaded assignment operator, destructor, and display method. The main function creates a Student object and calls its display method to output the student's information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Sem 6

The document defines a Student class with private and public members. It includes a default constructor, parameterized constructor, copy constructor, overloaded assignment operator, destructor, and display method. The main function creates a Student object and calls its display method to output the student's information.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

#include<iostream>

using namespace std;

class Student
{
private:
const int nrMatricol;
string nume;
int nrNote;
int* note;
float soldCont;

public:

Student() :nume("NA"), nrNote(0), note(NULL), nrMatricol(0),


soldCont(0)
{
cout << "\nAPEL CONSTR FARA PARAM";
}

Student(string nume, int nrNote, int* note, int nrMatricol, float


soldCont) :nume(nume), nrMatricol(nrMatricol), soldCont(soldCont)
{

cout << "\nAPEL CONSTR CU PARAM";


if (note != NULL && nrNote != 0)
{
this->note = new int[nrNote];
this->nrNote = nrNote;
for (int i = 0; i < this->nrNote; i++)
this->note[i] = note[i];
}
else
{
this->note = NULL;
this->nrNote = 0;
}
}

Student(const Student& s) :nume(s.nume),


nrMatricol(s.nrMatricol),soldCont(s.soldCont)
{
cout << "\nAPEL CONSTR COPIERE";
if (s.note != NULL && s.nrNote != 0)
{
this->note = new int[s.nrNote];
this->nrNote = s.nrNote;
for (int i = 0; i < this->nrNote; i++)
this->note[i] = s.note[i];
}
else
{
this->note = NULL;
this->nrNote = 0;
}
}

Student& operator=(const Student& s)


{

this->nume = s.nume;
this->soldCont = s.soldCont;
delete[] this->note;
if (s.note != NULL && s.nrNote != 0)
{
this->note = new int[s.nrNote];
this->nrNote = s.nrNote;
for (int i = 0; i < this->nrNote; i++)
this->note[i] = s.note[i];
}
else
{
this->note = NULL;
this->nrNote = 0;
}
return *this;
}

void afisare()
{
cout << "Studentul " << this->nume << ", nr matricol: " <<
this->nrMatricol<<", sold cont: "<<this->soldCont;
cout << " are " << this->nrNote << " note: ";
if (this->note != NULL)
for (int i = 0; i < this->nrNote; i++)
cout << this->note[i] << " ";
else
cout << "-";
cout << endl;
}

~Student()
{
cout << "\nAPEL DESTRUCTOR";
//if (this->note != NULL)
delete[] this->note;
}
};

int main()
{
int note[] = { 10,4,6 };
Student s("Gigel", 3, note, 102, 100.5);
s.afisare();

return 0;
}
/////sa citim in carte de la pagina 52
Supraincarcarea op sa se descurce si cu obiecte de tip student

You might also like