Compare commits

..

No commits in common. "lesson_2" and "master" have entirely different histories.

3 changed files with 0 additions and 248 deletions

View File

@ -1,117 +0,0 @@
#ifndef EXERCISE_1_HPP_
#define EXERCISE_1_HPP_
#include <iostream>
enum Gender
{
GENDER_MALE,
GENDER_FEMALE
};
class Person
{
private:
std::string m_name;
int m_age;
Gender m_gender;
float m_weight;
public:
Person(std::string name, int age, Gender gender, float weight) :
m_name(name), m_age(age), m_gender(gender), m_weight(weight) {}
void setName(std::string name = "")
{
if (name == "")
{
std::cout << "Введите новое имя: ";
std::cin >> m_name;
}
else
m_name = name;
}
void setAge(int age = 0)
{
if (age == 0)
{
std::cout << "Введите возраст: ";
std::cin >> m_age;
}
else
m_age = age;
}
void setWeight(float weight = 0.0)
{
if (weight == 0)
{
std::cout << "Введите вес: ";
std::cin >> m_weight;
}
else
m_weight = weight;
}
void printInfo() const
{
std::cout << "Имя: " << m_name << std::endl
<< "Возраст: " << m_age << std::endl
<< "Пол: " << (m_gender == GENDER_MALE ? "муж" : "жен") << std::endl
<< "Вес: " << m_weight << std::endl;
}
};
class Student : public Person
{
private:
static int count;
int m_yos; // year of study
public:
Student(std::string name, int age, Gender gender, float weight, int yos) :
Person(name, age, gender, weight), m_yos(yos)
{
count++;
}
Student(const Student &s) : Person(s)
{
count++;
m_yos = s.m_yos;
}
static void printCount()
{
std::cout << "Количество студентов: " << count << std::endl;
}
void setYearStudy(int yos = 0)
{
if (yos == 0)
{
std::cout << "Введите год обучения: ";
std::cin >> m_yos;
}
else
m_yos = yos;
}
void incYear()
{
m_yos++;
}
void printInfo() const
{
Person::printInfo();
std::cout << "Год обучения: " << m_yos << std::endl;
}
~Student()
{
count--;
}
};
#endif

View File

@ -1,68 +0,0 @@
#ifndef EXERCISE_2_HPP_
#define EXERCISE_2_HPP_
#include <iostream>
class Fruit
{
private:
std::string m_name;
std::string m_color;
public:
void setName(std::string name)
{
m_name = name;
}
void setColor(std::string color)
{
m_color = color;
}
const std::string& getName() const
{
return m_name;
}
const std::string& getColor() const
{
return m_color;
}
};
class Apple : public Fruit
{
public:
Apple(std::string color = "")
{
if (color == "")
color = "green";
setName("apple");
setColor(color);
}
};
class Banana : public Fruit
{
public:
Banana(std::string color = "")
{
if (color == "")
color = "yellow";
setName("banana");
setColor(color);
}
};
class GrannySmith : public Apple
{
public:
GrannySmith()
{
setName("Granny Smith " + Apple::getName());
}
};
#endif

View File

@ -1,63 +0,0 @@
#include <iostream>
#include <vector>
#include "exercise_1.hpp"
#include "exercise_2.hpp"
using namespace std;
int Student::count = 0;
int main()
{
vector<Student> students;
students.emplace_back("Олег", 20, GENDER_MALE, 75.2, 2020);
students.emplace_back("Андрей", 19, GENDER_MALE, 72.8, 2020);
Student::printCount();
students.emplace_back("Анастасия", 20, GENDER_FEMALE, 55.2, 2020);
students.emplace_back("Ольга", 21, GENDER_FEMALE, 49.3, 2020);
students.emplace_back("Владимир", 19, GENDER_MALE, 69.9, 2020);
Student::printCount();
// Exercise 2
Apple a("red");
Banana b;
GrannySmith c;
std::cout << "My " << a.getName() << " is " << a.getColor() << ".\n";
std::cout << "My " << b.getName() << " is " << b.getColor() << ".\n";
std::cout << "My " << c.getName() << " is " << c.getColor() << ".\n";
// Exercise 3
/*
Для реализации игры в Блэкджек необходимы данные объекты:
1) Колода карт
2) Игрок
3) Дилер
Исходя из указанных объектов можно определить несколько классов:
1) Карта
- номинал
- масть
2) Колода
- массив ссылок на объекты класса Карта
3) Игрок (абстрактный класс)
- Имя игрока
4) Игрок (человек, потомок от абстрактного класса Игрок)
5) Дилер (человек, потомок от абстрактного класса Игрок)
6) Рука (набор карт)
- массив ссылок на карты каждого игрока
7) Игра
- текущая Колода
- текущий Дилер
- текущий Игрок
*/
return 0;
}