Advertisement
Guest User

Programm

a guest
Nov 13th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #include "fhswf_service.h"
  4. #include<string.h>
  5. #include<stdlib.h>
  6. #include<ctype.h>
  7. #include<math.h>
  8.  
  9. int check_Input_float(char* eingabe);
  10.  
  11. int main(void)
  12. {
  13.  
  14. char vEingabe[10] = {0};
  15. char wEingabe[10] = {0};
  16. char xEingabe[10] = {0};
  17. char yEingabe[10] = {0};
  18. char dxEingabe[10] = {0};
  19.  
  20. float v = 0.0, w = 0.0, dx = 0.0, punkt = 0.0, flaecheNeu = 0.0, flaecheAlt = 0.0, p = 0.0, xAlt = 0.0, yAlt = 0.0, xNeu = 0.0, yNeu = 0.0;
  21.  
  22. float laengeVW = 0.0;
  23.  
  24. int laenge = 0, fehler = 0;
  25.  
  26. printf("Moin,Servus,Moin Herr Neugebauer oder Herr Klein #Ehregenommen");
  27. do {
  28. printf("\nBitte einen Wert fuer X eingeben: ");
  29. gets_s(xEingabe);
  30.  
  31. } while (check_Input_float(xEingabe) == 0);
  32.  
  33. xAlt = atof(xEingabe);
  34.  
  35. do {
  36.  
  37. do {
  38. printf("\nBitte einen Wert fuer Y eingeben: ");
  39. gets_s(yEingabe);
  40.  
  41. } while (check_Input_float(yEingabe) == 0);
  42.  
  43. } while (xEingabe <= yEingabe);
  44.  
  45. yAlt = atof(yEingabe);
  46.  
  47.  
  48. do {
  49. printf("\nBitte einen Wert fuer V eingeben: ");
  50. gets_s(vEingabe);
  51.  
  52. } while (check_Input_float(vEingabe) == 0);
  53.  
  54. v = atof(vEingabe);
  55.  
  56. do {
  57. printf("\nBitte einen Wert fuer W eingeben: ");
  58. gets_s(wEingabe);
  59.  
  60. } while (check_Input_float(wEingabe) == 0);
  61.  
  62. w = atof(wEingabe);
  63.  
  64. do {
  65. printf("\nBitte einen Wert fuer die Schrittweite eingeben: ");
  66. gets_s(dxEingabe);
  67.  
  68. } while (check_Input_float(dxEingabe) == 0);
  69.  
  70. dx = atof(dxEingabe);
  71.  
  72. laengeVW = sqrt(pow(v, 2) + pow(w, 2));
  73.  
  74. yNeu = yAlt - w;
  75.  
  76. p = dx;
  77.  
  78. for (punkt =yNeu; punkt <= yAlt; punkt + p)
  79. {
  80.  
  81.  
  82. flaecheNeu = xNeu * yNeu;
  83. flaecheAlt = flaecheNeu;
  84.  
  85. xNeu = xAlt - punkt;
  86. yNeu = yNeu + punkt;
  87.  
  88. if (flaecheAlt <= flaecheNeu && xNeu > xAlt - v && yNeu < yAlt)
  89. {
  90. printf("\n\nDas Maximum liegt bei: x= %f y =%f", xNeu, yNeu);
  91. printf("\n\nDie maximale Flaeche betraegt :%f", flaecheAlt);
  92.  
  93. }
  94.  
  95. }
  96.  
  97. printf("\n\nDas Maximum liegt bei: x= %f y =%f", xNeu, yNeu);
  98.  
  99. printf("\n\nDie maximale Flaeche betraegt :%f", flaecheAlt);
  100.  
  101.  
  102.  
  103. getchar();
  104. return(1);
  105. }
  106.  
  107. /*Funktion zur Überprüfung einer korrekten Eingabe
  108.  
  109. Rückgabewert 1 = korrekte Eingabe
  110. Rückgabewert 0 = unkorrekte Eingabe
  111. Prüfung von Vorzeichen
  112. Prüfung von Punkten
  113. */
  114. int check_Input_float(char* eingabe)
  115. {
  116. int index = 0;
  117.  
  118. if (strlen(eingabe) == 0)
  119. {
  120. return(0);
  121. }
  122.  
  123. if (eingabe[0]=='+')
  124. {
  125. eingabe[0] = '0';
  126. }
  127. else if (eingabe[0] == '-')
  128. {
  129. index = 1;
  130. }
  131. for (index; index < strlen(eingabe); index++)
  132. {
  133. if (!(isdigit(eingabe[index]) || eingabe[index]=='.'))
  134. {
  135. return(0);
  136. }
  137. }
  138. return(1);
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement