Guest User

Marius

a guest
Jan 10th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.24 KB | None | 0 0
  1.  
  2. //Matrikelnummer:
  3. //Name:
  4. //Vorname:
  5. //  main.cpp
  6. //  Beleg.cpp
  7. //
  8. //  Created by Carl M¸ller on 15.12.17.
  9. //  Copyright © 2017 Carl M¸ller. All rights reserved.
  10. //
  11.  
  12. #include <iostream>
  13. #include <fstream>      //f¸r Dateioperatoren
  14. #include <string>
  15. using namespace std;
  16.  
  17. int main()
  18. {
  19.     struct kennlinie
  20.     {
  21.         int liter; //Fˆrdermenge pro Minute
  22.         int hoehe; //in m
  23.     };
  24.  
  25.     struct pumpe
  26.     {
  27.         char name [20];         //Name der Pumpe
  28.         kennlinie pkt [5];      //Kennlinie aus 5 Punkten
  29.         float preis;            //In Euro
  30.     };
  31.  
  32.     struct brunnen
  33.     {
  34.         float foerderhoehe;          //in m
  35.         float wasserstandshoehe;     //in m
  36.         float brunnendurchmesser;
  37.     };
  38.  
  39. //Konstanten der main Funktion
  40.     const int pumpenanzahl = 9;
  41.     const int brunnenanzahl = 10;
  42.     int i,j,k;
  43.  
  44.     pumpe Pumpen [pumpenanzahl];    //Variable des Types pumpe
  45.  
  46.   //Einlesen Datei pumpen.txt in Array
  47.     ifstream pumpein ("pumpen.txt");  //Quelle
  48.         if (!pumpein)
  49.             cout << "÷ffnen von pumpen.txt missgl¸ckt!" << '\n';    //Test ob ˆffnen geklappt
  50.         else                                                        //wenn ja, starte einlesen
  51.             {
  52.                 for (i = 0 ; i < pumpenanzahl ; i++)
  53.                 {
  54.                     pumpein >> Pumpen[i].name;
  55.  
  56.                     for (k = 0 ; k < 5 ; k++)       //f¸r Pumpe i einmal pkt liter und einmal pkt hoehe
  57.                      {
  58.                       pumpein >> Pumpen[i].pkt[k].liter;        //Variablenzugriff ¸ber struct mit Punkt dazwischen
  59.                       pumpein >> Pumpen[i].pkt[k].hoehe;
  60.                      }
  61.                      pumpein >> Pumpen[i].preis;       // in letzte Spalte zu jeder Pumpe der Preis
  62.                 }
  63.                 pumpein.close();        //Datei schlieflen
  64.             }
  65.  
  66.  
  67.    brunnen Brun [brunnenanzahl];
  68.     //Einlesen Datei brunnen.txt in Array
  69.     ifstream brunnenin ("brunnen.txt");
  70.         if (!brunnenin)
  71.             cout << "÷ffnen von brunnen.txt missgl¸ckt!" << '\n';    //Test ob ˆffnen geklappt
  72.         else
  73.             {
  74.                 for ( j = 0 ; j < brunnenanzahl ; j++)
  75.                  {
  76.                      brunnenin >> Brun[j].foerderhoehe;
  77.                      brunnenin >> Brun[j].wasserstandshoehe;
  78.                      brunnenin >> Brun[j].brunnendurchmesser;
  79.                  }
  80.               brunnenin.close();
  81.             }
  82.  
  83.  
  84.  
  85. //////////////////////////Berechnungen////////////////////////////////////////////////
  86.  
  87.  
  88. //Volume berechnen
  89.   float V [brunnenanzahl];      //Feld Volumen
  90.   float pi = 3.1415;    // Pi als Konstante
  91.  
  92.   for ( j = 0 ; j < brunnenanzahl ; j++)
  93.   {
  94.       V[j] = pi * (Brun[j].brunnendurchmesser*Brun[j].brunnendurchmesser) / 4.0 * Brun[j].wasserstandshoehe * 1000;
  95.   }
  96.  
  97.  
  98.  
  99. //Zeit berechnen
  100. float zeit[pumpenanzahl][brunnenanzahl];    //Zeit die Pumpe[i] braucht um Brunnen[j] leer zu pumpen
  101.  
  102.     for ( i = 0 ; i < pumpenanzahl ; i++)   //Pumpen durchgehen
  103.     {
  104.         for ( j = 0 ; j < brunnenanzahl ; j++)  //Brunnen durchgehen
  105.         {
  106.             k = 0;
  107.             while (Brun[j].foerderhoehe > Pumpen[i].pkt[k].hoehe)
  108.             {
  109.                 k++;
  110.             }
  111.             zeit[i][j] = V[j]/Pumpen[i].pkt[k].liter;
  112.         }
  113.     }
  114.  
  115.  
  116.  
  117. /////Preis Leistungs Verh‰ltnis berechnen//////////////////////////////////////////////////
  118.  
  119.  
  120.      /////Preis Zeit Index/////////
  121.         double plv[pumpenanzahl][brunnenanzahl] ; //Preis Leistungs Verh‰ltnis
  122.         for ( j = 0 ; j < brunnenanzahl ; j++)
  123.         {
  124.             for ( i = 0 ; i < pumpenanzahl ; i++)
  125.             {
  126.                 if (Brun[j].foerderhoehe <= Pumpen[i].pkt[4].hoehe)
  127.                 {
  128.                     plv[i][j] = zeit[i][j] * Pumpen[i].preis;
  129.                 }
  130.  
  131.             }
  132.         }
  133.  
  134. ///////////Bestes Preis-Leistungs_verh‰ltnis berechnen////////////
  135.  
  136.     double mini[brunnenanzahl];                 //bestes plv
  137.     double nplv[pumpenanzahl][brunnenanzahl];       //plv in %
  138.  
  139.     for ( j = 0 ; j < brunnenanzahl ; j++)
  140.     {
  141.         float tmp_min = plv[3][j];
  142.         int i_min = 0;
  143.  
  144.         for ( i = 0 ; i < pumpenanzahl ; i++)
  145.         {
  146.            if (Brun[j].foerderhoehe <= Pumpen[i].pkt[4].hoehe)      //Filtern der mˆglichen Pumpen
  147.            {
  148.             if (plv[i][j] < tmp_min)
  149.             {
  150.                 tmp_min = plv[i][j];
  151.                 i_min = i;
  152.             }
  153.            }
  154.         }
  155.         mini[j] = plv[i_min][j];
  156.     }
  157.  
  158.  
  159.  
  160. ////umwandeln in Preis Leistungs Verh‰ltnis in %///////
  161.     for ( j = 0 ; j < brunnenanzahl ; j++)
  162.     {
  163.         for ( i = 0 ; i < pumpenanzahl ; i++)
  164.         {
  165.                 if (plv[i][j] > mini[j])
  166.                 {
  167.                     nplv[i][j] = (plv[i][j] * 100) / mini[j];
  168.                 }
  169.         }
  170.     }
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177. ////////////////////Ausgaben////////////////////////////////
  178.  
  179.  
  180. //Hier # Zeile...Zeit
  181.  
  182.    cout.setf(ios::right);
  183.    cout.fill('#') ;
  184.    cout.width(45);
  185.    cout << "Die Matrix - Zeit" ;
  186.    cout.internal ;
  187.    cout.fill('#');
  188.    cout.width(30);
  189.    cout << '\n' << '\n';
  190.  
  191.  
  192. ///////Hier ausgabe Matrix - Zeit///////
  193.  
  194. /////Tabellenkopf Zeit
  195.  
  196.             cout.unsetf(ios::left);
  197.             cout.setf(ios::right);
  198.             cout.width(16);
  199.             cout.fill(' ');
  200.             cout << " ";
  201.             cout.width(3);
  202.             cout << " |";
  203.  
  204.     for ( i = 0 ; i < pumpenanzahl ; i++)
  205.         {
  206.             cout.unsetf(ios::left);
  207.             cout.setf(ios::right);
  208.             cout.width(16);
  209.             cout.fill(' ');
  210.             cout << Pumpen[i].name;
  211.             cout.width(3);
  212.             cout << " |";
  213.         }
  214.  
  215. /////erste gestrichelte Zeile
  216.             cout << '\n';
  217.             cout.unsetf(ios::left);
  218.             cout.setf(ios::right);
  219.             cout.width(16);
  220.             cout.fill('-');
  221.             cout << "-";
  222.             cout.width(3);
  223.             cout << "|";
  224.     for ( i = 0 ; i < pumpenanzahl ; i++)
  225.         {
  226.             cout.unsetf(ios::left);
  227.             cout.setf(ios::right);
  228.             cout.width(16);
  229.             cout.fill('-');
  230.             cout << "-";
  231.             cout.width(3);
  232.             cout << " |";
  233.         }
  234.  
  235.  
  236. ////Ausgabe der Brunnen mit Volumen in Matrix Zeit
  237. cout << "\n";
  238.  
  239.  for (j = 0 ; j < brunnenanzahl; j++)
  240.      {
  241.      cout.fill(' ');
  242.      cout.unsetf(ios::right);
  243.      cout.setf(ios::left);
  244.      cout.width(8);
  245.      cout << "Brunnen";
  246.      cout.fill(' ');
  247.      cout.unsetf(ios::left);
  248.      cout.width(8);
  249.      cout << V[j] << "l";
  250.      cout.fill(' ');
  251.      cout.width(2);
  252.      cout << '|';
  253.  
  254.  
  255. /////Ausgabe der Zeiten in der Tabelle/////
  256.      for( i = 0 ; i < pumpenanzahl ; i++)
  257.          {
  258.         cout.unsetf(ios::left);
  259.         cout.setf(ios::dec);
  260.         cout.unsetf(ios::scientific);
  261. int mi[pumpenanzahl][brunnenanzahl], hour[pumpenanzahl][brunnenanzahl], day[pumpenanzahl][brunnenanzahl];  //10 freie Zeichen
  262.       if (Brun[j].foerderhoehe <= Pumpen[i].pkt[4].hoehe)
  263.         {
  264.             if(zeit[i][j]>=60)
  265.             {
  266.                 if(zeit[i][j]>=1440)
  267.                 {
  268.                     day[i][j]=zeit[i][j]/1440;
  269.                     hour[i][j]=(zeit[i][j]/60)-(day[i][j]*24);
  270.                     mi[i][j]=zeit[i][j]-(hour[i][j]*60)-(day[i][j]*1440);
  271.                         cout.fill(' ');
  272.                         cout.unsetf(ios::left);
  273.                         cout.width(8);
  274.                         cout << day[i][j]<<"T:";
  275.                         cout.fill(' ');
  276.                         cout.width(2);
  277.                         cout << hour[i][j]<<"H:";
  278.                         cout.fill(' ');
  279.                         cout.width(2);
  280.                         cout << mi[i][j]<<"M";
  281.                 }
  282.                 else
  283.                     {
  284.                         hour[i][j]=zeit[i][j]/60;
  285.                         mi[i][j]=zeit[i][j]-(hour[i][j]*60);
  286.                         cout.fill(' ');
  287.                         cout.unsetf(ios::left);
  288.                         cout.width(12);
  289.                         cout<<hour[i][j]<<"H:";
  290.                         cout.fill(' ');
  291.                         cout.width(2);
  292.                         cout <<mi[i][j]<<"M";
  293.                     }
  294.         }
  295.                 else
  296.                     {
  297.                         mi[i][j]=zeit[i][j];
  298.                         cout.fill(' ');
  299.                         cout.unsetf(ios::left);
  300.                         cout.width(16);
  301.                         cout<<mi[i][j]<<"M";
  302.                     }
  303.         }
  304.         else {
  305.                 cout.fill(' ');
  306.                 cout.unsetf(ios::left);
  307.                 cout.width(17);
  308.                 cout << "n.e.";
  309.              }
  310.  
  311.         cout.fill(' ');
  312.         cout.width(2);
  313.         cout << "|";
  314.          }
  315.        cout<<"\n";
  316.      }
  317.    cout << '\n' ;
  318.  
  319.  
  320.  
  321.  
  322. ///////Ausgabe der Matrix Pris Leistung//////////////////////
  323.  
  324. //Zwischenzeile mit #'s
  325.     cout.setf(ios::right);
  326.     cout.fill('#') ;
  327.     cout.width(45);
  328.     cout << "#" ;
  329.     cout.internal ;
  330.     cout.fill('#');
  331.     cout.width(30);
  332.     cout << '\n' << '\n';
  333.  
  334.  
  335. //Hier # Zeile mit Tabellen¸berschrift
  336.  
  337.    cout << '\n' ;
  338.    cout.setf(ios::right);
  339.    cout.fill('#') ;
  340.    cout.width(45);
  341.    cout << "Die Matrix - Preis-Leistung" ;
  342.    cout.internal ;
  343.    cout.fill('#');
  344.    cout.width(30);
  345.    cout << '\n' << '\n';
  346.  
  347.  
  348.  
  349. /////Tabellenkopf Preis-Leistung
  350.  
  351.             cout.unsetf(ios::left);
  352.             cout.setf(ios::right);
  353.             cout.width(16);
  354.             cout.fill(' ');
  355.             cout << " ";
  356.             cout.width(3);
  357.             cout << " |";
  358.  
  359.     for ( i = 0 ; i < pumpenanzahl ; i++)
  360.         {
  361.             cout.unsetf(ios::left);
  362.             cout.setf(ios::right);
  363.             cout.width(16);
  364.             cout.fill(' ');
  365.             cout << Pumpen[i].name;
  366.             cout.width(3);
  367.             cout << " |";
  368.         }
  369.  
  370.  
  371. /////erste gestrichelte Zeile in Matrix Preis-Leistung
  372.             cout << '\n';
  373.             cout.unsetf(ios::left);
  374.             cout.setf(ios::right);
  375.             cout.width(16);
  376.             cout.fill('-');
  377.             cout << "-";
  378.             cout.width(3);
  379.             cout << "|";
  380.     for ( i = 0 ; i < pumpenanzahl ; i++)
  381.         {
  382.             cout.unsetf(ios::left);
  383.             cout.setf(ios::right);
  384.             cout.width(16);
  385.             cout.fill('-');
  386.             cout << "-";
  387.             cout.width(3);
  388.             cout << " |";
  389.         }
  390.  
  391.  
  392. ////Ausgabe der Brunnen mit Volumen
  393.  
  394.     cout << "\n";
  395.  
  396.     for (j = 0 ; j < brunnenanzahl; j++)
  397.         {
  398.             cout.fill(' ');
  399.             cout.unsetf(ios::right);
  400.             cout.setf(ios::left);
  401.             cout.width(8);
  402.             cout << "Brunnen";
  403.             cout.fill(' ');
  404.             cout.unsetf(ios::left);
  405.             cout.width(8);
  406.             cout << V[j] << "l";
  407.             cout.fill(' ');
  408.             cout.width(2);
  409.             cout << '|';
  410.  
  411.  
  412. /////Ausgabe des Preis-Leistungs Verh‰ltnisses in der Tabelle/////
  413.  
  414.      for( i = 0 ; i < pumpenanzahl ; i++)
  415.          {
  416.             cout.fill(' ');
  417.             cout.unsetf(ios::left);
  418.             cout.unsetf(ios::scientific);
  419.             cout.width(16);
  420.  
  421.     if (Brun[j].foerderhoehe <= Pumpen[i].pkt[4].hoehe)
  422.     {
  423.         if (plv[i][j] > mini[j])
  424.         {
  425.             cout << nplv[i][j];
  426.             cout.fill(' ');
  427.             cout.unsetf(ios::left);
  428.             cout.width(1);
  429.             cout << "%";
  430.         }
  431.  
  432.         if (plv[i][j] == mini[j])
  433.             {
  434.                 cout << Pumpen[i].preis;
  435.                 cout.fill(' ');
  436.                 cout.unsetf(ios::left);
  437.                 cout.width(1);
  438.                 cout << "E";
  439.             }
  440.     }
  441.     else
  442.     {
  443.         cout << "0";
  444.         cout.fill(' ');
  445.         cout.unsetf(ios::left);
  446.         cout.width(1);
  447.         cout << " ";
  448.     }
  449.  
  450. ////////
  451.  
  452.             cout.fill(' ');
  453.             cout.width(2);
  454.             cout << "|";
  455.          }
  456.         cout<<"\n";
  457.     }
  458.  
  459. ////Letzte Zeile mit #'s
  460.  
  461.     cout << '\n';
  462.     cout.setf(ios::right);
  463.     cout.fill('#') ;
  464.     cout.width(45);
  465.     cout << "#" ;
  466.     cout.internal ;
  467.     cout.fill('#');
  468.     cout.width(30);
  469.     cout << '\n' << '\n';
  470.  
  471.  
  472. return 0;
  473. }
Advertisement
Add Comment
Please, Sign In to add comment