Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.81 KB | None | 0 0
  1. class Student {
  2.  
  3.     char* Name;
  4.     char EGN[11];
  5.     int facultyNumber;
  6.     double* grades;
  7.     int number_of_grades;
  8.     int capacity_of_grades;
  9.  
  10. public:
  11.  
  12.     Student() {
  13.  
  14.         Name = new char[1];
  15.         Name[0] = '\0';
  16.         EGN[0] = '\0';
  17.         facultyNumber = 0;
  18.         grades = new double[10];
  19.         capacity_of_grades = 10;
  20.         number_of_grades = 0;
  21.  
  22.     }
  23.  
  24.     Student(const char* Name_, const char* EGN_, const int facultyNumber_) {
  25.  
  26.         int nameLength = strlen(Name_);
  27.         Name = new char[nameLength + 1];
  28.  
  29.         strcpy_s(Name, nameLength + 1, Name_);
  30.         strcpy_s(EGN, EGN_);
  31.         facultyNumber = facultyNumber_;
  32.         grades = new double[10];
  33.         capacity_of_grades = 10;
  34.         number_of_grades = 0;
  35.  
  36.     }
  37.  
  38.     Student(const Student& other) {
  39.  
  40.         int nameLength = strlen(other.Name);
  41.         Name = new char[nameLength + 1];
  42.  
  43.         strcpy_s(Name, nameLength + 1, other.Name);
  44.         strcpy_s(EGN, other.EGN);
  45.         facultyNumber = other.facultyNumber;
  46.  
  47.     }
  48.  
  49.     Student& operator=(const Student& other) {
  50.  
  51.         if (this != &other) {
  52.  
  53.             delete[] Name;
  54.  
  55.             int nameLength = strlen(other.Name);
  56.             Name = new char[nameLength + 1];
  57.  
  58.             strcpy_s(Name, nameLength + 1, other.Name);
  59.             strcpy_s(EGN, other.EGN);
  60.             facultyNumber = other.facultyNumber;
  61.  
  62.         }
  63.  
  64.         return *this;
  65.  
  66.     }
  67.  
  68.     ~Student() {
  69.  
  70.         delete[] Name;
  71.  
  72.     }
  73.  
  74.     const char* get_Name() const {
  75.  
  76.         return Name;
  77.  
  78.     }
  79.  
  80.     const char* get_EGN() const {
  81.  
  82.         return EGN;
  83.  
  84.     }
  85.  
  86.     int get_facultyNumber() const {
  87.         return facultyNumber;
  88.  
  89.     }
  90.  
  91.     const double* get_grades() const {
  92.        
  93.         return grades;
  94.  
  95.     }
  96.  
  97.     void set_Name(const char* Name_) {
  98.  
  99.         delete[] Name;
  100.  
  101.         int nameLength = strlen(Name_);
  102.  
  103.         Name = new char[nameLength + 1];
  104.         strcpy_s(Name, nameLength + 1, Name_);
  105.  
  106.     }
  107.  
  108.     void set_EGN(const char* EGN_) {
  109.  
  110.         strcpy_s(EGN, EGN_);
  111.  
  112.     }
  113.  
  114.     void set_facultyNumber(int facultyNumber_) {
  115.  
  116.         facultyNumber = facultyNumber_;
  117.  
  118.     }
  119.  
  120.     void add_grade(double grade) {
  121.  
  122.         if (number_of_grades == capacity_of_grades) {
  123.  
  124.             capacity_of_grades += 10;
  125.             double* new_grade = new double[capacity_of_grades];
  126.  
  127.             for (int i = 0; i < number_of_grades; i++) {
  128.  
  129.                 new_grade[i] = grades[i];
  130.  
  131.             }
  132.  
  133.             new_grade[number_of_grades] = grade;
  134.  
  135.             number_of_grades++;
  136.  
  137.             delete[] grades;
  138.  
  139.             grades = new_grade;
  140.  
  141.         }
  142.  
  143.         else {
  144.  
  145.             grades[number_of_grades] = grade;
  146.             number_of_grades++;
  147.  
  148.         }
  149.     }
  150.  
  151.  
  152.     void print() const {
  153.  
  154.         cout << "Ime: " << Name << endl;
  155.         cout << "EGN: " << EGN << endl;
  156.         cout << "Faculty Number: " << facultyNumber << endl;
  157.         cout << "Ocenki: ";
  158.         for (int i = 0; i < number_of_grades; i++) {
  159.  
  160.             cout << grades[i] << " ";
  161.  
  162.         }
  163.         cout << endl;
  164.  
  165.     }
  166.  
  167.     void average() {
  168.  
  169.         double sum = 0;
  170.         for (int i = 0; i < number_of_grades; i++) {
  171.  
  172.             sum += grades[i];
  173.  
  174.         }
  175.  
  176.         cout << "Sredno aritmetichnoto na tekushtite ocenki e: " << sum / number_of_grades << endl;
  177.  
  178.     }
  179.  
  180. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement