Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 09 / task1 (not finished) / Grade.cpp
blob: 43021660b5184d3f5ef4a416f5491cd01d943c2b (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
#include "Grade.h"


Grade::Grade() : taskName(nullptr)
{
	setTaskName("Unknown");
	setGrade(2);
}

Grade::Grade(const char* taskName, size_t gradeValue) : taskName(nullptr)
{
	setTaskName(taskName);
	setGrade(gradeValue);
}

void Grade::free()
{
	delete[] taskName;
}
void Grade::copyFrom(const Grade& other)
{
	gradeValue = other.gradeValue;

	taskName = new char[strlen(other.taskName) + 1];
	strcpy(taskName, other.taskName);
}

Grade::Grade(const Grade& other)
{
	copyFrom(other);
}

Grade& Grade::operator=(const Grade& other)
{
	if (this != &other)
	{
		free();
		copyFrom(other);
	}
	return *this;
}
Grade::~Grade()
{
	free();
}

const char* Grade::getTaskName() const
{
	return taskName;
}
size_t Grade::getGrade() const
{
	return gradeValue;
}

void Grade::setGrade(size_t grade)
{
	if (grade < 2 || grade > 6)
		throw std::exception("error!");
	
	gradeValue = grade;
}

void Grade::setTaskName(const char* name)
{
	delete[] taskName;
	taskName = new char[strlen(name) + 1];
	strcpy(taskName, name);
}