Autor |
Beitrag |
interessierter
      
Beiträge: 75
|
Verfasst: Fr 11.05.12 18:30
Hallo liebe Forumgemeinde
Ich arbeite aktuell an einem C# Übungsprogramm (Konsolenprogramm) wo es um die Berechnung von geometrischen Formen geht. Den grössten Teil, die Trigonometrie, habe ich nun fertig abgetippt. Mein Gott war das ein riesen Ding.
Als Zeitrahmen plante ich letztes Wochenende, dazu kamm dann noch die ganze laufende Woche inkl. heute, weil ich zuerst mal lernen musste wie man Winkelmasse in C# berechnet. Hab mich wohl "leicht" verschätzt.
Ich poste hier den gesamten Code, in der Hoffnung auf Feedbacks, Kritik, Lob und Inputs zu stossen. Alles ist willkommen. Ich brauchte nur für diesen Teil 821 Codezeilen, was mir als sehr viel vorkommt. Vielleicht hat ja jemand Stichworte dazu, wie man den Code mit viel weniger Zeilen hinbekommen hätte. An dieser Stelle auch mal ein Dankeschön an alle Forummietglieder die mir immer wieder die Richtung vorgeben bei meinen Programmierschwierigkeiten.
Thema:
Trigonomische Berechnungen
Grundsatz:
Die Kongurenzsätze besagen, das ein Dreieck eindeutig konstruiert werden kann wenn mindestens eine der folgenden Kombinationen an gegebenen Massen vorliegt:
- eine Seite und zwei Winkel
- zwei Seiten und der der grösseren Seite gegenüberliegende Winkel
- zwei Seiten und der eingeschlossene Winkel
- drei Seiten
Anmerkungen:
- die Seiten werden jeweils gegen den Uhrzeigersinn definiert
- in meinem Programm ist die linke Seite jeweils Seite a, die untere Seite ist jeweils b, die rechte Seite immer c
- jede Seite hat immer den gleichen gegenüberliegenden Winkel. Seite a, Winkel Alpha. Seite b, Winkel Beta. Seite c, Winkel Gamma.
So, nun der Code:
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: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455: 456: 457: 458: 459: 460: 461: 462: 463: 464: 465: 466: 467: 468: 469: 470: 471: 472: 473: 474: 475: 476: 477: 478: 479: 480: 481: 482: 483: 484: 485: 486: 487: 488: 489: 490: 491: 492: 493: 494: 495: 496: 497: 498: 499: 500: 501: 502: 503: 504: 505: 506: 507: 508: 509: 510: 511: 512: 513: 514: 515: 516: 517: 518: 519: 520: 521: 522: 523: 524: 525: 526: 527: 528: 529: 530: 531: 532: 533: 534: 535: 536: 537: 538: 539: 540: 541: 542: 543: 544: 545: 546: 547: 548: 549: 550: 551: 552: 553: 554: 555: 556: 557: 558: 559: 560: 561: 562: 563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574: 575: 576: 577: 578: 579: 580: 581: 582: 583: 584: 585: 586: 587: 588: 589: 590: 591: 592: 593: 594: 595: 596: 597: 598: 599: 600: 601: 602: 603: 604: 605: 606: 607: 608: 609: 610: 611: 612: 613: 614: 615: 616: 617: 618: 619: 620: 621: 622: 623: 624: 625: 626: 627: 628: 629: 630: 631: 632: 633: 634: 635: 636: 637: 638: 639: 640: 641: 642: 643: 644: 645: 646: 647: 648: 649: 650: 651: 652: 653: 654: 655: 656: 657: 658: 659: 660: 661: 662: 663: 664: 665: 666: 667: 668: 669: 670: 671: 672: 673: 674: 675: 676: 677: 678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689: 690: 691: 692: 693: 694: 695: 696: 697: 698: 699: 700: 701: 702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719: 720: 721: 722: 723: 724: 725: 726: 727: 728: 729: 730: 731: 732: 733: 734: 735: 736: 737: 738: 739: 740: 741: 742: 743: 744: 745: 746: 747: 748: 749: 750: 751: 752: 753: 754: 755: 756: 757: 758: 759: 760: 761: 762: 763: 764: 765: 766: 767: 768: 769: 770: 771: 772: 773: 774: 775: 776: 777: 778: 779: 780: 781: 782: 783: 784: 785: 786: 787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798: 799: 800: 801: 802: 803: 804: 805: 806: 807: 808: 809: 810: 811: 812: 813: 814: 815: 816: 817: 818: 819: 820: 821:
| using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Formen_berechnen { class Program { static float askForFloat(string message) { while (true) { Console.WriteLine(message); string Eingabe = Console.ReadLine(); float value; if (float.TryParse(Eingabe, out value)) { return value; } } } static void Main(string[] args) { float Form = askForFloat("Welche Form willst du berechnen? Waehle:\n1 fuer Dreieck\n2 fuer Rechteck\n3 fuer Kreis");
if (Form == 1) { float Variante1 = askForFloat("Ein Dreieck kann eindeutig konstruiert werden wenn eine der folgenden Kombinationen an gegebenen Massen vorliegt. Wahele:\n1 fuer: eine Seite und 2 Winkel\n2 fuer: zwei Seiten und der der groesseren Seite gegenueberliegende Winkel\n3 fuer: zwei Seiten und der eingeschlossene Winkel\n4 fuer: drei Seiten");
if (Variante1 == 1) { float bekannteGroessen = askForFloat("Welche Seite und welche Winkel sind bekannt? Waehle:\n1 fuer: Seite a, Winkel Beta und Gamma\n2 fuer: Seite a, Winkel Alpha und Gamma\n3 fuer: Seite a, Winkel Alpha und Beta\n4 fuer: Seite b, Winkel Beta und Gamma\n5 fuer: Seite b, Winkel Alpha und Gamma\n6 fuer: Seite b, Winkel Alpha und Beta\n7 fuer: Seite c, Winkel Beta und Gamma\n8 fuer: Seite c, Winkel Alpha und Gamma\n9 fuer: Seite c, Winkel Alpha und Beta");
if (bekannteGroessen == 1) { Console.WriteLine("Welches Mass hat Seite a?"); string x = Console.ReadLine(); float SeiteA = float.Parse(x);
Console.WriteLine("Welchen Wert hat Winkel Beta?"); string y = Console.ReadLine(); double WinkelBeta = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Gamma?"); string z = Console.ReadLine(); double WinkelGamma = double.Parse(z);
double WinkelAlpha = 180 - WinkelBeta - WinkelGamma; double Alpha = WinkelAlpha / 180 * Math.PI; double Beta = WinkelBeta / 180 * Math.PI; double Gamma = WinkelGamma / 180 * Math.PI; double SeiteB = SeiteA * Math.Sin(Beta) / Math.Sin(Alpha); double SeiteC = SeiteA * Math.Sin(Gamma) / Math.Sin(Alpha);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); SeiteB = Math.Round(SeiteB, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 2) { Console.WriteLine("Welches Mass hat Seite a?"); string x = Console.ReadLine(); float SeiteA = float.Parse(x);
Console.WriteLine("Welchen Wert hat Winkel Alpha?"); string y = Console.ReadLine(); double WinkelAlpha = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Gamma?"); string z = Console.ReadLine(); double WinkelGamma = double.Parse(z);
double WinkelBeta = 180 - WinkelAlpha - WinkelGamma; double Alpha = WinkelAlpha / 180 * Math.PI; double Beta = WinkelBeta / 180 * Math.PI; double Gamma = WinkelGamma / 180 * Math.PI; double SeiteB = SeiteA * Math.Sin(Beta) / Math.Sin(Alpha); double SeiteC = SeiteA * Math.Sin(Gamma) / Math.Sin(Alpha);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); SeiteB = Math.Round(SeiteB, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 3) { Console.WriteLine("Welches Mass hat Seite a?"); string x = Console.ReadLine(); float SeiteA = float.Parse(x);
Console.WriteLine("Welchen Wert hat Winkel Alpha?"); string y = Console.ReadLine(); double WinkelAlpha = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Beta?"); string z = Console.ReadLine(); double WinkelBeta = double.Parse(z);
double WinkelGamma = 180 - WinkelAlpha - WinkelBeta; double Alpha = WinkelAlpha / 180 * Math.PI; double Beta = WinkelBeta / 180 * Math.PI; double Gamma = WinkelGamma / 180 * Math.PI; double SeiteB = SeiteA * Math.Sin(Beta) / Math.Sin(Alpha); double SeiteC = SeiteA * Math.Sin(Gamma) / Math.Sin(Alpha);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); SeiteB = Math.Round(SeiteB, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 4) { Console.WriteLine("Welches Mass hat Seite b?"); string x = Console.ReadLine(); float SeiteB = float.Parse(x);
Console.WriteLine("Welchen Wert hat Winkel Beta?"); string y = Console.ReadLine(); double WinkelBeta = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Gamma?"); string z = Console.ReadLine(); double WinkelGamma = double.Parse(z);
double WinkelAlpha = 180 - WinkelBeta - WinkelGamma; double Alpha = WinkelAlpha / 180 * Math.PI; double Beta = WinkelBeta / 180 * Math.PI; double Gamma = WinkelGamma / 180 * Math.PI; double SeiteA = SeiteB * Math.Sin(Alpha) / Math.Sin(Beta); double SeiteC = SeiteB * Math.Sin(Gamma) / Math.Sin(Beta);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); SeiteA = Math.Round(SeiteA, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 5) { Console.WriteLine("Welches Mass hat Seite b?"); string x = Console.ReadLine(); float SeiteB = float.Parse(x);
Console.WriteLine("Welchen Wert hat Winkel Alpha?"); string y = Console.ReadLine(); double WinkelAlpha = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Gamma?"); string z = Console.ReadLine(); double WinkelGamma = double.Parse(z);
double WinkelBeta = 180 - WinkelAlpha - WinkelGamma; double Alpha = WinkelAlpha / 180 * Math.PI; double Beta = WinkelBeta / 180 * Math.PI; double Gamma = WinkelGamma / 180 * Math.PI; double SeiteA = SeiteB * Math.Sin(Alpha) / Math.Sin(Beta); double SeiteC = SeiteB * Math.Sin(Gamma) / Math.Sin(Beta);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); SeiteA = Math.Round(SeiteA, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 6) { Console.WriteLine("Welches Mass hat Seite b?"); string x = Console.ReadLine(); float SeiteB = float.Parse(x);
Console.WriteLine("Welchen Wert hat Winkel Alpha?"); string y = Console.ReadLine(); double WinkelAlpha = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Beta?"); string z = Console.ReadLine(); double WinkelBeta = double.Parse(z);
double WinkelGamma = 180 - WinkelAlpha - WinkelBeta; double Alpha = WinkelAlpha / 180 * Math.PI; double Beta = WinkelBeta / 180 * Math.PI; double Gamma = WinkelGamma / 180 * Math.PI; double SeiteA = SeiteB * Math.Sin(Alpha) / Math.Sin(Beta); double SeiteC = SeiteB * Math.Sin(Gamma) / Math.Sin(Beta);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); SeiteA = Math.Round(SeiteA, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 7) { Console.WriteLine("Welches Mass hat Seite c?"); string x = Console.ReadLine(); float SeiteC = float.Parse(x);
Console.WriteLine("Welchen Wert hat Winkel Beta?"); string y = Console.ReadLine(); double WinkelBeta = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Gamma?"); string z = Console.ReadLine(); double WinkelGamma = double.Parse(z);
double WinkelAlpha = 180 - WinkelBeta - WinkelGamma; double Alpha = WinkelAlpha / 180 * Math.PI; double Beta = WinkelBeta / 180 * Math.PI; double Gamma = WinkelGamma / 180 * Math.PI; double SeiteA = SeiteC * Math.Sin(Alpha) / Math.Sin(Gamma); double SeiteB = SeiteC * Math.Sin(Beta) / Math.Sin(Gamma);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); SeiteA = Math.Round(SeiteA, 2); SeiteB = Math.Round(SeiteB, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 8) { Console.WriteLine("Welches Mass hat Seite c?"); string x = Console.ReadLine(); float SeiteC = float.Parse(x);
Console.WriteLine("Welchen Wert hat Winkel Alpha?"); string y = Console.ReadLine(); double WinkelAlpha = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Gamma?"); string z = Console.ReadLine(); double WinkelGamma = double.Parse(z);
double WinkelBeta = 180 - WinkelAlpha - WinkelGamma; double Alpha = WinkelAlpha / 180 * Math.PI; double Beta = WinkelBeta / 180 * Math.PI; double Gamma = WinkelGamma / 180 * Math.PI; double SeiteA = SeiteC * Math.Sin(Alpha) / Math.Sin(Gamma); double SeiteB = SeiteC * Math.Sin(Beta) / Math.Sin(Gamma);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); SeiteA = Math.Round(SeiteA, 2); SeiteB = Math.Round(SeiteB, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 9) { Console.WriteLine("Welches Mass hat Seite c?"); string x = Console.ReadLine(); float SeiteC = float.Parse(x);
Console.WriteLine("Welchen Wert hat Winkel Alpha?"); string y = Console.ReadLine(); double WinkelAlpha = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Beta?"); string z = Console.ReadLine(); double WinkelBeta = double.Parse(z);
double WinkelGamma = 180 - WinkelAlpha - WinkelBeta; double Alpha = WinkelAlpha / 180 * Math.PI; double Beta = WinkelBeta / 180 * Math.PI; double Gamma = WinkelGamma / 180 * Math.PI; double SeiteA = SeiteC * Math.Sin(Alpha) / Math.Sin(Gamma); double SeiteB = SeiteC * Math.Sin(Beta) / Math.Sin(Gamma);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); SeiteA = Math.Round(SeiteA, 2); SeiteB = Math.Round(SeiteB, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } }
if (Variante1 == 2) { float bekannteGroessen = askForFloat("Welche Seite und welche Winkel sind bekannt? Waehle:\n1 fuer: Seiten a, b und Winkel Alpha\n2 fuer: Seiten a, b und Winkel Beta\n3 fuer: Seiten a, c und Winkel Alpha\n4 fuer: Seiten a, c und Winkel Gamma\n5 fuer: Seiten b, c und winkel Beta\n6 fuer: Seiten b, c und Winkel Gamma");
if (bekannteGroessen == 1) { Console.WriteLine("Welches Mass hat Seite a? (groessere Seite)"); string x = Console.ReadLine(); float SeiteA = float.Parse(x);
Console.WriteLine("Welches Mass hat Seite b? (kleinere Seite)"); string y = Console.ReadLine(); double SeiteB = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Alpha?"); string z = Console.ReadLine(); double WinkelAlpha = double.Parse(z); double Alpha = WinkelAlpha / 180 * Math.PI; double WinkelBeta = Math.Asin(SeiteB * Math.Sin(Alpha) / SeiteA); WinkelBeta = WinkelBeta * 180 / Math.PI; double WinkelGamma = 180 - WinkelAlpha - WinkelBeta; double Gamma = WinkelGamma / 180 * Math.PI; WinkelBeta = Math.Round(WinkelBeta, 1); WinkelGamma = Math.Round(WinkelGamma, 1); double SeiteC = SeiteA * Math.Sin(Gamma) / Math.Sin(Alpha); SeiteC = Math.Round(SeiteC, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); Flaecheninhalt = Math.Round(Flaecheninhalt, 1);
Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 2) { Console.WriteLine("Welches Mass hat Seite a? (kleinere Seite)"); string x = Console.ReadLine(); float SeiteA = float.Parse(x);
Console.WriteLine("Welches Mass hat Seite b (groessere Seite)?"); string y = Console.ReadLine(); double SeiteB = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Beta?"); string z = Console.ReadLine(); double WinkelBeta = double.Parse(z); double Beta = WinkelBeta / 180 * Math.PI; double WinkelAlpha = Math.Asin(SeiteA * Math.Sin(Beta) / SeiteB); WinkelAlpha = WinkelAlpha * 180 / Math.PI; double WinkelGamma = 180 - WinkelAlpha - WinkelBeta; double Gamma = WinkelGamma / 180 * Math.PI; WinkelAlpha = Math.Round(WinkelAlpha, 1); WinkelGamma = Math.Round(WinkelGamma, 1); double SeiteC = SeiteB * Math.Sin(Gamma) / Math.Sin(Beta); SeiteC = Math.Round(SeiteC, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); Flaecheninhalt = Math.Round(Flaecheninhalt, 2);
Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 3) { Console.WriteLine("Welches Mass hat Seite a? (groessere Seite)"); string x = Console.ReadLine(); float SeiteA = float.Parse(x);
Console.WriteLine("Welches Mass hat Seite c? (kleinere Seite)"); string y = Console.ReadLine(); double SeiteC = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Alpha?"); string z = Console.ReadLine(); double WinkelAlpha = double.Parse(z); double Alpha = WinkelAlpha / 180 * Math.PI; double WinkelGamma = Math.Asin(SeiteC * Math.Sin(Alpha) / SeiteA); WinkelGamma = WinkelGamma * 180 / Math.PI; double WinkelBeta = 180 - WinkelAlpha - WinkelGamma; double Beta = WinkelBeta / 180 * Math.PI; WinkelBeta = Math.Round(WinkelBeta, 1); WinkelGamma = Math.Round(WinkelGamma, 1); double SeiteB = SeiteA * Math.Sin(Beta) / Math.Sin(Alpha); SeiteB = Math.Round(SeiteB, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); Flaecheninhalt = Math.Round(Flaecheninhalt, 1);
Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 4) { Console.WriteLine("Welches Mass hat Seite a? (kleinere Seite)"); string x = Console.ReadLine(); float SeiteA = float.Parse(x);
Console.WriteLine("Welches Mass hat Seite c? (groessere Seite)"); string y = Console.ReadLine(); double SeiteC = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Gamma?"); string z = Console.ReadLine(); double WinkelGamma = double.Parse(z); double Gamma = WinkelGamma / 180 * Math.PI; double WinkelAlpha = Math.Asin(SeiteA * Math.Sin(Gamma) / SeiteC); WinkelAlpha = WinkelAlpha * 180 / Math.PI; double WinkelBeta = 180 - WinkelAlpha - WinkelGamma; double Beta = WinkelBeta / 180 * Math.PI; WinkelAlpha = Math.Round(WinkelAlpha, 1); WinkelBeta = Math.Round(WinkelBeta, 1); double SeiteB = SeiteC * Math.Sin(Beta) / Math.Sin(Gamma); SeiteB = Math.Round(SeiteB, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); Flaecheninhalt = Math.Round(Flaecheninhalt, 1);
Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 5) { Console.WriteLine("Welches Mass hat Seite b? (groessere Seite)"); string x = Console.ReadLine(); float SeiteB = float.Parse(x);
Console.WriteLine("Welches Mass hat Seite c? (kleinere Seite)"); string y = Console.ReadLine(); double SeiteC = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Beta?"); string z = Console.ReadLine(); double WinkelBeta = double.Parse(z); double Beta = WinkelBeta / 180 * Math.PI; double WinkelGamma = Math.Asin(SeiteC * Math.Sin(Beta) / SeiteB); WinkelGamma = WinkelGamma * 180 / Math.PI; double WinkelAlpha = 180 - WinkelBeta - WinkelGamma; double Alpha = WinkelAlpha / 180 * Math.PI; WinkelAlpha = Math.Round(WinkelAlpha, 1); WinkelGamma = Math.Round(WinkelGamma, 1); double SeiteA = SeiteB * Math.Sin(Alpha) / Math.Sin(Beta); SeiteA = Math.Round(SeiteA, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); Flaecheninhalt = Math.Round(Flaecheninhalt, 1);
Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 6) { Console.WriteLine("Welches Mass hat Seite b? (kleinere Seite)"); string x = Console.ReadLine(); float SeiteB = float.Parse(x);
Console.WriteLine("Welches Mass hat Seite c? (groessere Seite)"); string y = Console.ReadLine(); double SeiteC = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Gamma?"); string z = Console.ReadLine(); double WinkelGamma = double.Parse(z); double Gamma = WinkelGamma / 180 * Math.PI; double WinkelBeta = Math.Asin(SeiteB * Math.Sin(Gamma) / SeiteC); WinkelBeta = WinkelBeta * 180 / Math.PI; double WinkelAlpha = 180 - WinkelBeta - WinkelGamma; double Alpha = WinkelAlpha / 180 * Math.PI; WinkelAlpha = Math.Round(WinkelAlpha, 1); WinkelBeta = Math.Round(WinkelBeta, 1); double SeiteA = SeiteC * Math.Sin(Alpha) / Math.Sin(Gamma); SeiteA = Math.Round(SeiteA, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); Flaecheninhalt = Math.Round(Flaecheninhalt, 1);
Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } }
if (Variante1 == 3) { float bekannteGroessen = askForFloat("Welche Seiten und welcher Winkel sind bekannt? Waehle:\n1 fuer: Seiten a, b und Winkel Gamma\n2 fuer: Seiten a, c und Winkel Beta\n3 fuer: Seiten a, c und Winkel Alpha");
if (bekannteGroessen == 1) { Console.WriteLine("Welches Mass hat Seite a?)"); string x = Console.ReadLine(); float SeiteA = float.Parse(x);
Console.WriteLine("Welches Mass hat Seite b?"); string y = Console.ReadLine(); double SeiteB = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Gamma?"); string z = Console.ReadLine(); double WinkelGamma = double.Parse(z); double Gamma = WinkelGamma / 180 * Math.PI; double SeiteC = Math.Sqrt(SeiteA * SeiteA + SeiteB * SeiteB - 2 * SeiteA * SeiteB * Math.Cos(Gamma)); SeiteC = Math.Round(SeiteC, 2); double WinkelAlpha = Math.Acos((SeiteA * SeiteA - SeiteB * SeiteB - SeiteC * SeiteC) / (-2 * SeiteB * SeiteC)); WinkelAlpha = WinkelAlpha * 180 / Math.PI; WinkelAlpha = Math.Round(WinkelAlpha, 1);
double WinkelBeta = Math.Acos((SeiteB * SeiteB - SeiteC * SeiteC - SeiteA * SeiteA) / (-2 * SeiteC * SeiteA)); WinkelBeta = WinkelBeta * 180 / Math.PI; WinkelBeta = Math.Round(WinkelBeta, 1);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); Flaecheninhalt = Math.Round(Flaecheninhalt, 1);
Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 2) { Console.WriteLine("Welches Mass hat Seite a?)"); string x = Console.ReadLine(); float SeiteA = float.Parse(x);
Console.WriteLine("Welches Mass hat Seite c?"); string y = Console.ReadLine(); double SeiteC = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Beta?"); string z = Console.ReadLine(); double WinkelBeta = double.Parse(z); double Beta = WinkelBeta / 180 * Math.PI; double SeiteB = Math.Sqrt(SeiteA * SeiteA + SeiteC * SeiteC - 2 * SeiteA * SeiteC * Math.Cos(Beta)); SeiteB = Math.Round(SeiteB, 2); double WinkelAlpha = Math.Acos((SeiteA * SeiteA - SeiteB * SeiteB - SeiteC * SeiteC) / (-2 * SeiteB * SeiteC)); WinkelAlpha = WinkelAlpha * 180 / Math.PI; WinkelAlpha = Math.Round(WinkelAlpha, 1); double WinkelGamma = Math.Acos((SeiteC * SeiteC - SeiteA * SeiteA - SeiteB * SeiteB) / (-2 * SeiteA * SeiteB)); WinkelGamma = WinkelGamma * 180 / Math.PI; WinkelGamma = Math.Round(WinkelGamma, 1);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); Flaecheninhalt = Math.Round(Flaecheninhalt, 1);
Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } if (bekannteGroessen == 3) { Console.WriteLine("Welches Mass hat Seite b?)"); string x = Console.ReadLine(); float SeiteB = float.Parse(x);
Console.WriteLine("Welches Mass hat Seite c?"); string y = Console.ReadLine(); double SeiteC = double.Parse(y);
Console.WriteLine("Welchen Wert hat Winkel Alpha?"); string z = Console.ReadLine(); double WinkelAlpha = double.Parse(z); double Alpha = WinkelAlpha / 180 * Math.PI; double SeiteA = Math.Sqrt(SeiteB * SeiteB + SeiteC * SeiteC - 2 * SeiteB * SeiteC * Math.Cos(Alpha)); SeiteA = Math.Round(SeiteA, 2); double WinkelBeta = Math.Acos((SeiteB * SeiteB - SeiteC * SeiteC - SeiteA * SeiteA) / (-2 * SeiteC * SeiteA)); WinkelBeta = WinkelBeta * 180 / Math.PI; WinkelBeta = Math.Round(WinkelBeta, 1);
double WinkelGamma = Math.Acos((SeiteC * SeiteC - SeiteA * SeiteA - SeiteB * SeiteB) / (-2 * SeiteA * SeiteB)); WinkelGamma = WinkelGamma * 180 / Math.PI; WinkelGamma = Math.Round(WinkelGamma, 1);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); Flaecheninhalt = Math.Round(Flaecheninhalt, 1);
Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } } if (Variante1 == 4) { Console.WriteLine("Welches Mass hat Seite a?)"); string x = Console.ReadLine(); float SeiteA = float.Parse(x);
Console.WriteLine("Welches Mass hat Seite b?"); string y = Console.ReadLine(); double SeiteB = double.Parse(y);
Console.WriteLine("Welches Mass hat Seite c?"); string z = Console.ReadLine(); double SeiteC = double.Parse(z);
double WinkelAlpha = Math.Acos((SeiteA * SeiteA - SeiteB * SeiteB - SeiteC * SeiteC) / (-2 * SeiteB * SeiteC)); WinkelAlpha = WinkelAlpha * 180 / Math.PI; WinkelAlpha = Math.Round(WinkelAlpha, 1);
double WinkelBeta = Math.Acos((SeiteB * SeiteB - SeiteC * SeiteC - SeiteA * SeiteA) / (-2 * SeiteC * SeiteA)); WinkelBeta = WinkelBeta * 180 / Math.PI; WinkelBeta = Math.Round(WinkelBeta, 1);
double WinkelGamma = Math.Acos((SeiteC * SeiteC - SeiteA * SeiteA - SeiteB * SeiteB) / (-2 * SeiteA * SeiteB)); WinkelGamma = WinkelGamma * 180 / Math.PI; WinkelGamma = Math.Round(WinkelGamma, 1);
double s = (SeiteA + SeiteB + SeiteC) / 2; double w = s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC); double Flaecheninhalt = Math.Sqrt(w); Flaecheninhalt = Math.Round(Flaecheninhalt, 1);
Console.WriteLine(""); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad"); Console.WriteLine(""); Console.WriteLine("Seite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm"); Console.WriteLine(""); Console.WriteLine("Flaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); Console.WriteLine(""); } } } } } |
Grüsse
interessierter
|
|
Th69
      

