Website Summary Files Commits Branches @commit @diff @stats
path: root / Big4_basic_examples / InformaticsStudent
diff options
context:
space:
mode:
Commit0218c678e13e1cb94a352c91733cea68467dc566 (patch)
Author
 Angeld55 <angel_dimitriev@abv.bg>
2021-02-14 23:06:35 +0200
Committer
 Angeld55 <angel_dimitriev@abv.bg>
2021-02-14 23:06:35 +0200
Files16fb3114cb560242458d10411765e50f5d6183db /Big4_basic_examples/InformaticsStudent
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.tar
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.tar.gz
Object-oriented_programming_FMI-0218c678e13e1cb94a352c91733cea68467dc566.zip
Parentd4ae0ef9ec1b54420176c4a88e09f2fd44ae31b0 (diff)
start from scratch
diff --git a/Big4_basic_examples/InformaticsStudent/InformaticsStudent.cpp b/Big4_basic_examples/InformaticsStudent/InformaticsStudent.cpp
deleted file mode 100644
index 9073355..0000000
--- a/Big4_basic_examples/InformaticsStudent/InformaticsStudent.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-#include "InformaticsStudent.h"
-#include <cstring>
-
-
-bool hasDigits(const char* str,int len)
-{
- for (int i = 0; i < len;i++)
- {
- if (str[i] >= '0' && str[i] <= '9')
- return true;
- }
- return false;
-}
-
-void InformaticsStudent::CopyFrom(const InformaticsStudent& other)
-{
- int len = strlen(other.name);
- name = new char[len + 1];
- strcpy(name, other.name); //copy name
- fn = other.fn; //copy fn
-}
-void InformaticsStudent::Free()
-{
- delete[] name;
- fn = 0;
-}
-
-InformaticsStudent::InformaticsStudent()
-{
- name = nullptr;
- fn = 0;
-}
-
-InformaticsStudent::InformaticsStudent(const char* name, int fn) //При конструктура винаги КОПИРАМЕ подадения стринг за нашния нов обект.
-{ // Това е важно, защото не искаме някой друг да има достъп до него.
- setName(name);
- setFn(fn);
-}
-
-
-InformaticsStudent::InformaticsStudent(const InformaticsStudent& other)
-{
- //Използваме функцията, която копира всичко от other в нашия обект.
- CopyFrom(other);
-
- //Понеже това е конструктор, няма нужда да трия нищо от обекта, понеже няма как да е имало данни тук,защото сега го създаваме.
-}
-
-InformaticsStudent& InformaticsStudent::operator=(const InformaticsStudent& other)
-{
- //За разлика от при Копи-контструктора , тука е имало данни , преди копирането
- // (обектът да е съществувал). За това преди да копираме трябва да изтрием това, което е седяло тук.
- // Проверката на 44 ред е с цел да не стане нещо от сорта T1=T1. Това би изтрило данните в обекта, защото първо трием и после
- // присвояваме вече изтритите данни.
-
- if (this != &other)
- {
- Free(); //трия своята памет
-
- CopyFrom(other); // копирам от другия обект
- }
- return *this; // Връщаме указател към обекта, в който сме копирали, за може да chain-ваме T1=T2=T3.
-}
-
-InformaticsStudent::~InformaticsStudent()
-{
- Free();
-}
-
-
-void InformaticsStudent::setName(const char* name)
-{
- delete[] name; //трием данните, които са били тук.
- int len = strlen(name);
- if (hasDigits(name, len))
- {
- this->name[0] = '\0';
- return;
- }
- this->name = new char[len + 1];
- strcpy(this->name, name);
-
-
-}
-void InformaticsStudent::setFn(int fn)
-{
- if (fn < 45000 || fn >45999)
- fn = 45000;
- this->fn = fn;
-}
-const char* InformaticsStudent::getName() const
-{
- return name;
-}
-int InformaticsStudent::getFn() const
-{
- return fn;
-}
-
-void InformaticsStudent::printStudent() const
-{
- std::cout << name << " fn: " << fn << std::endl;
-}
diff --git a/Big4_basic_examples/InformaticsStudent/InformaticsStudent.h b/Big4_basic_examples/InformaticsStudent/InformaticsStudent.h
deleted file mode 100644
index 6e9d743..0000000
--- a/Big4_basic_examples/InformaticsStudent/InformaticsStudent.h
+++ /dev/null
@@ -1,40 +0,0 @@
-
-// Голямта 4-ка - Функции, които трябва да разпишем, САМО когато имаме динамична памет в класа.
-
-// 1.Defualt constructor InformaticsStudent();
-// 2.Copy-constructor InformaticsStudent(const InformaticsStudent& other);
-// 3.operator= InformaticsStudent& operator=(const InformaticsStudent& other);
-// 4.Destructor ~InformaticsStudent()
-// (Най-лесно е като си разпишем функция за копиране CopyFrom и функция за триене Free())
-
-#pragma once
-#include <iostream>
-
-class InformaticsStudent
-{
-private:
- char* name;
- int fn;
-
- void CopyFrom(const InformaticsStudent& other);
- void Free();
-
-public:
- /// BIG 4 starts here
-
- InformaticsStudent();
- InformaticsStudent(const InformaticsStudent& other);
- InformaticsStudent& operator=(const InformaticsStudent& other);
- ~InformaticsStudent();
- // BIG 4 ends here
-
- InformaticsStudent(const char* name, int fn);
-
- void setName(const char* name);
- void setFn(int fn);
- const char* getName() const;
- int getFn() const;
-
- void printStudent() const;
-
-};