Website Summary Files Commits Branches @commit @diff @stats
path: root / Big4AndInheritance / Students / GradesBook.cpp
diff options
context:
space:
mode:
Commit112a0d344da9e66d20ee9ab5d488e59c5d52e6ad (patch)
Author
 Angeld55 <angel_dimitriev@abv.bg>
2020-04-09 18:09:42 +0300
Committer
 Angeld55 <angel_dimitriev@abv.bg>
2020-04-09 18:09:42 +0300
Filese3bb9cf17c24a3b53c746d9142906d550d549465 /Big4AndInheritance/Students/GradesBook.cpp
Object-oriented_programming_FMI-112a0d344da9e66d20ee9ab5d488e59c5d52e6ad.tar
Object-oriented_programming_FMI-112a0d344da9e66d20ee9ab5d488e59c5d52e6ad.tar.gz
Object-oriented_programming_FMI-112a0d344da9e66d20ee9ab5d488e59c5d52e6ad.zip
Parentec26fab32d144b436d08f9da6049bd053156d783 (diff)
added new examples
1 files changed, 0 insertions, 91 deletions
-rw-r--r--Big4AndInheritance/Students/GradesBook.cpp91
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