diff options
added new examples
6 files changed, 0 insertions, 204 deletions
| -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/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();
-};
|
