Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

КМБО-06-21 Нечаев Иван #49

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 88 additions & 3 deletions animals/animal.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,92 @@
#include <iostream>
#include "animal.h"

#include <sstream>
using namespace std;


string Animal::about() const {
stringstream ss;
ss << "herbivore_or_carnivorous? : " << herbivore_or_carnivorous << endl;
return ss.str();
}


string Mammal::about() const {
stringstream ss;
ss << Animal::about() << "\t" << "milk_glands: " << milk_glands << endl;
return ss.str();
}


string Tiger::about() const {
stringstream ss;
ss << Animal::about() << "\t" << Mammal::about() << "color_tiger: " << color_tiger << endl;
return ss.str();
}



string Cat::about() const {
stringstream ss;
ss << Animal::about() << Mammal::about() << "\t" << "favorite_food_Cat: " << favorite_food_Cat << endl;
return ss.str();
}


string Arachnids::about() const {
stringstream ss;
ss << Animal::about() << "\t" << " type_of_birth: " << type_of_birth << endl;
return ss.str();
}

string Black_Vdova::about() const {
stringstream ss;
ss << Arachnids::about() << "\t" << " geolacation: " << geolacation << endl;
return ss.str();
}

string tarantula::about() const {
stringstream ss;
ss << Arachnids::about() << " max_weight: " << max_weight << endl;
return ss.str();
}



inline ostream& operator <<(ostream& os, const Animal& animal) {
return os << animal.about();
}


int main() {
return 0;
}
Black_Vdova tt;
tt.count_limbs = 65;
tt.geolacation = "49494946.78668887";
tt.setType_of_birth("egg");
cout << "Black_Vdova" << endl;
cout << tt.about();

Tiger sherhan;
sherhan.color_tiger = "orange-white";
sherhan.fine_for_murder = 100000;
cout << "Tiger" << endl;
cout << sherhan.about();


tarantula vik;
vik.speed = 1010;
vik.max_weight = 4;
vik.setType_of_birth("egg");
cout << "tarantula" << endl;
cout << vik.about() << endl;

Cat Arsik;
Arsik.setVibrissaLength(5);
Arsik.favorite_food_Cat = "wiski";
cout << "Cat" << endl;
cout << Arsik.about();




}
108 changes: 103 additions & 5 deletions animals/animal.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,116 @@
#pragma once

#include <iostream>
#include <string>
#include <sstream>
using namespace std;




//���� ������������ ����



class Animal {
string herbivore_or_carnivorous; // ����������-true ����������-false
protected:
Animal() { herbivore_or_carnivorous = "hserbivore"; }

public:
float weight; // kg
virtual string about() const;
};

class Mammal : public Animal {


class Mammal : public Animal { // �������������
public:
float pregnancyDuration; // days
void setWool_cover(bool value) { wool_cover = value; }
bool getWool_cover() { return wool_cover; }
bool milk_glands;

virtual string about() const;
private:
bool wool_cover;

protected:
Mammal() { milk_glands = true; }

};

class Tiger : public Mammal {
public:
string color_tiger; // ����
int fine_for_murder; // ����� �� ��������
void setDay_of_tgers(string value) { day_of_tigers = value; }
string getDay_of_tgers() { return day_of_tigers; }

virtual string about() const;


private:
string day_of_tigers;

};

class Cat : public Mammal {
public:
float vibrissaLength; // meters
string favorite_food_Cat;
void setVibrissaLength(float value) { vibrissaLength = value; }
float getVibrissaLength() { return vibrissaLength; }
int sok;
virtual string about() const;
private:
float vibrissaLength;

protected:
//Cat() { favorite_food_Cat = "wiski"; }
};

class Arachnids : public Animal { // ������
public:
float mean_age;// years
int count_limbs; // ����� �����������

void setType_of_birth(string value) { type_of_birth = value; }
string getType_of_birth() { return type_of_birth; }

virtual string about() const;
private:
string type_of_birth;// ��� ��������

protected:
Arachnids() { count_limbs = 8; }

};

class Black_Vdova : public Arachnids {
public:
string geolacation;
int favorite_temperatur;
void setThe_presence_of_poison(bool value) { the_presence_of_poison = value; }

bool getThe_presence_of_poison() { return the_presence_of_poison; }

virtual string about() const;

private:
bool the_presence_of_poison; // ������� ���

};

class tarantula : public Arachnids {
public:
float max_weight;
float speed;
void setThe_presence_of_wool(bool value) { the_presence_of_wool = value; }
bool setThe_presence_of_wool() { return the_presence_of_wool; }

virtual string about() const;

private:
bool the_presence_of_wool; // ������� ����������� �������

protected:


};
5 changes: 3 additions & 2 deletions classwork/vehicle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ string Automobile::about() const {
int main()
{
Automobile a1(5.3f);

cout << "Automobile 1: " << a1 << endl;

return 0;

}
13 changes: 13 additions & 0 deletions local_RepC++.wsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32126.317
MinimumVisualStudioVersion = 10.0.40219.1
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2487EDB4-3AF0-4F59-9F34-57D999692252}
EndGlobalSection
EndGlobal
65 changes: 35 additions & 30 deletions vectors/array.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,8 @@
#include <iostream>
#include "array.h"
using namespace std;

class Vector3d {
float data[3];
public:
Vector3d() { data[2] = data[1] = data[0] = 0; }
Vector3d(float value) { data[2] = data[1] = data[0] = value; }
float operator[] (int index) const { cerr << "const" << index << endl; return data[index]; }
float& operator[] (int index) { cerr << "non-const" << index << endl; return data[index]; }
};

template<size_t Dimensions>
class Vector {
float data[Dimensions];
public:
Vector(float value = 0) { for (size_t i = 0; i < Dimensions; i++) data[i] = value; }
float operator[] (size_t index) const { return data[index]; }
float& operator[] (size_t index) { return data[index]; }
};

// Написать шаблонные функции:
// 1. operator + (реализация внутри класса)
// 2. operator * (вектор на скаляр и скаляр на вектор; реализация вне класса)
// 3. Нахождение среднего для двух векторов (реализация вне класса)

ostream& operator <<(ostream& os, const Vector3d& v) {
return os << "{ " << v[0] << ", " << v[1] << ", " << v[2] << " }";
}

template<size_t Dimensions>
ostream& operator <<(ostream& os, const Vector<Dimensions>& v) {
Expand All @@ -36,10 +12,39 @@ ostream& operator <<(ostream& os, const Vector<Dimensions>& v) {
return os << " }";
}

ostream& operator <<(ostream& os, const Vector3d& v) {
return os << "{ " << v[0] << ", " << v[1] << ", " << v[2] << " }";
}




int main() {
Vector<12> v1;
v1[1] = v1[2] = 54;
Vector<12> v2 = v1;
cout << v2 << endl;
return 0;
Vector3d v1(1, 2, 3), v2(1), v3 = v1 + v2, v4 = v2 * 6, v5 = v1 - v2, v6 = -v1;

Vector3d srVect = v1 & v2;

cout << v3 << endl;
cout << v4 << endl;
cout << v5 << endl;
cout << v6 << endl;
cout << srVect;
bool a = test_vector3d(v3, v2, v5, '-');
cout << a<<endl;
bool b = test_vector3d(v2, 6, v4, '*');
cout << b<<endl;
bool c = test_vector3d(v1, v6, '-');
cout << c << endl;











}

Loading