blob: 55b3e3aede82c603ba0e17be35be5dd56028465c (
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
|
#pragma warning(disable: 4996)
#include "Drink.h"
#include <iostream>
Drink::Drink() : Drink("Unknown", 0)
{}
const char* Drink::getName() const
{
return name;
}
int Drink::getMl() const
{
return ml;
}
void Drink::setName(const char* name)
{
delete[] this->name;
this->name = new char[strlen(name) + 1];
strcpy(this->name, name);
}
void Drink::setMl(int ml)
{
const int MAX_ML = 1000;
const int MIN_ML = 100;
ml = MIN_ML;
if (MIN_ML <= ml && ml <= MAX_ML)
this->ml = ml;
}
Drink::Drink(const char* name, int ml) : name(nullptr)
{
setName(name);
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::copyFrom(const Drink& other)
{
name = new char[strlen(other.name) + 1];
strcpy(name, other.name);
ml = other.ml;
}
void Drink::free()
{
delete[] name;
ml = 0;
}
|