Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Sem4 / Sem4 Шкурко МП-22а

.docx
Скачиваний:
0
Добавлен:
10.04.2019
Размер:
19.95 Кб
Скачать

#pragma once

class Base

{

double ost_h; //свободное пространство документа (объекты располагаются друг под другом)

protected:

double l; //ширина и высота документа

double h;

public:

Base();

void SetLH(double, double);

double GetL();

double GetH();

double GetOstH();

void ChangeOstH(double); //вычисление свободного пространства в документе

~Base();

};

#include "stdafx.h"

#include "Base.h"

#include <iostream>

using namespace std;

Base::Base()

{

l = 0;

h = 0;

ost_h = 0;

}

void Base::SetLH(double _l, double _h)

{

l = _l;

h = _h;

ost_h = h;

}

double Base::GetL()

{

return l;

}

double Base::GetH()

{

return h;

}

double Base::GetOstH()

{

return ost_h;

}

void Base::ChangeOstH(double H)

{

ost_h = ost_h - H;

cout << "Places left: " << ost_h << endl;

}

Base::~Base()

{

}

#pragma once

#include "Base.h"

class Text :

public virtual Base

{

int number_sym; //кол-во символов в тексте

double h_sym; //высота символа

double line_space; //межстрочный интервал

double h_text; //высота текста

public:

Text();

int Set(int, double, double, Base);

int TextHeight(Base);

double GetH_Text();

~Text();

};

#include "stdafx.h"

#include "Text.h"

#include <cmath>

#include <iostream>

using namespace std;

Text::Text()

{

number_sym = 0;

h_sym = 0;

line_space = 0;

h_text = 0;

}

int Text::Set(int n, double h, double l, Base b)

{

number_sym = n;

h_sym = h;

line_space = l;

return TextHeight(b);

}

int Text::TextHeight(Base b)

{

int n_str;

n_str = ceil(number_sym*h_sym / b.GetL()); //кол-во строк

h_text = n_str * h_sym + (n_str - 1) * line_space; //высота текста

cout << "Text height: " << h_text << endl;

if (b.GetOstH() >= h_text)

{

cout << "This text can be placed in this document\n";

return 0;

}

else

{

cout << "This text can not be placed in this document\n";

return -1;

}

}

double Text::GetH_Text()

{

return h_text;

}

Text::~Text()

{

}

#pragma once

#include "Base.h"

class Picture :

public virtual Base

{

public:

Picture();

int Set(double, double, Base);

~Picture();

};

#include "stdafx.h"

#include "Picture.h"

#include <iostream>

using namespace std;

Picture::Picture()

{

}

int Picture::Set(double _l, double _h, Base b)

{

l = _l;

h = _h;

if ((b.GetOstH() >= h) && (b.GetL() >= l))

{

cout << "This image can be placed in this document\n";

return 0;

}

else

{

cout << "This image can not be placed in this document\n";

return -1;

}

}

Picture::~Picture()

{

}

#pragma once

#include "Base.h"

class Formula :

public virtual Base

{

public:

Formula();

int Set(double, double, Base);

~Formula();

};

#include "stdafx.h"

#include "Formula.h"

#include <iostream>

using namespace std;

Formula::Formula()

{

}

int Formula::Set(double _l, double _h, Base b)

{

l = _l;

h = _h;

if ((b.GetOstH() >= h)&&(b.GetL() >= l))

{

cout << "This formula can be placed in this document\n";

return 0;

}

else

{

cout << "This formula can not be placed in this document\n";

return -1;

}

}

Formula::~Formula()

{

}

// Sem4.cpp: определяет точку входа для консольного приложения.

//

#include "stdafx.h"

#include "Base.h"

#include "Text.h"

#include "Picture.h"

#include "Formula.h"

#include <cmath>

#include <iostream>

using namespace std;

template <typename type>

void Valid(type& a) //проверка ввода

{

while (true)

{

cin.clear(); //восстанавливает поток

cin.sync(); // очистка буфера

cin >> a;

if (cin.good())

{

cin.ignore(10, '\n'); //игнорирование "лишних" символов

break;

}

cin.clear();

cout << "Enter the correct data" << endl;

cin.ignore(10, '\n');

}

}

int main()

{

Base B;

double w, h;

cout << "Enter the document width: ";

Valid(w);

cout << "Enter the document height: ";

Valid(h);

B.SetLH(w, h);

char a = 'y';

while (a == 'y')

{

char choose;

cout << "What you want to create?\n"

<< "1. Text\n"

<< "2. Picture\n"

<< "3. Formula\n";

cin >> choose;

switch (choose)

{

case '1':

{

Text T;

int n;

double h, l_space;

int povt = -1;

while (povt == -1)

{

cout << "\nEnter the number of the symbols: ";

Valid(n);

cout << "Enter the height of the symbols: ";

Valid(h);

cout << "Enter the line spacing: ";

Valid(l_space);

povt = T.Set(n, h, l_space, B);

}

double h_text = T.GetH_Text();

B.ChangeOstH(h_text); //вычисление оставшегося места

}

break;

case '2':

{

Picture P;

double h, l;

int povt = -1;

while (povt == -1)

{

cout << "\nEnter the image height: ";

Valid(h);

cout << "Enter the image width: ";

Valid(l);

povt = P.Set(l, h, B);

}

B.ChangeOstH(h);

}

break;

case '3':

{

Formula F;

double h, l;

int povt = -1;

while (povt == -1)

{

cout << "\nEnter the image height: ";

Valid(h);

cout << "Enter the image width: ";

Valid(l);

povt = F.Set(l, h, B);

}

B.ChangeOstH(h);

}

break;

default:

break;

}

cout << "Do you want to continue? (y/n)";

cin >> a;

}

return 0;

}

Соседние файлы в папке Sem4