Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Student
- {
- private:
- const int nrStud;
- int nrNote = 0;
- int* note = NULL;
- public:
- static int nrPctCredit;
- Student(const int nrStud) :nrStud(nrStud)
- {
- }
- Student(const int nrStud, int* note, int nrNote) :nrStud(nrStud)
- {
- this->note = new int[nrNote];
- for (int i = 0; i < nrNote; i++)
- this->note[i] = note[i];
- this->nrNote = nrNote;
- }
- Student(const Student& s) :nrStud(s.nrStud)
- {
- this->nrNote = s.nrNote;
- this->note = new int[s.nrNote];
- for (int i = 0; i < s.nrNote; i++)
- this->note[i] = s.note[i];
- }
- void setNote(int* note, int nrNote)
- {
- this->nrNote = nrNote;
- this->note = new int[nrNote];
- for (int i = 0; i < nrNote; i++)
- this->note[i] = note[i];
- }
- int getNrNote()
- {
- return this->nrNote;
- }
- int getNrStud()
- {
- return this->nrStud;
- }
- int getNota(int index)
- {
- return note[index];
- }
- Student& operator=(const Student& s)
- {
- nrNote = s.nrNote;
- if (note != NULL)
- delete[] note;
- note = new int[s.nrNote];
- for (int i = 0; i < s.nrNote; i++)
- note[i] = s.note[i];
- return *this;
- }
- bool estePromovat(int nrPctCredit)
- {
- if (nrPctCredit > 14)
- return true;
- else
- return false;
- }
- explicit operator float()
- {
- float medie = 0;
- for (int i = 0; i < nrNote; i++)
- medie = medie + note[i];
- if (nrNote > 0)
- return medie / nrNote;
- else
- return 0;
- }
- Student operator++(int)
- {
- int* copy = new int[nrNote];
- for (int i = 0; i < nrNote; i++)
- copy[i] = note[i];
- nrNote++;
- delete[] note;
- note = new int[nrNote];
- for (int i = 0; i < nrNote - 1; i++)
- note[i] = copy[i];
- note[nrNote - 1] = note[nrNote - 2];
- delete[] copy;
- return *this;
- }
- ~Student()
- {
- delete[] note;
- }
- };
- int Student::nrPctCredit = 3;
- bool operator==(Student s1, Student s2)
- {
- int n1 = 0, n2 = 0;
- for (int i = 0; i < s1.getNrNote(); i++)
- if (s1.getNota(i) >= 5)
- n1++;
- for (int i = 0; i < s2.getNrNote(); i++)
- if (s2.getNota(i) >= 5)
- n2++;
- return n1 == n2;
- }
- void operator<<(ostream& out, Student& s)
- {
- out << "Studentul cu codul " << s.getNrStud() << " are " << s.getNrNote() << " note: ";
- for (int i = 0; i < s.getNrNote(); i++)
- out << s.getNota(i) << " ";
- }
- int main()
- {
- Student s1(102);
- cout << s1.getNrNote() << endl;
- int note[] = { 10, 7, 8, 10, 4 };
- Student s2(104, note, 5);
- cout << s2.getNrNote() << endl;
- Student s3 = s2;
- cout << s3.getNrStud() << endl;
- int note2[] = { 5, 5, 4, 10 };
- s1.setNote(note2, 4);
- cout << s1.getNrNote() << endl;
- Student::nrPctCredit = 4;
- s3 = s1;
- bool promovat = s3.estePromovat(15);
- if (promovat)
- cout << endl << "Studentul are un numar suficient de credite" << endl;
- else
- cout << endl << "Studentul nu are un numar suficient de credite" << endl;
- Student* ps1 = new Student(109);
- *ps1 = s1;
- cout << *ps1;
- delete ps1;
- float medie = (float)s1;
- cout << endl << medie << endl;
- s1 = s3++;
- cout << endl;
- cout << s1;
- cout << endl;
- cout << s3;
- cout << endl;
- if (s1 == s3)
- cout << "Studentul 1 are acelasi numar de note de trecere ca studentul 3";
- else
- cout << "Studentul 1 nu are acelasi numar de note de trecere ca studentul 3";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement