Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Student
- {
- private: // implicit sunt private.
- char *nume;
- int varsta;
- float medieAdmitere;
- int note[20];
- int nrNote;
- //pentru acces- public:
- //validari. -constructori NU declarati in zona private.
- public:
- Student() {
- cout << "\n Apel constructor fara parametri ";
- this->nume = new char[strlen("N\\A") + 1];
- strcpy(this->nume, "N\\A");
- this->varsta = 0;
- this->medieAdmitere = 0;
- this->nrNote = 0;
- }
- Student(char *nume, int nrNote, int *note, int varsta, float medieAdmitere=6.0) //sau ():varsta(varsta) //putem folosi _ pt a nu ne incruca in denumiri this->nume vs nume simplu. nte e scris gresit .
- {
- cout << "\n Apel constructor cu parametri ";
- if (nume != NULL)
- {
- this->nume = new char[strlen(nume) + 1];
- strcpy(this->nume, nume);
- }
- else
- this->nume = NULL;
- this->varsta = varsta;
- this->medieAdmitere = medieAdmitere;
- this->nrNote = nrNote;
- for (int i = 0; i < this->nrNote; i++)
- this->note[i] = note[i];
- }
- //accesori (get si set)
- getMedieAdmitere() {
- return this->medieAdmitere;
- }
- void afisare() {
- cout << "\n ****************************************";
- if(this->nume !=NULL) //verificam daca s-a alocat memorie
- cout << "\n Nume: " << this->nume;
- cout << "\n Varsta: " << this->varsta;
- cout << "\n Medie admitere: " << this->medieAdmitere;
- if (this->nrNote > 0) {
- cout << "\Note: ";
- for (int i = 0; i < this->nrNote; i++)
- cout << this->note[i] << " ";
- }
- else cout << "\n Nu detine note !";
- cout << "\n ****************************************";
- }
- };
- //transfer prin valoare.
- int comparareStudent(Student s1, Student s2) {
- if (s1.getMedieAdmitere() > s2.getMedieAdmitere())
- return 1;
- else
- if (s1.getMedieAdmitere() == s2.getMedieAdmitere())
- return 0;
- }
- void main()
- {
- Student s;
- Student *ps=new Student(); //pointer ce pointeaza la o adresa.,trebuie alocata memorie sau new Student [3];
- s.afisare();
- //Student vs[10];
- char nume[] = "gigel";
- int note[] = { 10,7,4 };
- Student s2(nume, 3, note, 19, 8.5);
- s2.afisare();
- Student s3(nume, 3, note, 19);
- s3.afisare(); //s-a folosit valoarea default
- Student s4(nume, 3, note,19);
- s4.afisare();
- cout << "\n Rezultat comparare " << comparareStudent(s2, s3);
- //incercare in interiorul clasei.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement