Website Summary Files Commits Branches @commit @diff @stats
path: root / Utils / BigFour.cpp
blob: 383440dbb222c3fcb90d5d0501fd517062c18b5f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89

#include <iostream>
#include <cstring>

using namespace std;

class Student
{
    char* name;
    int* grades;
    size_t gradesSize;
    
    void free()
    {
        delete[] name, grades;
    }
    
    void copyFrom(const Student& other)
    {
        setName(other.name);
        setGrades(other.grades);
    }
    
    public:
    
    Student() : name(nullptr), grades(nullptr) {}
    
    Student(const Student& other)
    {
        copyFrom(other);
    }
    
    Student& operator=(const Student& other)
    {
        if (this != &other)
        {
        	free();
        	copyFrom(other);
        }
        return *this;
    }
    
    ~Student()
    {
        free();
    }
    
    const char* getName() const
    {
        return name;
    }
    
    const int* getGrades() const
    {
        return grades;
    }
    
    void setName(const char* givenName)
    {
        if(givenName == nullptr || givenName == name)
             return;
        delete[] name;
        name = new char[strlen(givenName) + 1];
        strcpy(name, givenName);
    }
    
    void setGrades(const int* givenGrades, size_t size)
    {
        if(givenGrades == nullptr || givenGrades == grades)
              return;

        delete[] grades;
        
        grades = new int[size];
        for(size_t i = 0; i< size; i++)
            grades[i] = givenGrades[i];
        gradesSize = size;
    }
    
    
};

int main()
{


    return 0;
}