Advertisement
frentzy

test lab 1 momentan

Mar 20th, 2018
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #pragma warning(disable:4996)
  2. #include <conio.h>
  3. #include <iostream>
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. using namespace std;
  7.  
  8. class Student {
  9. private:
  10.     char *nume;
  11.     int nota;
  12. public:
  13.     Student(char *nume = 0, int nota = 0);
  14.     Student(const Student  &s);
  15. //  Student();
  16.     ~Student();
  17.     char* getNume();
  18.     int getNota();
  19.     void SetNume(char *nume);
  20.     void SetNota(int nota);
  21.     void afis();
  22.     void citeste();
  23. };
  24.  
  25. Student::Student(char *nume, int nota) {
  26.     if (nume != NULL) {
  27.     this->nume = new char[strlen(nume) + 1];
  28.     strcpy_s(this->nume, strlen(nume) + 1, nume);
  29. }
  30.     else this->nume = NULL;
  31.     this->nota = nota;
  32. }
  33.  
  34. Student::Student(const Student  &s) {
  35.     this->nume = new char[strlen(s.nume) + 1];
  36.     strcpy(this->nume, s.nume);
  37.     this->nota = s.nota;
  38. }
  39.  
  40. char *Student::getNume() {
  41.     return this->nume;
  42. }
  43.  
  44. int Student::getNota() {
  45.     return nota;
  46. }
  47. Student::~Student() {
  48.     if (nume != NULL)
  49.         delete nume;
  50. }
  51.  
  52.  
  53.  
  54. void Student::SetNume(char *nume) {
  55.     strcpy(this->nume, nume);
  56. }
  57.  
  58. void Student::SetNota(int nota) {
  59.     this->nota = nota;
  60. }
  61.  
  62. void Student::afis() {
  63.     if (nume != NULL)
  64.         cout << nume << ": " << nota << endl;
  65. }
  66.  
  67. void Student::citeste() {
  68.     char aux[75];
  69.     cout << "Nume: ";cin >> aux;
  70.     this->nume = new char[strlen(aux) + 1];
  71.     strcpy(this->nume, aux);
  72.     cout << "Nota: ";cin >> nota;
  73.     cout << endl;
  74. }
  75.  
  76. class Catalog {
  77.     private:
  78.         int nr;
  79.         Student *s;
  80.     public:
  81.         Catalog(int n);
  82.         ~Catalog();
  83.         void afis();
  84.         void Citeste();
  85.        
  86. };
  87.  
  88. Catalog::Catalog(int n) {
  89.     this->nr = n;
  90.     s = new Student[nr];
  91. }
  92. Catalog::~Catalog() {
  93.     if (nr != 0)
  94.         delete s;
  95. }
  96.  
  97. void Catalog::afis() {
  98.     for (int i = 0;i < nr;i++) {
  99.     //  cout << i + 1 << "." << s[i].getNume << ": " << s[i].getNota;
  100.         s[i].afis();
  101.     }
  102. }
  103.  
  104. void Catalog::Citeste() {
  105.     for (int i = 0;i < nr;i++) {
  106. //      cout << "Student" << i << "." << endl;
  107.         s[i].citeste();
  108.     }
  109. }
  110.  
  111.  
  112. void main() {
  113.     Catalog classA(3);
  114.     classA.Citeste();
  115.     classA.afis();
  116.  
  117.  
  118.  
  119.     _getch();
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement