Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 05 / Student.cpp
blob: 0bf2ce851836e10688f7e5f3fe448a72af12841e (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
#include <iostream>
using namespace std;

bool isSmallLetter(char ch)
{
	return ch >= 'a' && ch <= 'z';
}
bool isCapitalLetter(char ch)
{
	return ch >= 'A' && ch <= 'Z';
}
bool containsOnlySmallChars(const char* str)
{
	size_t len = strlen(str);

	for (int i = 0; i < len; i++)
	{
		if (!isSmallLetter(str[i]))
			return false;
	}
	return true;
}

class Student
{
	char name[20];
	int age;

	bool isValidAge(int age)
	{
		return age >= 15 && age <= 60;
	}

	bool isValidName(const char* name)
	{
		if (name == nullptr)
			return false;

		if (strlen(name) >= 20)
			return false;

		if (!isCapitalLetter(*name))
			return false;
		return containsOnlySmallChars(name + 1);
	}

public:
	Student(const char* name, int age)
	{
		setName(name);
		setAge(age);
	}

	int getAge() const //връщаме копие!!
	{
		return age;
	}

	const char* const getName()//копие на указателя!!!
	{
		return name;
	}

	void setName(const char* name)
	{
		if (isValidName(name))
			strcpy(this->name, name);
		else
			strcpy(this->name, "Unknown");

	}
	void setAge(int age)
	{
		if (isValidAge(age))
			this->age = age;
		else
			this->age = 15;
	}
};

int main()
{
	Student s("Ivan", 33);

}