-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathInputData.cpp
More file actions
88 lines (76 loc) · 2.24 KB
/
InputData.cpp
File metadata and controls
88 lines (76 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <iostream>
#include <fstream>
#include <string>
#include "InputData.h"
#include "Out.h"
void InputData::get_data_from_user()
{
if (!_out.stdin_isatty)
_out.can_output = false;
setNumOfSourceVars();
alloc_memory(numOfSourceVars);
setFactorsOfTargetFunctionVars();
setWayOfTargetFunction();
setFactorsOfSystemVars();
setFreeMembersOfSystem();
if (!_out.stdin_isatty)
_out.can_output = true;
}
void InputData::setFreeMembersOfSystem()
{
for (int i = 0; i < numOfSourceVars; ++i)
{
_out << std::cout << "Введите значение свободного члена для " << i + 1 << "-го неравенства: ";
std::cin >> freeMembersOfSystem[i];
}
_out << std::cout << "\n";
}
void InputData::setFactorsOfSystemVars()
{
int i, j;
for (i = 0; i < numOfSourceVars; ++i)
{
for (j = 0; j < numOfSourceVars; ++j)
{
_out << std::cout << "Введите коэффициент при X" << j + 1 << " для " << i + 1 << "-го неравенства: ";
std::cin >> (*factorsOfSystemVars)[i][j];
}
_out << std::cout << "\n";
}
}
void InputData::setFactorsOfTargetFunctionVars()
{
_out << std::cout << "\n";
for (int i = 0; i < numOfSourceVars; ++i)
{
_out << std::cout << "Введите коэффициент целевой функции при X" << i + 1 << ": ";
std::cin >> factorsOfTargetFunctionVars[i];
}
_out << std::cout << "\n";
}
void InputData::setNumOfSourceVars()
{
for (numOfSourceVars = 0; numOfSourceVars <= 0;) {
_out << std::cout << "Введите количество основных переменных задачи (> 0): ";
std::cin >> numOfSourceVars;
}
}
void InputData::setWayOfTargetFunction()
{
std::string MaxOrMin;
while (MaxOrMin.compare("max") != 0 && MaxOrMin.compare("min")) {
_out << std::cout << "Введите направление целевой функции (max, min): ";
std::cin >> MaxOrMin;
if (MaxOrMin.compare("max") == 0)
wayOfTargetFunction = true;
else if (MaxOrMin.compare("min") == 0)
wayOfTargetFunction = false;
}
_out << std::cout << "\n";
}
void InputData::alloc_memory(unsigned int vars)
{
freeMembersOfSystem = new double[vars];
factorsOfSystemVars = new matrix(vars, vars);
factorsOfTargetFunctionVars = new double[vars];
}