Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Matrikelnummer:
- //Name:
- //Vorname:
- // main.cpp
- // Beleg.cpp
- //
- // Created by Carl M¸ller on 15.12.17.
- // Copyright © 2017 Carl M¸ller. All rights reserved.
- //
- #include <iostream>
- #include <fstream> //f¸r Dateioperatoren
- #include <string>
- using namespace std;
- int main()
- {
- struct kennlinie
- {
- int liter; //Fˆrdermenge pro Minute
- int hoehe; //in m
- };
- struct pumpe
- {
- char name [20]; //Name der Pumpe
- kennlinie pkt [5]; //Kennlinie aus 5 Punkten
- float preis; //In Euro
- };
- struct brunnen
- {
- float foerderhoehe; //in m
- float wasserstandshoehe; //in m
- float brunnendurchmesser;
- };
- //Konstanten der main Funktion
- const int pumpenanzahl = 9;
- const int brunnenanzahl = 10;
- int i,j,k;
- pumpe Pumpen [pumpenanzahl]; //Variable des Types pumpe
- //Einlesen Datei pumpen.txt in Array
- ifstream pumpein ("pumpen.txt"); //Quelle
- if (!pumpein)
- cout << "÷ffnen von pumpen.txt missgl¸ckt!" << '\n'; //Test ob ˆffnen geklappt
- else //wenn ja, starte einlesen
- {
- for (i = 0 ; i < pumpenanzahl ; i++)
- {
- pumpein >> Pumpen[i].name;
- for (k = 0 ; k < 5 ; k++) //f¸r Pumpe i einmal pkt liter und einmal pkt hoehe
- {
- pumpein >> Pumpen[i].pkt[k].liter; //Variablenzugriff ¸ber struct mit Punkt dazwischen
- pumpein >> Pumpen[i].pkt[k].hoehe;
- }
- pumpein >> Pumpen[i].preis; // in letzte Spalte zu jeder Pumpe der Preis
- }
- pumpein.close(); //Datei schlieflen
- }
- brunnen Brun [brunnenanzahl];
- //Einlesen Datei brunnen.txt in Array
- ifstream brunnenin ("brunnen.txt");
- if (!brunnenin)
- cout << "÷ffnen von brunnen.txt missgl¸ckt!" << '\n'; //Test ob ˆffnen geklappt
- else
- {
- for ( j = 0 ; j < brunnenanzahl ; j++)
- {
- brunnenin >> Brun[j].foerderhoehe;
- brunnenin >> Brun[j].wasserstandshoehe;
- brunnenin >> Brun[j].brunnendurchmesser;
- }
- brunnenin.close();
- }
- //////////////////////////Berechnungen////////////////////////////////////////////////
- //Volume berechnen
- float V [brunnenanzahl]; //Feld Volumen
- float pi = 3.1415; // Pi als Konstante
- for ( j = 0 ; j < brunnenanzahl ; j++)
- {
- V[j] = pi * (Brun[j].brunnendurchmesser*Brun[j].brunnendurchmesser) / 4.0 * Brun[j].wasserstandshoehe * 1000;
- }
- //Zeit berechnen
- float zeit[pumpenanzahl][brunnenanzahl]; //Zeit die Pumpe[i] braucht um Brunnen[j] leer zu pumpen
- for ( i = 0 ; i < pumpenanzahl ; i++) //Pumpen durchgehen
- {
- for ( j = 0 ; j < brunnenanzahl ; j++) //Brunnen durchgehen
- {
- k = 0;
- while (Brun[j].foerderhoehe > Pumpen[i].pkt[k].hoehe)
- {
- k++;
- }
- zeit[i][j] = V[j]/Pumpen[i].pkt[k].liter;
- }
- }
- /////Preis Leistungs Verh‰ltnis berechnen//////////////////////////////////////////////////
- /////Preis Zeit Index/////////
- double plv[pumpenanzahl][brunnenanzahl] ; //Preis Leistungs Verh‰ltnis
- for ( j = 0 ; j < brunnenanzahl ; j++)
- {
- for ( i = 0 ; i < pumpenanzahl ; i++)
- {
- if (Brun[j].foerderhoehe <= Pumpen[i].pkt[4].hoehe)
- {
- plv[i][j] = zeit[i][j] * Pumpen[i].preis;
- }
- }
- }
- ///////////Bestes Preis-Leistungs_verh‰ltnis berechnen////////////
- double mini[brunnenanzahl]; //bestes plv
- double nplv[pumpenanzahl][brunnenanzahl]; //plv in %
- for ( j = 0 ; j < brunnenanzahl ; j++)
- {
- float tmp_min = plv[3][j];
- int i_min = 0;
- for ( i = 0 ; i < pumpenanzahl ; i++)
- {
- if (Brun[j].foerderhoehe <= Pumpen[i].pkt[4].hoehe) //Filtern der mˆglichen Pumpen
- {
- if (plv[i][j] < tmp_min)
- {
- tmp_min = plv[i][j];
- i_min = i;
- }
- }
- }
- mini[j] = plv[i_min][j];
- }
- ////umwandeln in Preis Leistungs Verh‰ltnis in %///////
- for ( j = 0 ; j < brunnenanzahl ; j++)
- {
- for ( i = 0 ; i < pumpenanzahl ; i++)
- {
- if (plv[i][j] > mini[j])
- {
- nplv[i][j] = (plv[i][j] * 100) / mini[j];
- }
- }
- }
- ////////////////////Ausgaben////////////////////////////////
- //Hier # Zeile...Zeit
- cout.setf(ios::right);
- cout.fill('#') ;
- cout.width(45);
- cout << "Die Matrix - Zeit" ;
- cout.internal ;
- cout.fill('#');
- cout.width(30);
- cout << '\n' << '\n';
- ///////Hier ausgabe Matrix - Zeit///////
- /////Tabellenkopf Zeit
- cout.unsetf(ios::left);
- cout.setf(ios::right);
- cout.width(16);
- cout.fill(' ');
- cout << " ";
- cout.width(3);
- cout << " |";
- for ( i = 0 ; i < pumpenanzahl ; i++)
- {
- cout.unsetf(ios::left);
- cout.setf(ios::right);
- cout.width(16);
- cout.fill(' ');
- cout << Pumpen[i].name;
- cout.width(3);
- cout << " |";
- }
- /////erste gestrichelte Zeile
- cout << '\n';
- cout.unsetf(ios::left);
- cout.setf(ios::right);
- cout.width(16);
- cout.fill('-');
- cout << "-";
- cout.width(3);
- cout << "|";
- for ( i = 0 ; i < pumpenanzahl ; i++)
- {
- cout.unsetf(ios::left);
- cout.setf(ios::right);
- cout.width(16);
- cout.fill('-');
- cout << "-";
- cout.width(3);
- cout << " |";
- }
- ////Ausgabe der Brunnen mit Volumen in Matrix Zeit
- cout << "\n";
- for (j = 0 ; j < brunnenanzahl; j++)
- {
- cout.fill(' ');
- cout.unsetf(ios::right);
- cout.setf(ios::left);
- cout.width(8);
- cout << "Brunnen";
- cout.fill(' ');
- cout.unsetf(ios::left);
- cout.width(8);
- cout << V[j] << "l";
- cout.fill(' ');
- cout.width(2);
- cout << '|';
- /////Ausgabe der Zeiten in der Tabelle/////
- for( i = 0 ; i < pumpenanzahl ; i++)
- {
- cout.unsetf(ios::left);
- cout.setf(ios::dec);
- cout.unsetf(ios::scientific);
- int mi[pumpenanzahl][brunnenanzahl], hour[pumpenanzahl][brunnenanzahl], day[pumpenanzahl][brunnenanzahl]; //10 freie Zeichen
- if (Brun[j].foerderhoehe <= Pumpen[i].pkt[4].hoehe)
- {
- if(zeit[i][j]>=60)
- {
- if(zeit[i][j]>=1440)
- {
- day[i][j]=zeit[i][j]/1440;
- hour[i][j]=(zeit[i][j]/60)-(day[i][j]*24);
- mi[i][j]=zeit[i][j]-(hour[i][j]*60)-(day[i][j]*1440);
- cout.fill(' ');
- cout.unsetf(ios::left);
- cout.width(8);
- cout << day[i][j]<<"T:";
- cout.fill(' ');
- cout.width(2);
- cout << hour[i][j]<<"H:";
- cout.fill(' ');
- cout.width(2);
- cout << mi[i][j]<<"M";
- }
- else
- {
- hour[i][j]=zeit[i][j]/60;
- mi[i][j]=zeit[i][j]-(hour[i][j]*60);
- cout.fill(' ');
- cout.unsetf(ios::left);
- cout.width(12);
- cout<<hour[i][j]<<"H:";
- cout.fill(' ');
- cout.width(2);
- cout <<mi[i][j]<<"M";
- }
- }
- else
- {
- mi[i][j]=zeit[i][j];
- cout.fill(' ');
- cout.unsetf(ios::left);
- cout.width(16);
- cout<<mi[i][j]<<"M";
- }
- }
- else {
- cout.fill(' ');
- cout.unsetf(ios::left);
- cout.width(17);
- cout << "n.e.";
- }
- cout.fill(' ');
- cout.width(2);
- cout << "|";
- }
- cout<<"\n";
- }
- cout << '\n' ;
- ///////Ausgabe der Matrix Pris Leistung//////////////////////
- //Zwischenzeile mit #'s
- cout.setf(ios::right);
- cout.fill('#') ;
- cout.width(45);
- cout << "#" ;
- cout.internal ;
- cout.fill('#');
- cout.width(30);
- cout << '\n' << '\n';
- //Hier # Zeile mit Tabellen¸berschrift
- cout << '\n' ;
- cout.setf(ios::right);
- cout.fill('#') ;
- cout.width(45);
- cout << "Die Matrix - Preis-Leistung" ;
- cout.internal ;
- cout.fill('#');
- cout.width(30);
- cout << '\n' << '\n';
- /////Tabellenkopf Preis-Leistung
- cout.unsetf(ios::left);
- cout.setf(ios::right);
- cout.width(16);
- cout.fill(' ');
- cout << " ";
- cout.width(3);
- cout << " |";
- for ( i = 0 ; i < pumpenanzahl ; i++)
- {
- cout.unsetf(ios::left);
- cout.setf(ios::right);
- cout.width(16);
- cout.fill(' ');
- cout << Pumpen[i].name;
- cout.width(3);
- cout << " |";
- }
- /////erste gestrichelte Zeile in Matrix Preis-Leistung
- cout << '\n';
- cout.unsetf(ios::left);
- cout.setf(ios::right);
- cout.width(16);
- cout.fill('-');
- cout << "-";
- cout.width(3);
- cout << "|";
- for ( i = 0 ; i < pumpenanzahl ; i++)
- {
- cout.unsetf(ios::left);
- cout.setf(ios::right);
- cout.width(16);
- cout.fill('-');
- cout << "-";
- cout.width(3);
- cout << " |";
- }
- ////Ausgabe der Brunnen mit Volumen
- cout << "\n";
- for (j = 0 ; j < brunnenanzahl; j++)
- {
- cout.fill(' ');
- cout.unsetf(ios::right);
- cout.setf(ios::left);
- cout.width(8);
- cout << "Brunnen";
- cout.fill(' ');
- cout.unsetf(ios::left);
- cout.width(8);
- cout << V[j] << "l";
- cout.fill(' ');
- cout.width(2);
- cout << '|';
- /////Ausgabe des Preis-Leistungs Verh‰ltnisses in der Tabelle/////
- for( i = 0 ; i < pumpenanzahl ; i++)
- {
- cout.fill(' ');
- cout.unsetf(ios::left);
- cout.unsetf(ios::scientific);
- cout.width(16);
- if (Brun[j].foerderhoehe <= Pumpen[i].pkt[4].hoehe)
- {
- if (plv[i][j] > mini[j])
- {
- cout << nplv[i][j];
- cout.fill(' ');
- cout.unsetf(ios::left);
- cout.width(1);
- cout << "%";
- }
- if (plv[i][j] == mini[j])
- {
- cout << Pumpen[i].preis;
- cout.fill(' ');
- cout.unsetf(ios::left);
- cout.width(1);
- cout << "E";
- }
- }
- else
- {
- cout << "0";
- cout.fill(' ');
- cout.unsetf(ios::left);
- cout.width(1);
- cout << " ";
- }
- ////////
- cout.fill(' ');
- cout.width(2);
- cout << "|";
- }
- cout<<"\n";
- }
- ////Letzte Zeile mit #'s
- cout << '\n';
- cout.setf(ios::right);
- cout.fill('#') ;
- cout.width(45);
- cout << "#" ;
- cout.internal ;
- cout.fill('#');
- cout.width(30);
- cout << '\n' << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment