-
Notifications
You must be signed in to change notification settings - Fork 0
/
input.h
171 lines (154 loc) · 3.94 KB
/
input.h
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#pragma once
#include <iostream>
#include "var.h"
using namespace std;
void inPut() {
while(1) {
cout << "Ban lua chon: 1->max, 2->min - (1/2): ";
cin >> min_max;
if (min_max!=1 && min_max!=2){
cout << "Dau vao sai! Vui long chon lai." << endl;
}
else break;
}
while(1) {
cout << "\n***So bien x:";
cin >> x_num;
cout << "--Nhap c[1]~c[" << x_num << "]: " << endl;
for (size_t i=0; i<x_num; ++i) {
cout << "\tc" << i+1 << " = ";
double c_;
cin >> c_;
c.push_back(c_); // them gia tri vao c
}
if (min_max==1){
cout << "**Max z = ";
}
else{
cout << "**Min z = ";
}
if (c[0]==1){
cout << "x[1]";
}
else if(c[0]==-1){
cout << "-x[1]";
}
else if(c[0]!=0){
cout << " " << c[0] << "x[1]";
}
for (size_t i=1; i<x_num; ++i) {
if(c[i]==1){
cout << " + x[" << i+1 << "]";
}
else if (c[i]==-1){
cout << " - x[" << i+1 << "]";
}
else if (c[i]>0){
cout << " + " << c[i] << "x[" << i+1 << "]";
}
else if (c[i]<0){
cout << " - " << -c[i] << "x[" << i+1 << "]";
}
}
cout << "\t";
a1: cout << "\tKet qua nhap chinh xac? - (y/n): ";
char yn;
cin >> yn;
if (yn == 'y'){
break;
}
else if (yn == 'n'){
continue;
}
else {
cout << "\tDau vao loi!" << endl;
goto a1;
}
}
cout << "\n***So rang buoc: ";
cin >> st_num;
// reset kich thuoc cac vecto
eql.resize(size);
b.resize(size);
base_id.resize(size);
ar_id.resize(size);
// lua chon dau cho rang buoc
for (size_t i=0; i<st_num; ++i) {
cout << "--Rang buoc thu: " << i+1 << ":" << endl;
while (1) {
cout << "+++Chon dau: 1: ==; 2: >=, 3: <=. --- (1/2/3): ";
cin >> eql[i];
if(eql[i]!=1 && eql[i]!=2 && eql[i]!=3){
cout << "Dau vao sai! Vui long chon lai." << endl;
}
else break;
}
// nhap he so rang buoc
cout << "--Input a: " << endl;
vector<double> a_(x_num);
for (size_t j=0; j<x_num; ++j) {
cout << "\ta" << j+1 << " = ";
cin >> a_[j];
}
a.push_back(a_);
// nhap gia tri rang buoc
cout << "--Input b: " << endl;
cout << "\tb" << i+1 << " = ";
cin >> b[i];
cout << "St." << i+1 << ": ";
if (a[i][0]==1){
cout << "x[1]";
}
else if(a[i][0]==-1){
cout << "-x[1]";
}
else if(a[i][0]!=0){
cout << " " << a[i][0] << "x[1]";
}
for (size_t j=1; j<x_num; ++j) {
if(a[i][j]==1){
cout << " + x[" << j+1 << "]";
}
else if (a[i][j]==-1){
cout << " - x[" << j+1 << "]";
}
else if (a[i][j]>0){
cout << " + " << a[i][j] << "x[" << j+1 << "]";
}
else if (a[i][j]<0){
cout << " - " << -a[i][j] << "x[" << j+1 << "]";
}
}
switch (eql[i]) {
case 1:{
cout << " == " << b[i];
break;
}
case 2:{
cout << " >= " << b[i];
break;
}
case 3:{
cout << " <= " << b[i];
break;
}
}
while (1) {
cout << "\t" ;
cout << "*** Du lieu nhap chinh xac? - (y/n): ";
char yn;
cin >> yn;
if (yn == 'y'){
break;
}
else if(yn == 'n') {
--i;
a.pop_back();
break;
}
}
cout << endl;
}
c.resize(size);
a.resize(size);
}