Website Summary Files Commits Branches @commit @diff @stats
path: root / Big4AndInheritance / Drink.cpp
blob: 0e5bc778a0d9ae1578d83aa6ae5fc1a723bcb902 (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
#include "Drink.h"


void Drink::CopyFrom(const Drink& other)
{
	int len = strlen(other.mark);
	mark = new char[len + 1];
	strcpy(mark, other.mark);

	ml = other.ml;
}
void Drink::Free()
{
	delete[] mark;
	ml = 0;
}

Drink::Drink()
{
	mark = new char[6];
	strcpy(mark, "Water");
	ml = 500;
}
Drink::Drink(const char* mark, int ml)
{
	int len = strlen(mark);
	this->mark = new char[len + 1];
	strcpy(this->mark, mark);
	
	setML(ml);

}
Drink::Drink(const Drink& other)
{
	CopyFrom(other);
}
Drink& Drink::operator=(const Drink& other)
{
	if (this != &other)
	{
		Free();
		CopyFrom(other);
	}
	return *this;
}
Drink::~Drink()
{
	Free();
}
void Drink::setML(int ml)
{
	if (ml < 100 || ml> 1000)
		ml = 500;
	this->ml = ml;
}
int Drink::getML() const
{
	return ml;
}
const char* Drink::getMark() const
{
	return mark;
}