Beiträge: 4798
Erhaltene Danke: 1059
Win10
C#, C++ (VS 2017/19/22)
|
Verfasst: Fr 11.05.12 19:35
Hallo,
interessierter hat folgendes geschrieben: | Vielleicht hat ja jemand Stichworte dazu, wie man den Code mit viel weniger Zeilen hinbekommen hätte |
Methoden (bzw. oftmals auch Funktionen genannt)!
Zwei bewährte "Methoden" (ich hoffe, du verstehst den Wortwitz  ) der Programmierung sind KISS-Prinzip und DRY.
Vermeide Wiederholungen in deinem Code, sondern extrahiere diese zu einer Methode und verwende passende Parameter.
Bezogen auf deinen Code wäre dies z.B. der große if-Block sowie die Ausgabe - erzeuge dir dafür passend benannte Methoden und rufe diese dann mit den entsprechenden Parametern (z.B. WinkelAlpha, WinkelBeta, WinkelGamma, SeiteA, ...) auf.
Das EVA-Prinzip hast du ja schon generell in deinem Programm drin, nur solltest du dieses auch klarer trennen (auch hier am besten eigene Methoden dafür definieren).
Am besten sogar eine eigene Klasse, welche nur für die Berechnungen zuständig ist.
Dann ist mir noch aufgefallen, daß du zwar schon die Methode askForFloat definiert und verwendet hast, jedoch nicht durchgängig. Probiere mal bei den Abfragen für die Werte (z.B. "Seite a") einen Buchstaben einzugeben (anstatt einer Zahl).
Und auch für die Umrechnung Bogen- nach Grad (RadToDeg) und umgekehrt (DegToRad) solltest du eine Methode verwenden.
Du siehst, da kann man noch viel optimieren...
Für diesen Beitrag haben gedankt: interessierter
|
|
interessierter 
      
