-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLAB #2 RES. DE TRIANGULOS
277 lines (275 loc) · 9.96 KB
/
LAB #2 RES. DE TRIANGULOS
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
#include <iostream>
#include <stdio.h>
#include <windows.h>
#include <conio.h>
#include <math.h>
#include <cmath>
#include <stdlib.h>
using namespace std;
int main(){
int k;
float Area, S;
int aux;
char var,v1;
const double pi = std::acos(-1);
do{
cout<<"\n\t****POR MEDIO DE TEORIA DE SENOS, COSENOS Y TRANGENTES**\n";
cout<<"\n\t\t\t*** CALCULADORA DE TRIANGULOS ***"<<endl;
cout<<"\t\t\t\t gamma * \n";
cout<<"\t\t\t\t *|* \n";
cout<<"\t\t\t\t **|** \n";
cout<<"\t\t\t\t ***|*** \n";
cout<<"\t\t\t\t A ****|**** B \n";
cout<<"\t\t\t\t *****|***** \n";
cout<<"\t\t\t\t ******|****** \n";
cout<<"\t\t\t\t *******|******* \n";
cout<<"\t\t\t\tbeta ********|******** alpha \n";
cout<<"\t\t\t\t C \n";
cout<<"\n ESCOJA UNA OPCIÓN.\n"<<endl<<endl;
cout<<"\t\t 1. TRES LADOS."<<endl;
cout<<"\t\t 2. TRES ANGULOS."<<endl;
cout<<"\t\t 3. DOS LADOS Y EL ANGULO ENTRE ELLOS."<<endl;
cout<<"\t\t 4. DOS LADOS Y UN ANGULO OPUESTO DE LOS MISMOS"<<endl;
cout<<"\t\t 5. UN LADO, SU ANGULO OPUESTO Y UNO DE SUS ADYACENTES."<<endl;
cout<<"\t\t 6. UN LADO Y SUS DOS ANGULOS ADYACENTES."<<endl;
cout<<"\t\t 7. SALIR"<<endl;
cout<<"\n PRESIONE EL NUMERO DE LA OPCION A REALIZAR: ";
cin>>k;
system("cls");
switch(k){
case 1:
float a,b,c,L[3],L1[3],alpha,beta,gamma;
double A,B,C,AF,BF,CF;
do{
cout<<"\n\tDIGITE LOS VALORES DE LOS ANGULOS: "<<endl;
cout<<"\t\tA= ";cin>>L[0];
cout<<"\t\tB= ";cin>>L[1];
cout<<"\t\tC= ";cin>>L[2];
if(L[0]>0,L[1]>0,L[2]>0){
S=(L[0]+L[1]+L[2])/2;
Area=sqrt(S*(S-L[0])*(S-L[1])*(S-L[2]));
for(int i=0;i<3;i++){
L1[i]=L[i];
}
a=L1[0];
b=L1[1];
c=L1[2];
for(int i=0;i<3;++i){
for(int j=0;j<3;++j){
if(L[j]>L[j+1]){
aux=L[j];
L[j]=L[j+1];
L[j+1]=aux;
}
}
}
if(L[3]<L[2]+L[1]){
cout<<"\n LOS ANGULOS SON: "<<endl<<endl;
A=(pow(b,2)+pow(c,2)-pow(a,2))/(2*b*c);
alpha=alpha+acos(A);
cout<<"\tALPHA= "<<(alpha*180)/pi<<endl;
B=(pow(a,2)+pow(c,2)-pow(b,2))/(2*a*c);
beta=beta+acos(B);
cout<<"\tBETA= "<<(beta*180)/pi<<endl;
}
C=(pow(b,2)+pow(a,2)-pow(c,2))/(2*b*a);
gamma=gamma+acos(C);
cout<<"\tGAMMA= "<<(gamma*180)/pi<<endl;
cout<<"\n EL AREA ES: "<<Area<<" [u^2]"<<endl;
cout<<"\n\t\tQUIERE REGRESAR AL MENU?"<<endl;//PREGUNTA
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>var;
system("cls");
break;
}else{
cout<<"\n\tLA SUMA DE LOS LADOS DEBE SER MAYOR A LA LONGITUD DEL TERCER LADO"<<endl;
cout<<"\tREVISE SUS DATOS ."<<endl<<endl;
cout<<"\t\t¿DESEA INTENTAR CON NUEVOS DATOS?"<<endl; //PREGUNTA
cout<<"\tIngrese Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>v1;
system("cls");
}
}while(v1=='s');
break;
case 2:
cout<<"\n\tDEBE INGRESAR EL DATO DE UN LADO PARA PODER REALIZAR EL CALCULO"<<endl<<endl;
cout<<"\t\t¿QUIERE REGRESAR AL MENU?"<<endl;//PREGUNTA
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>var;
system("cls");
break;
case 3:
float a4,b4,c4,alpha4,beta4,gamma4;
double A4,B4,C4,AF4,BF4,CF4;
do{
cout<<"\n\tDIGITE LOS VALORES DE: "<<endl;
cout<<"\t\tA= "; cin>>a4;
cout<<"\t\tB= "; cin>>b4;
cout<<"\t\tGAMMA= "; cin>>gamma4;
if(a4>0,b4>0,gamma4>0){
Area=(a4*b4*std::sin(pi*gamma4/180)/2);c4=sqrt(pow(a4,2)+pow(b4,2)-(2*a4*b4*cos((gamma4*pi)/180)));
cout<<"\n\tEL OTRO LADO Y LOS OTROS ANGULOS SON: "<<endl;
cout<<"\t\tC= "<<c4<<"[u]"<<endl;
A4=sin((gamma4*pi)/180);
AF4=(asin((a4*A4)/c4)*180)/pi;
alpha4=alpha4+AF4;
cout<<"\t\tALPHA= "<<alpha4<<"[grados]"<<endl;
beta4=beta4+180-alpha4-gamma4;
cout<<"\t\tBETA= "<<beta4<<"[grados]"<<endl<<endl;
cout<<"\n EL AREA ES: "<<Area<<" [u^2]"<<endl;
cout<<"\n\t\tQUIERE REGRESAR AL MENU?"<<endl;//PREGUNTA
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>var;
system("cls");
break;
}else{
cout<<"\tLOS VALORES INGRESADOS DEBEN SER MAYOR A 0, que"<<endl;
cout<<"\t el angulo sea menor a 180 grados y sus datos tengan coherencia "<<endl;
cout<<"\t con su triangulo."<<endl<<endl;
cout<<"\t\t¿Desea ingresar nuevos datos?"<<endl;
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>v1;
system("cls");
}
}while(v1=='s');
break;
case 4:
float a2,b2,c2,alpha2,beta2,gamma2;
long double m2,n2,D2;
double x2;
double A2,B2,C2,AF2,BF2,CF2;
do{
cout<<"\n\tIngrese los valores de: "<<endl;
cout<<"\t\tA= "; cin>>a2;
cout<<"\t\tB= "; cin>>b2;
cout<<"\t\tALPHA= "; cin>>alpha2;
if(a2>0,b2>0,alpha2>0){
m2=-2*b2*cos((alpha2*pi)/180);
n2=pow(b2,2)-pow(a2,2);
D2=pow(m2,2)-4*n2;
if(D2>=0){
x2=(-m2+sqrt(D2))/(2);
c2=c2+x2;
cout<<"\n\tEl lado y los otros dos angulos del triangulo son: "<<endl;
cout<<"\t\tC= "<<c2<<"[u]"<<endl;
B2=sin((alpha2*pi)/180);
BF2=(asin((b2*B2)/a2)*180)/pi;
beta2=beta2+BF2;
cout<<"\t\tBETA= "<<beta2<<"[grados]"<<endl;
gamma2=gamma2+180-alpha2-beta2;
cout<<"\t\tGAMMA= "<<gamma2<<"[grados]"<<endl<<endl;
cout<<"\t\t¿Desea regresar al menu?"<<endl;//PREGUNTA
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>var;
system("cls");
break;
}else{
cout<<" **Lado A insuficiente para formar un triangulo*"<<endl;
cout<<"\t\t¿Desea ingresar nuevos datos?"<<endl;
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>v1;
system("cls");
}
}else{
cout<<"\tVerifique que los valores ingresados seran mayores a cero, que"<<endl;
cout<<"\t el angulo sea menor a 180 grados y sus datos tengan coherencia "<<endl;
cout<<"\t con su triangulo."<<endl<<endl;
cout<<"\t\t¿Desea ingresar nuevos datos?"<<endl;
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>v1;
system("cls");
}
}while(v1=='s');
break;
case 5:
float a3,b3,c3,alpha3,beta3,gamma3;
long double m3,n3,D3;
double x3;
double A3,B3,C3,AF3,BF3,CF3;
do{
cout<<"\n\tIngrese los valores de: "<<endl;
cout<<"\t\tA= "; cin>>a3;
cout<<"\t\tALPHA= "; cin>>alpha3;
cout<<"\t\tGAMMA= "; cin>>gamma3;
if(a3>0,alpha3>0,gamma3>0){
if(alpha3+gamma3<170){
c3=(a3*sin((gamma3*pi)/180))/sin((alpha3*pi)/180);
beta3=180-alpha3-gamma3;
b3=sqrt(pow(a3,2)+pow(c3,2)-(2*a3*c3*cos((beta3*pi)/180)));
cout<<"\n\tLos otros dos lados y el angulo del triangulo son: "<<endl;
cout<<"\t\tB= "<<b3<<"[u]"<<endl;
cout<<"\t\tC= "<<c3<<"[u]"<<endl;
cout<<"\t\tBETA= "<<beta3<<"[grados]"<<endl;
cout<<"\t\t¿Desea regresar al menu?"<<endl;
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>var;
system("cls");
break;
}else{
cout<<" Los angulos son demasiado grandes para formar un triangulo,"<<endl;
cout<<" revise sus datos y vuelva a ingresalos por favor."<<endl;
cout<<"\t\t¿Desea ingresar nuevos datos?"<<endl;
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>v1;
system("cls");
}
}else{
cout<<"\tVerifique que los valores ingresados seran mayores a cero, que"<<endl;
cout<<"\t el angulo sea menor a 180 grados y sus datos tengan coherencia "<<endl;
cout<<"\t con su triangulo."<<endl<<endl;
cout<<"\t\t¿Desea ingresar nuevos datos?"<<endl;
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>v1;system("cls");
}
}while(v1=='s');
break;
case 6:
float a5,b5,c5,alpha5,beta5,gamma5;
long double m5,n5,D5;
double x5;
double A5,B5,C5,AF5,BF5,CF5;
do{
cout<<"\n\tIngrese los valores de: "<<endl;
cout<<"\t\tA= "; cin>>a5;
cout<<"\t\tBETA= "; cin>>beta5;
cout<<"\t\tGAMMA= "; cin>>gamma5;
if(a5>0,beta5>0,gamma5>0){
Area=(a5*a5*std::sin(pi*beta5/180)*std::sin(pi*gamma5/180))/(2*std::sin(pi*(180-beta5-gamma5)/180));
if(alpha3+gamma3<170){
alpha5=180-beta5-gamma5;
c5=(a5*sin((gamma5*pi)/180))/sin((alpha5*pi)/180);
b5=sqrt(pow(a5,2)+pow(c5,2)-(2*a5*c5*cos((beta5*pi)/180)));
cout<<"\n\tLos otros dos lados y el angulo del triangulo son: "<<endl;
cout<<"\t\tB= "<<b5<<"[u]"<<endl;
cout<<"\t\tC= "<<c5<<"[u]"<<endl;
cout<<"\t\tALPHA= "<<alpha5<<"[grados]"<<endl;
cout<<"\n El Area sera: "<<Area<<" [u^2]"<<endl;
cout<<"\n\t\tDesea regresar al menu?"<<endl;
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>var;
system("cls");
break;
}else{
cout<<" Los angulos son demasiado grandes para formar un triangulo,"<<endl;
cout<<" revise sus datos y vuelva a ingresalos por favor."<<endl;
cout<<"\t\t¿Desea ingresar nuevos datos?"<<endl;
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>v1;
system("cls");
}
}else{
cout<<"\tVerifique que los valores ingresados seran mayores a cero, que"<<endl;
cout<<"\t el angulo sea menor a 180 grados y sus datos tengan coherencia "<<endl;
cout<<"\t con su triangulo."<<endl<<endl;
cout<<"\t\t¿Desea ingresar nuevos datos?"<<endl;
cout<<" Escriba Si (s) o presione otra tecla en caso contrario"<<endl;
cin>>v1;
system("cls");
}
}while(v1=='s');
break;
case 7: cout<<"\n\t\t Gracias! Hasta pronto!"<<endl; return 0;
default:break;
}
}while(var=='s',k!=6);
}