Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 05 / Student.cpp
diff options
context:
space:
mode:
Commit60d2a40b31393a24e3f4327d182098248b2c6108 (patch)
Author
 Angel Dimitriev <angel_dimitriev@abv.bg>
2022-03-22 19:46:03 +0200
Committer
 GitHub <noreply@github.com>
2022-03-22 19:46:03 +0200
Files41d4d7d01d0f340a46c66c41d4a351008c13197e /Sem. 05/Student.cpp
Object-oriented_programming_FMI-60d2a40b31393a24e3f4327d182098248b2c6108.tar
Object-oriented_programming_FMI-60d2a40b31393a24e3f4327d182098248b2c6108.tar.gz
Object-oriented_programming_FMI-60d2a40b31393a24e3f4327d182098248b2c6108.zip
Parentb4a25be14014ae75aa487898f5a2868701bb9980 (diff)
Create Student.cpp
1 files changed, 85 insertions, 0 deletions
-rw-r--r--Sem. 05/Student.cpp85
diff --git a/Sem. 05/Student.cpp b/Sem. 05/Student.cpp
new file mode 100644
index 0000000..0bf2ce8
--- /dev/null
+++ b/Sem. 05/Student.cpp
@@ -0,0 +1,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);
+
+}