Beiträge: 75
|
Verfasst: Sa 12.05.12 18:15
Danke viel mal, ich mach mich gleich mal ans optimieren
Grüsse
interessierter
|
|
interessierter 
      
Beiträge: 75
|
Verfasst: So 13.05.12 00:54
Ich habe jetzt meinen Code fertig optimiert und hatte von den angfänglichen 880 Codezeilen nur noch 455. 425 Zeilen sind verschwunden, fast die Hälfte des ursprünglichen Quellcode
Was ich gemacht habe:
1. Leere Zeilen gelöscht und alle Abfragen an eine Funktion weitergegeben
2. Alle Umrechnungen von Grad in Bogenmass an eine Funktion übergeben
Der neue Quellcode sieht meines Erachtens viel professioneller aus. Werde den neuen Code posten. Hat jemand noch weitere Inputs wie man es noch einfacher und übersichtlicher gestalten könnte? Jetzt mal abgesehen von weiteren Klassen die z.B nur für die Berechnungen zuständig sind, weil soweit bin ich noch nicht mit den Grundlagen. Kommt aber noch. Kreis und Rechteckberechnung ist jetzt übrigens auch noch dabei.
Hier der Code:
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: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380: 381: 382: 383: 384: 385: 386: 387: 388: 389: 390: 391: 392: 393: 394: 395: 396: 397: 398: 399: 400: 401: 402: 403: 404: 405: 406: 407: 408: 409: 410: 411: 412: 413: 414: 415: 416: 417: 418: 419: 420: 421: 422: 423: 424: 425: 426: 427: 428: 429: 430: 431: 432: 433: 434: 435: 436: 437: 438: 439: 440: 441: 442: 443: 444: 445: 446: 447: 448: 449: 450: 451: 452: 453: 454: 455:
| using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace Formen_berechnen { class Program { static float askForFloat(string message) { while (true) { Console.WriteLine(message); string Eingabe = Console.ReadLine(); float value; if (float.TryParse(Eingabe, out value)) { return value; } } } static double askForDouble(string message) { while (true) { Console.WriteLine(message); string Eingabe = Console.ReadLine(); double value; if (double.TryParse(Eingabe, out value)) { return value; } } } static double GradzuBogenmass(double Grad) { return (Math.PI / 180.0) * Grad; } static void Main(string[] args) { float Form = askForFloat("Welche Form willst du berechnen? Waehle:\n1 fuer Dreieck\n2 fuer Rechteck\n3 fuer Kreis"); if (Form == 1) { float Variante = askForFloat("Ein Dreieck kann eindeutig konstruiert werden wenn eine der folgenden Kombinationen an gegebenen Massen vorliegt. Wahele:\n1 fuer: eine Seite und 2 Winkel\n2 fuer: zwei Seiten und der der groesseren Seite gegenueberliegende Winkel\n3 fuer: zwei Seiten und der eingeschlossene Winkel\n4 fuer: drei Seiten"); if (Variante == 1) { float bekannteGroessen = askForFloat("Welche Seite und welche Winkel sind bekannt? Waehle:\n1 fuer: Seite a, Winkel Beta und Gamma\n2 fuer: Seite a, Winkel Alpha und Gamma\n3 fuer: Seite a, Winkel Alpha und Beta\n4 fuer: Seite b, Winkel Beta und Gamma\n5 fuer: Seite b, Winkel Alpha und Gamma\n6 fuer: Seite b, Winkel Alpha und Beta\n7 fuer: Seite c, Winkel Beta und Gamma\n8 fuer: Seite c, Winkel Alpha und Gamma\n9 fuer: Seite c, Winkel Alpha und Beta"); if (bekannteGroessen == 1) { float SeiteA = askForFloat("Welches Mass hat Seite a?"); double WinkelBeta = askForDouble("Welchen Wert hat Winkel Beta?"); double WinkelGamma = askForDouble("Welchen Wert hat Winkel Gamma?"); double WinkelAlpha = 180 - WinkelBeta - WinkelGamma; double Alpha = GradzuBogenmass(WinkelAlpha); double Beta = GradzuBogenmass(WinkelBeta); double Gamma = GradzuBogenmass(WinkelGamma); double SeiteB = SeiteA * Math.Sin(Beta) / Math.Sin(Alpha); double SeiteC = SeiteA * Math.Sin(Gamma) / Math.Sin(Alpha); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); SeiteB = Math.Round(SeiteB, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 2) { float SeiteA = askForFloat("Welches Mass hat Seite a?"); double WinkelAlpha = askForDouble("Welchen Wert hat Winkel Alpha?"); double WinkelGamma = askForDouble("Welchen Wert hat Winkel Gamma?"); double WinkelBeta = 180 - WinkelAlpha - WinkelGamma; double Alpha = GradzuBogenmass(WinkelAlpha); double Beta = GradzuBogenmass(WinkelBeta); double Gamma = GradzuBogenmass(WinkelGamma); double SeiteB = SeiteA * Math.Sin(Beta) / Math.Sin(Alpha); double SeiteC = SeiteA * Math.Sin(Gamma) / Math.Sin(Alpha); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); SeiteB = Math.Round(SeiteB, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 3) { float SeiteA = askForFloat("Welches Mass hat Seite a?"); double WinkelAlpha = askForDouble("Welchen Wert hat Winkel Alpha?"); double WinkelBeta = askForDouble("Welchen Wert hat Winkel Beta?"); double WinkelGamma = 180 - WinkelAlpha - WinkelBeta; double Alpha = GradzuBogenmass(WinkelAlpha); double Beta = GradzuBogenmass(WinkelBeta); double Gamma = GradzuBogenmass(WinkelGamma); double SeiteB = SeiteA * Math.Sin(Beta) / Math.Sin(Alpha); double SeiteC = SeiteA * Math.Sin(Gamma) / Math.Sin(Alpha); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); SeiteB = Math.Round(SeiteB, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 4) { float SeiteB = askForFloat("Welches Mass hat Seite b?"); double WinkelBeta = askForDouble("Welchen Wert hat Winkel Beta?"); double WinkelGamma = askForDouble("Welchen Wert hat Winkel Gamma?"); double WinkelAlpha = 180 - WinkelBeta - WinkelGamma; double Alpha = GradzuBogenmass(WinkelAlpha); double Beta = GradzuBogenmass(WinkelBeta); double Gamma = GradzuBogenmass(WinkelGamma); double SeiteA = SeiteB * Math.Sin(Alpha) / Math.Sin(Beta); double SeiteC = SeiteB * Math.Sin(Gamma) / Math.Sin(Beta); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); SeiteA = Math.Round(SeiteA, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 5) { float SeiteB = askForFloat("Welches Mass hat Seite b?"); double WinkelAlpha = askForDouble("Welchen Wert hat Winkel Alpha?"); double WinkelGamma = askForDouble("Welchen Wert hat Winkel Gamma?"); double WinkelBeta = 180 - WinkelAlpha - WinkelGamma; double Alpha = GradzuBogenmass(WinkelAlpha); double Beta = GradzuBogenmass(WinkelBeta); double Gamma = GradzuBogenmass(WinkelGamma); double SeiteA = SeiteB * Math.Sin(Alpha) / Math.Sin(Beta); double SeiteC = SeiteB * Math.Sin(Gamma) / Math.Sin(Beta); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); SeiteA = Math.Round(SeiteA, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 6) { float SeiteB = askForFloat("Welches Mass hat Seite b?"); double WinkelAlpha = askForDouble("Welchen Wert hat Winkel Alpha?"); double WinkelBeta = askForDouble("Welchen Wert hat Winkel Beta?"); double WinkelGamma = 180 - WinkelAlpha - WinkelBeta; double Alpha = GradzuBogenmass(WinkelAlpha); double Beta = GradzuBogenmass(WinkelBeta); double Gamma = GradzuBogenmass(WinkelGamma); double SeiteA = SeiteB * Math.Sin(Alpha) / Math.Sin(Beta); double SeiteC = SeiteB * Math.Sin(Gamma) / Math.Sin(Beta); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); SeiteA = Math.Round(SeiteA, 2); SeiteC = Math.Round(SeiteC, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 7) { float SeiteC = askForFloat("Welches Mass hat Seite c?"); double WinkelBeta = askForDouble("Welchen Wert hat Winkel Beta?"); double WinkelGamma = askForDouble("Welchen Wert hat Winkel Gamma?"); double WinkelAlpha = 180 - WinkelBeta - WinkelGamma; double Alpha = GradzuBogenmass(WinkelAlpha); double Beta = GradzuBogenmass(WinkelBeta); double Gamma = GradzuBogenmass(WinkelGamma); double SeiteA = SeiteC * Math.Sin(Alpha) / Math.Sin(Gamma); double SeiteB = SeiteC * Math.Sin(Beta) / Math.Sin(Gamma); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); SeiteA = Math.Round(SeiteA, 2); SeiteB = Math.Round(SeiteB, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 8) { float SeiteC = askForFloat("Welches Mass hat Seite c?"); double WinkelAlpha = askForDouble("Welchen Wert hat Winkel Alpha?"); double WinkelGamma = askForDouble("Welchen Wert hat Winkel Gamma?"); double WinkelBeta = 180 - WinkelAlpha - WinkelGamma; double Alpha = GradzuBogenmass(WinkelAlpha); double Beta = GradzuBogenmass(WinkelBeta); double Gamma = GradzuBogenmass(WinkelGamma); double SeiteA = SeiteC * Math.Sin(Alpha) / Math.Sin(Gamma); double SeiteB = SeiteC * Math.Sin(Beta) / Math.Sin(Gamma); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); SeiteA = Math.Round(SeiteA, 2); SeiteB = Math.Round(SeiteB, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 9) { float SeiteC = askForFloat("Welches Mass hat Seite c?"); double WinkelAlpha = askForDouble("Welchen Wert hat Winkel Alpha?"); double WinkelBeta = askForDouble("Welchen Wert hat Winkel Beta?"); double WinkelGamma = 180 - WinkelAlpha - WinkelBeta; double Alpha = GradzuBogenmass(WinkelAlpha); double Beta = GradzuBogenmass(WinkelBeta); double Gamma = GradzuBogenmass(WinkelGamma); double SeiteA = SeiteC * Math.Sin(Alpha) / Math.Sin(Gamma); double SeiteB = SeiteC * Math.Sin(Beta) / Math.Sin(Gamma); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); SeiteA = Math.Round(SeiteA, 2); SeiteB = Math.Round(SeiteB, 2); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } } if (Variante == 2) { float bekannteGroessen = askForFloat("Welche Seite und welche Winkel sind bekannt? Waehle:\n1 fuer: Seiten a, b und Winkel Alpha\n2 fuer: Seiten a, b und Winkel Beta\n3 fuer: Seiten a, c und Winkel Alpha\n4 fuer: Seiten a, c und Winkel Gamma\n5 fuer: Seiten b, c und winkel Beta\n6 fuer: Seiten b, c und Winkel Gamma"); if (bekannteGroessen == 1) { float SeiteA = askForFloat("Welches Mass hat Seite a? (groessere Seite)"); float SeiteB = askForFloat("Welches Mass hat Seite b? (kleinere Seite)"); double WinkelAlpha = askForDouble("Welchen Wert hat Winkel Alpha?"); double Alpha = GradzuBogenmass(WinkelAlpha); double WinkelBeta = Math.Asin(SeiteB * Math.Sin(Alpha) / SeiteA); double Beta = GradzuBogenmass(WinkelBeta); double WinkelGamma = 180 - WinkelAlpha - WinkelBeta; double Gamma = GradzuBogenmass(WinkelGamma); WinkelBeta = Math.Round(WinkelBeta, 1); WinkelGamma = Math.Round(WinkelGamma, 1); double SeiteC = SeiteA * Math.Sin(Gamma) / Math.Sin(Alpha); SeiteC = Math.Round(SeiteC, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); Flaecheninhalt = Math.Round(Flaecheninhalt, 1); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 2) { float SeiteA = askForFloat("Welches Mass hat Seite a? (kleinere Seite)"); float SeiteB = askForFloat("Welches Mass hat Seite b? (groessere Seite)"); double WinkelBeta = askForDouble("Welchen Wert hat Winkel Beta?"); double Beta = GradzuBogenmass(WinkelBeta); double WinkelAlpha = Math.Asin(SeiteA * Math.Sin(Beta) / SeiteB); double Alpha = GradzuBogenmass(WinkelAlpha); double WinkelGamma = 180 - WinkelAlpha - WinkelBeta; double Gamma = GradzuBogenmass(WinkelGamma); WinkelAlpha = Math.Round(WinkelAlpha, 1); WinkelGamma = Math.Round(WinkelGamma, 1); double SeiteC = SeiteB * Math.Sin(Gamma) / Math.Sin(Beta); SeiteC = Math.Round(SeiteC, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 3) { float SeiteA = askForFloat("Welches Mass hat Seite a? (groessere Seite)"); float SeiteC = askForFloat("Welches Mass hat Seite c? (kleinere Seite)"); double WinkelAlpha = askForDouble("Welchen Wert hat Winkel Alpha?"); double Alpha = GradzuBogenmass(WinkelAlpha); double WinkelGamma = Math.Asin(SeiteC * Math.Sin(Alpha) / SeiteA); double Gamma = GradzuBogenmass(WinkelGamma); double WinkelBeta = 180 - WinkelAlpha - WinkelGamma; double Beta = GradzuBogenmass(WinkelBeta); WinkelBeta = Math.Round(WinkelBeta, 1); WinkelGamma = Math.Round(WinkelGamma, 1); double SeiteB = SeiteA * Math.Sin(Beta) / Math.Sin(Alpha); SeiteB = Math.Round(SeiteB, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); Flaecheninhalt = Math.Round(Flaecheninhalt, 1); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 4) { float SeiteA = askForFloat("Welches Mass hat Seite a? (kleinere Seite)"); float SeiteC = askForFloat("Welches Mass hat Seite c? (groessere Seite)"); double WinkelGamma = askForDouble("Welchen Wert hat Winkel Gamma?"); double Gamma = GradzuBogenmass(WinkelGamma); double WinkelAlpha = Math.Asin(SeiteA * Math.Sin(Gamma) / SeiteC); double Alpha = GradzuBogenmass(WinkelAlpha); double WinkelBeta = 180 - WinkelAlpha - WinkelGamma; double Beta = GradzuBogenmass(WinkelBeta); WinkelAlpha = Math.Round(WinkelAlpha, 1); WinkelBeta = Math.Round(WinkelBeta, 1); double SeiteB = SeiteC * Math.Sin(Beta) / Math.Sin(Gamma); SeiteB = Math.Round(SeiteB, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); Flaecheninhalt = Math.Round(Flaecheninhalt, 1); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 5) { float SeiteB = askForFloat("Welches Mass hat Seite b? (groessere Seite)"); float SeiteC = askForFloat("Welches Mass hat Seite c? (kleinere Seite)"); double WinkelBeta = askForDouble("Welchen Wert hat Winkel Beta?"); double Beta = GradzuBogenmass(WinkelBeta); double WinkelGamma = Math.Asin(SeiteC * Math.Sin(Beta) / SeiteB); double Gamma = GradzuBogenmass(WinkelGamma); double WinkelAlpha = 180 - WinkelBeta - WinkelGamma; double Alpha = GradzuBogenmass(WinkelAlpha); WinkelAlpha = Math.Round(WinkelAlpha, 1); WinkelGamma = Math.Round(WinkelGamma, 1); double SeiteA = SeiteB * Math.Sin(Alpha) / Math.Sin(Beta); SeiteA = Math.Round(SeiteA, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); Flaecheninhalt = Math.Round(Flaecheninhalt, 1); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 6) { float SeiteB = askForFloat("Welches Mass hat Seite b? (kleinere Seite)"); float SeiteC = askForFloat("Welches Mass hat Seite c? (groessere Seite)"); double WinkelGamma = askForDouble("Welchen Wert hat Winkel Gamma?"); double Gamma = GradzuBogenmass(WinkelGamma); double WinkelBeta = Math.Asin(SeiteB * Math.Sin(Gamma) / SeiteC); double Beta = GradzuBogenmass(WinkelBeta); double WinkelAlpha = 180 - WinkelBeta - WinkelGamma; double Alpha = GradzuBogenmass(WinkelAlpha); WinkelAlpha = Math.Round(WinkelAlpha, 1); WinkelBeta = Math.Round(WinkelBeta, 1); double SeiteA = SeiteC * Math.Sin(Alpha) / Math.Sin(Gamma); SeiteA = Math.Round(SeiteA, 2); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); Flaecheninhalt = Math.Round(Flaecheninhalt, 1); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } } if (Variante == 3) { float bekannteGroessen = askForFloat("Welche Seiten und welcher Winkel sind bekannt? Waehle:\n1 fuer: Seiten a, b und Winkel Gamma\n2 fuer: Seiten a, c und Winkel Beta\n3 fuer: Seiten a, c und Winkel Alpha"); if (bekannteGroessen == 1) { float SeiteA = askForFloat("Welches Mass hat Seite a?"); float SeiteB = askForFloat("Welches Mass hat Seite b?"); double WinkelGamma = askForDouble("Welchen Wert hat Winkel Gamma?"); double Gamma = GradzuBogenmass(WinkelGamma); double SeiteC = Math.Sqrt(SeiteA * SeiteA + SeiteB * SeiteB - 2 * SeiteA * SeiteB * Math.Cos(Gamma)); SeiteC = Math.Round(SeiteC, 2); double WinkelAlpha = Math.Acos((SeiteA * SeiteA - SeiteB * SeiteB - SeiteC * SeiteC) / (-2 * SeiteB * SeiteC)); double Alpha = GradzuBogenmass(WinkelAlpha); WinkelAlpha = Math.Round(WinkelAlpha, 1); double WinkelBeta = Math.Acos((SeiteB * SeiteB - SeiteC * SeiteC - SeiteA * SeiteA) / (-2 * SeiteC * SeiteA)); double Beta = GradzuBogenmass(WinkelBeta); WinkelBeta = Math.Round(WinkelBeta, 1); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); Flaecheninhalt = Math.Round(Flaecheninhalt, 1); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 2) { float SeiteA = askForFloat("Welches Mass hat Seite a?"); float SeiteC = askForFloat("Welches Mass hat Seite c?"); double WinkelBeta = askForDouble("Welchen Wert hat Winkel Beta?"); double Beta = GradzuBogenmass(WinkelBeta); double SeiteB = Math.Sqrt(SeiteA * SeiteA + SeiteC * SeiteC - 2 * SeiteA * SeiteC * Math.Cos(Beta)); SeiteB = Math.Round(SeiteB, 2); double WinkelAlpha = Math.Acos((SeiteA * SeiteA - SeiteB * SeiteB - SeiteC * SeiteC) / (-2 * SeiteB * SeiteC)); double Alpha = GradzuBogenmass(WinkelAlpha); WinkelAlpha = Math.Round(WinkelAlpha, 1); double WinkelGamma = Math.Acos((SeiteC * SeiteC - SeiteA * SeiteA - SeiteB * SeiteB) / (-2 * SeiteA * SeiteB)); double Gamma = GradzuBogenmass(WinkelGamma); WinkelGamma = Math.Round(WinkelGamma, 1); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); Flaecheninhalt = Math.Round(Flaecheninhalt, 1); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 3) { float SeiteB = askForFloat("Welches Mass hat Seite b?"); float SeiteC = askForFloat("Welches Mass hat Seite c?"); double WinkelAlpha = askForDouble("Welchen Wert hat Winkel Alpha?"); double Alpha = GradzuBogenmass(WinkelAlpha); double SeiteA = Math.Sqrt(SeiteB * SeiteB + SeiteC * SeiteC - 2 * SeiteB * SeiteC * Math.Cos(Alpha)); SeiteA = Math.Round(SeiteA, 2); double WinkelBeta = Math.Acos((SeiteB * SeiteB - SeiteC * SeiteC - SeiteA * SeiteA) / (-2 * SeiteC * SeiteA)); double Beta = GradzuBogenmass(WinkelBeta); WinkelBeta = Math.Round(WinkelBeta, 1); double WinkelGamma = Math.Acos((SeiteC * SeiteC - SeiteA * SeiteA - SeiteB * SeiteB) / (-2 * SeiteA * SeiteB)); double Gamma = GradzuBogenmass(WinkelGamma); WinkelGamma = Math.Round(WinkelGamma, 1); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); Flaecheninhalt = Math.Round(Flaecheninhalt, 1); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } } if (Variante == 4) { float SeiteA = askForFloat("Welches Mass hat Seite a?"); float SeiteB = askForFloat("Welches Mass hat Seite b?"); float SeiteC = askForFloat("Welches Mass hat Seite c?"); double WinkelAlpha = Math.Acos((SeiteA * SeiteA - SeiteB * SeiteB - SeiteC * SeiteC) / (-2 * SeiteB * SeiteC)); double Alpha = GradzuBogenmass(WinkelAlpha); WinkelAlpha = Math.Round(WinkelAlpha, 1); double WinkelBeta = Math.Acos((SeiteB * SeiteB - SeiteC * SeiteC - SeiteA * SeiteA) / (-2 * SeiteC * SeiteA)); double Beta = GradzuBogenmass(WinkelBeta); WinkelBeta = Math.Round(WinkelBeta, 1); double WinkelGamma = Math.Acos((SeiteC * SeiteC - SeiteA * SeiteA - SeiteB * SeiteB) / (-2 * SeiteA * SeiteB)); double Gamma = GradzuBogenmass(WinkelGamma); WinkelGamma = Math.Round(WinkelGamma, 1); double s = (SeiteA + SeiteB + SeiteC) / 2; double Flaecheninhalt = Math.Sqrt(s * (s - SeiteA) * (s - SeiteB) * (s - SeiteC)); Flaecheninhalt = Math.Round(Flaecheninhalt, 1); Console.WriteLine("Winkel Alpha: " + WinkelAlpha + " Grad\nWinkel Beta: " + WinkelBeta + " Grad\nWinkel Gamma: " + WinkelGamma + " Grad\nSeite a: " + SeiteA + "cm\nSeite b: " + SeiteB + "cm\nSeite c: " + SeiteC + "cm\nFlaecheninhalt des Dreiecks: " + Flaecheninhalt + "cm^2"); } } if (Form == 2) { float seiteA = askForFloat("Welche laenge hat Seite a?"); float seiteB = askForFloat("Welche laenge hat Seite b?"); float Flaecheninhalt = seiteA * seiteB; float Umfang = (2 * seiteA) + (2 * seiteB); double Diagonale = Math.Sqrt((seiteA * seiteA) + (seiteB * seiteB)); Console.WriteLine("Flaecheninhalt = " + Flaecheninhalt + "cm^2\nUmfang = " + Umfang + "cm\nDiagonale = " + Diagonale + "cm"); } if (Form == 3) { float bekannteGroessen = askForFloat("Welches Groesse ist bekannt? Wahele:\n1 fuer: Radius\n2 fuer: Durchmesser\n3 fuer: Umfang"); if (bekannteGroessen == 1) { double Radius = askForDouble("Welchen Wert hat der Radius? (in cm)"); double Flaecheninhalt = Radius * Radius * Math.PI; Flaecheninhalt = Math.Round(Flaecheninhalt, 2); Console.WriteLine("Die Kreisflaeche betraegt: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 2) { double Durchmesser = askForDouble("Welchen Wert hat der Durchmesser? (in cm)"); double y = Durchmesser / 2; double Flaecheninhalt = y * y * Math.PI; Flaecheninhalt = Math.Round(Flaecheninhalt, 3); Console.WriteLine("Die Kreisflaeche betraegt: " + Flaecheninhalt + "cm^2"); } if (bekannteGroessen == 3) { double Umfang = askForDouble("Welchen Wert hat der Umfang? (in cm)"); double Radius = Umfang / (2 * Math.PI); double Flaecheninhalt = Radius * Radius * Math.PI; Flaecheninhalt = Math.Round(Flaecheninhalt, 3); Console.WriteLine("Die Kreisflaeche betraegt: " + Flaecheninhalt + "cm^2"); } } } } } |
Grüsse
interessierter
|
|
|