Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Source.cpp
- #include <iostream>
- #include <cmath>
- #include "Header.h"
- using namespace std;
- float arMittel();
- float geoMittel();
- float harMittel();
- void main() {
- while (true) {
- char m;
- cout << "Bitte wählen Sie die Art ihres Mittelwerts: " << endl;
- cout << "1: Arithmetischer Mittelwert " << endl;
- cout << "2: Geometrischer Mittelwert " << endl;
- cout << "3: Harmonischer Mittelwert " << endl;
- cout << "Q: Programm beenden " << endl << endl;
- cin >> m;
- cout << endl;
- switch (m) {
- case '1':
- cout << "Arithmetischer Mittelwert: " << arMittel() << endl;
- cout << endl;
- break;
- case '2':
- cout << "Geometrischer Mittelwert: " << geoMittel() << endl;
- cout << endl;
- break;
- case '3':
- cout << "Harmonischer Mittelwert: " << harMittel() << endl;
- cout << endl;
- break;
- case 'q':
- case 'Q':
- return;
- default:
- cout << "Falsche Eingabe!" << endl << endl;
- }
- }
- }
- // Header.h
- #pragma once
- #include <cmath>
- float arMittel() {
- int a[32];
- for (int i = 0; i < 32; i++) {
- a[i] = 3 * i;
- }
- float S = 0;
- for (int j = 0; j < 32; j++) {
- S = S + a[j];
- }
- return S / 32;
- }
- float geoMittel() {
- int a[32];
- for (int i = 0; i < 32; i++) {
- a[i] = 3 * i;
- }
- double P = 1.0;
- for (int j = 1; j < 32; j++) {
- P = P * a[j];
- }
- double MG = 0;
- MG = pow(P, (1.0 / (31.0)));
- return MG;
- }
- float harMittel() {
- float a[32];
- for (int i = 1; i < 32; i++) {
- a[i] = (1.0 / (i * 3.0));
- }
- float S = 0;
- for (int j = 1; j < 32; j++) {
- S = S + a[j];
- }
- float MH = 0;
- MH = 31 / S;
- return MH;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement