diff options
added new examples
11 files changed, 0 insertions, 330 deletions
| -rw-r--r-- | Big4AndInheritance/Drinks/AlcoholDrink.cpp | 18 | ||||
| -rw-r--r-- | Big4AndInheritance/Drinks/AlcoholDrink.h | 14 | ||||
| -rw-r--r-- | Big4AndInheritance/Drinks/Drink.cpp | 63 | ||||
| -rw-r--r-- | Big4AndInheritance/Drinks/Drink.h | 21 | ||||
| -rw-r--r-- | Big4AndInheritance/Drinks/main.cpp | 10 | ||||
| -rw-r--r-- | Big4AndInheritance/Students/GradesBook.cpp | 91 | ||||
| -rw-r--r-- | Big4AndInheritance/Students/GradesBook.h | 27 | ||||
| -rw-r--r-- | Big4AndInheritance/Students/Student.cpp | 10 | ||||
| -rw-r--r-- | Big4AndInheritance/Students/Student.h | 15 | ||||
| -rw-r--r-- | Big4AndInheritance/Students/User.cpp | 43 | ||||
| -rw-r--r-- | Big4AndInheritance/Students/User.h | 18 |
diff --git a/Big4AndInheritance/Drinks/AlcoholDrink.cpp b/Big4AndInheritance/Drinks/AlcoholDrink.cpp deleted file mode 100644 index db3619c..0000000 --- a/Big4AndInheritance/Drinks/AlcoholDrink.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "AlcoholDrink.h"
-
-
-
-AlcoholDrink::AlcoholDrink(const char* mark, int ml, int percentAlcohol) : Drink(mark,ml)
-{
- setAlcohol(percentAlcohol);
-}
-void AlcoholDrink::setAlcohol(int alcohol)
-{
- if (alcohol < 4 || alcohol>98)
- alcohol = 20;
- percentAlcohol = alcohol;
-}
-int AlcoholDrink::getAlcohol() const
-{
- return percentAlcohol;
-}
diff --git a/Big4AndInheritance/Drinks/AlcoholDrink.h b/Big4AndInheritance/Drinks/AlcoholDrink.h deleted file mode 100644 index 1bf3d66..0000000 --- a/Big4AndInheritance/Drinks/AlcoholDrink.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once
-
-#include "Drink.h"
-
-class AlcoholDrink : public Drink
-{
-private:
- int percentAlcohol;
-
-public:
- AlcoholDrink(const char* mark, int ml, int percentAlcohol);
- void setAlcohol(int alcohol);
- int AlcoholDrink::getAlcohol() const;
-};
diff --git a/Big4AndInheritance/Drinks/Drink.cpp b/Big4AndInheritance/Drinks/Drink.cpp deleted file mode 100644 index a2933ad..0000000 --- a/Big4AndInheritance/Drinks/Drink.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#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;
-}
diff --git a/Big4AndInheritance/Drinks/Drink.h b/Big4AndInheritance/Drinks/Drink.h deleted file mode 100644 index c02398b..0000000 --- a/Big4AndInheritance/Drinks/Drink.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once
-#include <iostream>
-
-class Drink
-{
-private:
- char* mark;
- int ml;
- void CopyFrom(const Drink& other);
- void Free();
-public:
- Drink();
- Drink(const char* mark, int ml);
- Drink(const Drink& other);
- Drink& operator=(const Drink& other);
- ~Drink();
-
- void setML(int ml);
- int getML() const;
- const char* getMark() const;
-};
diff --git a/Big4AndInheritance/Drinks/main.cpp b/Big4AndInheritance/Drinks/main.cpp deleted file mode 100644 index 6c67b96..0000000 --- a/Big4AndInheritance/Drinks/main.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "AlcoholDrink.h"
-int main()
-{
- AlcoholDrink DR1("Spirt", 100, 98);
-
- AlcoholDrink dr2 (DR1);
- dr2.getMark();
-
-
-}
diff --git a/Big4AndInheritance/Students/GradesBook.cpp b/Big4AndInheritance/Students/GradesBook.cpp deleted file mode 100644 index 759a63c..0000000 --- a/Big4AndInheritance/Students/GradesBook.cpp +++ /dev/null @@ -1,91 +0,0 @@ -#include "GradesBook.h"
-
-
-GradesBook::GradesBook()
-{
- capacity = 4;
- grades = new int[capacity];
- size = 0;
-}
-GradesBook::GradesBook(const GradesBook& other)
-{
- std::cout << "Copy contr of GradesBook" << std::endl;
- CopyFrom(other);
-}
-GradesBook& GradesBook::operator=(const GradesBook& other)
-{
- if (this != &other)
- {
- Free();
- CopyFrom(other);
- }
- return *this;
-}
-GradesBook::~GradesBook()
-{
- Free();
-}
-
-
-void GradesBook::CopyFrom(const GradesBook& other)
-{
- grades = new int[other.capacity];
- for (int i = 0; i < other.size; i++)
- grades[i] = other.grades[i];
- capacity = other.capacity;
- size = other.size;
-}
-void GradesBook::Free()
-{
- delete[] grades;
-}
-
-
-bool GradesBook::isFull()
-{
- return size == capacity;
-}
-void GradesBook::AddGrade(int grade)
-{
- if (!isValidGrade(grade))
- return;
- if (isFull())
- Resize();
- grades[size++] = grade;
-
-}
-void GradesBook::Resize()
-{
- int* temp = new int[capacity * 2];
- for (int i = 0; i < size; i++)
- temp[i] = grades[i];
- capacity *= 2;
- delete[] grades;
- grades = temp;
-}
-void GradesBook::RemoveLastGrade()
-{
- size--;
-}
-bool GradesBook::isValidGrade(int grade)
-{
- return (grade >= 2 && grade <= 6);
-}
-int GradesBook::operator[](int index) const
-{
- if (index < 0 || index >= size)
- return -1;
- return grades[index];
-}
-
-std::ostream& operator<<(std::ostream& stream, GradesBook& obj)
-{
- for (int i = 0; i < obj.capacity; i++)
- {
- if (i < obj.size)
- stream << obj.grades[i] << ' ';
- else
- stream << '_' << ' ';
- }
- return stream;
-}
\ No newline at end of file diff --git a/Big4AndInheritance/Students/GradesBook.h b/Big4AndInheritance/Students/GradesBook.h deleted file mode 100644 index e1dd262..0000000 --- a/Big4AndInheritance/Students/GradesBook.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once
-#include <iostream>
-
-class GradesBook
-{
- int* grades;
- int size;
- int capacity;
-
- bool isValidGrade(int grade);
- void Resize();
- void CopyFrom(const GradesBook& other);
- void Free();
-public:
- GradesBook();
- GradesBook(const GradesBook& other);
- GradesBook& operator=(const GradesBook& other);
- ~GradesBook();
-
- bool isFull();
- void AddGrade(int grade);
- void RemoveLastGrade();
-
- int operator[](int index) const;
- friend std::ostream& operator<<(std::ostream& stream, GradesBook& obj);
-
-};
diff --git a/Big4AndInheritance/Students/Student.cpp b/Big4AndInheritance/Students/Student.cpp deleted file mode 100644 index e3d5f06..0000000 --- a/Big4AndInheritance/Students/Student.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Student.h"
-Student::Student(const char* name, int age, int fn): User(name,age)
-{
- this->fn = fn;
-}
-
-void Student::ReceiveGrade(int grade)
-{
- b.AddGrade(grade);
-}
\ No newline at end of file diff --git a/Big4AndInheritance/Students/Student.h b/Big4AndInheritance/Students/Student.h deleted file mode 100644 index 45a103d..0000000 --- a/Big4AndInheritance/Students/Student.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once
-#include "User.h"
-#include "GradesBook.h"
-
-class Student : public User
-{
-public:
- int fn;
- GradesBook b;
-
- Student(const char* name, int age, int fn);
- void ReceiveGrade(int grade);
-
-
-};
diff --git a/Big4AndInheritance/Students/User.cpp b/Big4AndInheritance/Students/User.cpp deleted file mode 100644 index 27947b1..0000000 --- a/Big4AndInheritance/Students/User.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include "User.h"
-
-/*
-User::User(): name(nullptr),age(10)
-{
-
-}
-*/
-
-User::User(const char* name, int age)
-{
- this->name = new char[strlen(name) + 1];
- strcpy(this->name, name);
- this->age = age;
-}
-User::User(const User& other)
-{
- cout << "Copy contr of user" << endl;
- CopyFrom(other);
-}
-User& User::operator=(const User& other)
-{
- if (this != &other)
- {
- Free();
- CopyFrom(other);
- }
- return *this;
-}
-User::~User()
-{
- Free();
-}
-void User::CopyFrom(const User& other)
-{
- name = new char[strlen(other.name) + 1];
- strcpy(name, other.name);
- age = other.age;
-}
-void User::Free()
-{
- delete[] name;
-}
\ No newline at end of file diff --git a/Big4AndInheritance/Students/User.h b/Big4AndInheritance/Students/User.h deleted file mode 100644 index d84bd71..0000000 --- a/Big4AndInheritance/Students/User.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once
-
-#include <iostream>
-using namespace std;
-class User
-{
-private:
- char* name;
- int age;
- void CopyFrom(const User& other);
- void Free();
-public:
- //User();
- User(const char*name, int age);
- User(const User& other);
- User& operator=(const User& other);
- ~User();
-};
|
