Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class Student
  4. {
  5. private: // implicit sunt private.
  6. char *nume;
  7. int varsta;
  8. float medieAdmitere;
  9. int note[20];
  10. int nrNote;
  11. //pentru acces- public:
  12. //validari. -constructori NU declarati in zona private.
  13.  
  14. public:
  15. Student() {
  16. cout << "\n Apel constructor fara parametri ";
  17. this->nume = new char[strlen("N\\A") + 1];
  18. strcpy(this->nume, "N\\A");
  19. this->varsta = 0;
  20. this->medieAdmitere = 0;
  21. this->nrNote = 0;
  22. }
  23. 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 .
  24. {
  25. cout << "\n Apel constructor cu parametri ";
  26. if (nume != NULL)
  27. {
  28. this->nume = new char[strlen(nume) + 1];
  29. strcpy(this->nume, nume);
  30. }
  31. else
  32. this->nume = NULL;
  33. this->varsta = varsta;
  34. this->medieAdmitere = medieAdmitere;
  35. this->nrNote = nrNote;
  36. for (int i = 0; i < this->nrNote; i++)
  37. this->note[i] = note[i];
  38.  
  39. }
  40. //accesori (get si set)
  41. getMedieAdmitere() {
  42. return this->medieAdmitere;
  43. }
  44.  
  45. void afisare() {
  46. cout << "\n ****************************************";
  47. if(this->nume !=NULL) //verificam daca s-a alocat memorie
  48. cout << "\n Nume: " << this->nume;
  49. cout << "\n Varsta: " << this->varsta;
  50. cout << "\n Medie admitere: " << this->medieAdmitere;
  51. if (this->nrNote > 0) {
  52. cout << "\Note: ";
  53. for (int i = 0; i < this->nrNote; i++)
  54. cout << this->note[i] << " ";
  55. }
  56. else cout << "\n Nu detine note !";
  57. cout << "\n ****************************************";
  58. }
  59.  
  60.  
  61.  
  62. };
  63. //transfer prin valoare.
  64. int comparareStudent(Student s1, Student s2) {
  65. if (s1.getMedieAdmitere() > s2.getMedieAdmitere())
  66. return 1;
  67. else
  68. if (s1.getMedieAdmitere() == s2.getMedieAdmitere())
  69. return 0;
  70.  
  71. }
  72.  
  73. void main()
  74. {
  75. Student s;
  76.  
  77. Student *ps=new Student(); //pointer ce pointeaza la o adresa.,trebuie alocata memorie sau new Student [3];
  78. s.afisare();
  79. //Student vs[10];
  80. char nume[] = "gigel";
  81. int note[] = { 10,7,4 };
  82. Student s2(nume, 3, note, 19, 8.5);
  83. s2.afisare();
  84. Student s3(nume, 3, note, 19);
  85. s3.afisare(); //s-a folosit valoarea default
  86. Student s4(nume, 3, note,19);
  87. s4.afisare();
  88.  
  89. cout << "\n Rezultat comparare " << comparareStudent(s2, s3);
  90.  
  91. //incercare in interiorul clasei.
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement