Sunteți pe pagina 1din 3

// ConsoleApplication1.cpp : Defines the entry point for the console application.

//

#include "stdafx.h"
#include <iostream>
#pragma warning (disable :4996)
using namespace std;

class Student

private:

int* note;
int NrNote;
int medie;
bool integralist;

public:

char* nume;
int varsta;

Student();
Student(Student &s);
Student(char*nume, int* note, int NrNote , int varsta );
friend ostream & operator << (ostream &iesire, const Student s)
{

iesire << s.nume << s.varsta;


return iesire;
}

Student & operator = (const Student s)


{

this->nume = new char(strlen(s.nume));


strcpy(this->nume, s.nume);
if (this != &s) // self - assignment check
if (this->NrNote != s.NrNote )
delete[] note;
this->NrNote = s.NrNote; // why no . operator
note = new int[NrNote];
for (int i = 0; i < NrNote; i++)
this->note[i] = s.note[i];
this->medie = 0;
this->varsta = 0;
this->integralist = s.integralist;

return *this

}
~Student()

delete[] nume;
delete[] note;
cout << " Am chemat destructorul " << endl;

};

inline Student::Student (char*nume, int* note, int NrNote , int varsta )

this->nume = new char(strlen(nume) + 1);


strcpy(this->nume, nume);
this->NrNote = NrNote;
this->varsta = varsta;
this->note = new int[NrNote];
for (int i = 0; i < NrNote; i++)
this->note[i] = note[i];

inline Student::Student(Student &s)

this->nume = new char(strlen(s.nume));


strcpy(this->nume, s.nume);
this->NrNote = s.NrNote;
note = new int[NrNote];
for (int i = 0; i < NrNote; i++)
this->note[i] = s.note[i];

this->medie = s.medie;
this->varsta = s.varsta;
this->integralist = s.integralist;
cout << " Constructorul de copiere " << endl;

inline Student::Student()
{

nume = new char(strlen("Anonim") + 1);


strcpy(this->nume, "Anonim");
this->NrNote = 10;
note = new int[NrNote];
for (int i = 0; i < NrNote; i++)
this->note[i] = 0;
this->medie = 0;
this->varsta = 0;
integralist = false;
cout << " Am chemat constructorul standard " << endl;

int main()
{

int note[] = { 5 , 7 , 9 , 10 , 7 };
Student s1;
Student s2 = s1;
Student s3;
Student s4("Mihai", note, sizeof(note) / sizeof(int), 12);
s3 = s4;
s3 = s2;
cout << s1;
//cout << s2;

S-ar putea să vă placă și