Advertisement
Guest User

MW Arrays

a guest
Jan 29th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. // Source.cpp
  2.  
  3.  
  4. #include <iostream>
  5. #include <cmath>
  6. #include "Header.h"
  7.  
  8. using namespace std;
  9.  
  10. float arMittel();
  11. float geoMittel();
  12. float harMittel();
  13.  
  14.  
  15. void main() {
  16.  
  17. while (true) {
  18.  
  19. char m;
  20.  
  21. cout << "Bitte wählen Sie die Art ihres Mittelwerts: " << endl;
  22. cout << "1: Arithmetischer Mittelwert " << endl;
  23. cout << "2: Geometrischer Mittelwert " << endl;
  24. cout << "3: Harmonischer Mittelwert " << endl;
  25. cout << "Q: Programm beenden " << endl << endl;
  26. cin >> m;
  27. cout << endl;
  28.  
  29. switch (m) {
  30.  
  31. case '1':
  32.  
  33. cout << "Arithmetischer Mittelwert: " << arMittel() << endl;
  34. cout << endl;
  35.  
  36. break;
  37.  
  38. case '2':
  39.  
  40.  
  41. cout << "Geometrischer Mittelwert: " << geoMittel() << endl;
  42. cout << endl;
  43.  
  44. break;
  45.  
  46. case '3':
  47.  
  48.  
  49. cout << "Harmonischer Mittelwert: " << harMittel() << endl;
  50. cout << endl;
  51.  
  52. break;
  53.  
  54. case 'q':
  55. case 'Q':
  56. return;
  57.  
  58. default:
  59.  
  60. cout << "Falsche Eingabe!" << endl << endl;
  61.  
  62.  
  63. }
  64. }
  65.  
  66. }
  67.  
  68. // Header.h
  69. #pragma once
  70.  
  71. #include <cmath>
  72.  
  73. float arMittel() {
  74.  
  75. int a[32];
  76.  
  77. for (int i = 0; i < 32; i++) {
  78. a[i] = 3 * i;
  79. }
  80.  
  81. float S = 0;
  82.  
  83. for (int j = 0; j < 32; j++) {
  84. S = S + a[j];
  85. }
  86. return S / 32;
  87.  
  88. }
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96. float geoMittel() {
  97.  
  98. int a[32];
  99.  
  100. for (int i = 0; i < 32; i++) {
  101.  
  102. a[i] = 3 * i;
  103. }
  104.  
  105. double P = 1.0;
  106.  
  107. for (int j = 1; j < 32; j++) {
  108.  
  109. P = P * a[j];
  110. }
  111.  
  112.  
  113. double MG = 0;
  114.  
  115.  
  116. MG = pow(P, (1.0 / (31.0)));
  117.  
  118.  
  119.  
  120.  
  121. return MG;
  122. }
  123.  
  124.  
  125.  
  126.  
  127. float harMittel() {
  128.  
  129. float a[32];
  130.  
  131.  
  132.  
  133. for (int i = 1; i < 32; i++) {
  134.  
  135. a[i] = (1.0 / (i * 3.0));
  136.  
  137.  
  138. }
  139.  
  140. float S = 0;
  141.  
  142. for (int j = 1; j < 32; j++) {
  143.  
  144. S = S + a[j];
  145. }
  146.  
  147. float MH = 0;
  148.  
  149. MH = 31 / S;
  150.  
  151.  
  152.  
  153.  
  154. return MH;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement