Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <cmath>
- #include <cstdlib>
- #include <string>
- using namespace std;
- class NegativeException {
- string exc;
- friend ostream& operator<<(ostream& os, const NegativeException& vi) {
- os << "исключение " << vi.exc;
- return os;
- }
- public:
- NegativeException() {
- this->exc = "NegativeException";
- }
- };
- class InvalidAdress {
- string exc;
- friend ostream& operator<<(ostream& os, const InvalidAdress& vi) {
- os << "исключение " << vi.exc;
- return os;
- }
- public:
- InvalidAdress() {
- this->exc = "InvalidAdress";
- }
- };
- class Human {
- protected:
- string name;
- double ves;
- double rost;
- int vozrast;
- public:
- Human(string a = "Иван", double b = 84, double r = 162, int v = 21) {
- name = a;
- ves = b;
- rost = r;
- vozrast = v;
- }
- Human(const Human &m) {
- name = m.name;
- vozrast = m.vozrast;
- ves = m.ves;
- rost = m.rost;
- }
- Human& operator=(Human m) {
- name = m.name;
- vozrast = m.vozrast;
- ves = m.ves;
- rost = m.rost;
- }
- void setname(string c) {
- name = c;
- }
- string getname() {
- return name;
- }
- void setves(double c) {
- ves = c;
- }
- double getves() {
- return ves;
- }
- void setrost(double c) {
- rost = c;
- }
- double getrost() {
- return rost;
- }
- void setvozrast(int c) {
- vozrast = c;
- }
- int getvozrast() {
- return vozrast;
- }
- friend ostream& operator<<(ostream& vivod, Human& H) {
- vivod << "name " << H.name << endl << "vozrast " << H.vozrast << endl << "rost " << H.rost << endl << "ves " << H.ves << endl;
- return vivod;
- }
- friend istream& operator>>(istream& vvod, Human& H) {
- cout << "Enter name " << endl;
- vvod >> H.name;
- vvod.ignore();
- cout << "Enter vozrast " << endl;
- vvod >> H.vozrast;
- vvod.ignore();
- cout << "Enter rost " << endl;
- vvod >> H.rost;
- vvod.ignore();
- cout << "Enter ves " << endl;
- vvod >> H.ves;
- cout << endl;
- return vvod;
- }
- double IndMas() {
- double k = ves / pow(rost, 2);
- return k;
- }
- };
- class Book {
- protected:
- string *pred;
- int size;
- int *mark;
- public:
- Book(int size = 2) {//Конструктор. size задаёт количество сдаваемых предметов. По умолчанию - 2
- this->size = size;
- pred = new string [size];
- mark = new int [size];
- for (int i = 0; i < size; i++) {
- char a[10];
- //cout<<"1";
- itoa(i, a, 10);
- //cout<<"2";
- string s = "Предмет";
- //cout<<"3";
- s += a;
- // cout<<"4";
- pred[i] = s;
- //cout<<"5";
- //cout<<endl;
- }
- for (int i = 0; i < size; i++) {
- mark[i] = rand() % (5 - 2 + 1) + 2;
- }
- }
- Book(int *mark, string *pred, int size = 2) {
- if (size <= 0)throw NegativeException();
- this->pred = new string [size];
- this->mark = new int [size];
- for (int i = 0; i < size; i++) {
- this->pred[i] = pred[i];
- }
- for (int i = 0; i < size; i++) {
- this->mark[i] = mark[i];
- }
- this->size = size;
- }
- /**
- * <b>Переопределённый оператор =</b><br>
- * @param b присваеваемый Book
- * @return изменённый объект
- */
- Book& operator=(Book b) {
- //if (*this == b)return *this;
- if (b.size != this->size) {
- delete []this->mark;
- delete []this->pred;
- this->size = b.size;
- this->pred = new string [b.size];
- this->mark = new int [b.size];
- }
- this->copy(b.mark, b.pred);
- return *this;
- }
- /**
- * <b>Перенос массива</b>
- * Техническая функция. ВАЖНО: Размер this.v должен совпадать с размером переносимого массива
- * @param v переносимый массив
- */
- void copy(int *v, string *v1) {
- for (int i = 0; i<this->size; i++) {
- this->mark[i] = v[i];
- }
- for (int i = 0; i<this->size; i++) {
- this->pred[i] = v1[i];
- }
- }
- Book(const Book& b) {
- pred = new string[b.size];
- mark = new int[b.size];
- size = b.size;
- for (int i = 0; i < size; i++) {
- this->pred[i] = b.pred[i];
- }
- for (int i = 0; i < size; i++) {
- this->mark[i] = b.mark[i];
- }
- }
- ~Book() {
- delete []pred;
- delete mark;
- }
- void setPred(string s, int i = 0) {
- if (i<this->size) {
- this->pred[i] = s;
- } else cout << "Error";
- }
- void setPred(int m, int i = 0) {
- if (i<this->size && m >= 1 && m <= 5) {
- this->mark[i] = m;
- } else cout << "Error";
- }
- int getMark(int i = 0) {
- if (i<this->size) {
- return this->mark[i];
- } else cout << "Error";
- //return;
- }
- string getPredm(int i = 0) {
- if (i<this->size) {
- return this->pred[i];
- } else throw InvalidAdress();
- //return;
- }
- string getEntry(int i = 0) {
- if (i<this->size) {
- string s = "";
- s += this->pred[i];
- s += " - ";
- char a[2];
- itoa(this->mark[i], a, 10);
- s += a;
- return s;
- } else throw InvalidAdress();
- //return;
- }
- double mid() {
- double s = 0;
- for (int i = 0; i<this->size; i++) {
- s += this->mark[i];
- }
- s /= this->size;
- return s;
- }
- };
- class Student {
- protected:
- int num;
- Human hum;
- Book b;
- public:
- Student(int num = 1) {
- hum = Human();
- b = Book();
- this->num = num;
- }
- Student(Human hum, Book b, int num = 1) {
- this->hum = hum;
- this->b = b;
- this->num = num;
- }
- void setNum(int num = 1) {
- this->num = num;
- }
- int getNum() {
- return this->num;
- }
- string getName() {
- return this->hum.getname();
- }
- double getMid() {
- return this->b.mid();
- }
- string stip() {
- if ((int) this->b.mid() <= 3)return "0";
- if (this->b.mid() == 4)return "+";
- if (this->b.mid() > 4 && this->b.mid() < 5)return "++";
- else return "+++";
- }
- bool grad() {
- if ((int) b.mid() > 3)return true;
- return false;
- }
- };
- int main() {
- setlocale(0, "");
- srand(time(0));
- Human I = Human();
- cout<<I.getname()<<" рост:"<<I.getrost()<<" вес:"<<I.getves()<<" возраст:"<<I.getvozrast()<<endl;
- //cout << I.getname() << endl;
- Book b = Book(5);
- cout << b.getEntry(0) << endl
- << b.getEntry(1) << endl
- << b.getEntry(2) << endl << b.getEntry(3) << endl << b.getEntry(4) << endl;
- Student s = Student(I, b);
- cout << endl <<"Cтудент "<< s.getName() << " средний балл=" << b.mid() << " -> " << s.stip() << endl;
- if(s.grad())cout<<endl<<"Переведён"<<endl;
- else cout<<endl<<"Отчислен А.Г. Тисовским. Лично."<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment