Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.84 KB | None | 0 0
  1. // cviko_smejk1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. typedef struct {
  6.     char Typ[100];
  7.     int Rok;
  8.     float GWH;
  9. } TVyroba;
  10.  
  11. void Zobraz(TVyroba Seznam[], int pocet)
  12. {
  13.     printf("hlavicka\n");
  14.     for (int i = 0; i < pocet; i++)
  15.         printf ("%s\t%d\t%f\n", Seznam[i].Typ, Seznam[i].Rok, Seznam[i].GWH);
  16. }
  17.  
  18.     void BubbleSortGWH(TVyroba *Data, int Count) {
  19.         int i, j;
  20.         for (i = 0; i < Count - 1; i++) //Vnější cyklus.
  21.         {
  22.             for (j = 0; j < Count - 1 - i; j++) //Vnitřní cyklus.
  23.             {
  24.                 if (Data[j + 1].GWH < Data[j].GWH) //Porovnání položek.
  25.                 {
  26.                     TVyroba Temp = Data[j]; //Prohození položek.
  27.                     Data[j] = Data[j + 1];
  28.                     Data[j + 1] = Temp;
  29.                 }
  30.             }
  31.         }
  32.     }
  33.  
  34.         void BubbleSortRok(TVyroba *Data, int Count) {
  35.         int i, j;
  36.         for (i = 0; i < Count - 1; i++) //Vnější cyklus.
  37.         {
  38.             for (j = 0; j < Count - 1 - i; j++) //Vnitřní cyklus.
  39.             {
  40.                 if (Data[j + 1].Rok < Data[j].Rok) //Porovnání položek.
  41.                 {
  42.                     TVyroba Temp = Data[j]; //Prohození položek.
  43.                     Data[j] = Data[j + 1];
  44.                     Data[j + 1] = Temp;
  45.                 }
  46.             }
  47.         }
  48.     }
  49.  
  50.         void BubbleSortTyp(TVyroba *Data, int Count) {
  51.         int i, j;
  52.         for (i = 0; i < Count - 1; i++) //Vnější cyklus.
  53.         {
  54.             for (j = 0; j < Count - 1 - i; j++) //Vnitřní cyklus.
  55.             {
  56.                 if (Data[j + 1].Typ < Data[j].Typ) //Porovnání položek.
  57.                 {
  58.                     TVyroba Temp = Data[j]; //Prohození položek.
  59.                     Data[j] = Data[j + 1];
  60.                     Data[j + 1] = Temp;
  61.                 }
  62.             }
  63.         }
  64.     }
  65.  
  66.    
  67. int _tmain(int argc, _TCHAR* argv[])
  68. {
  69.     int pocet;
  70.     const int Pocet = 12;
  71.         TVyroba Seznam[Pocet] =
  72.     {
  73.         {"Parni\t\t", 2013, 44737.0},
  74.         {"Vodni\t\t", 2013, 3761.7},
  75.         {"Jaderna\t\t", 2013, 30745.3},
  76.         {"Fotovoltaicka\t", 2013, 2070.2},
  77.         {"Parni\t\t", 2012, 47261.0},
  78.         {"Vodni\t\t", 2012, 2963.0},
  79.         {"Jaderna\t\t", 2012, 30324.2},
  80.         {"Fotovoltaicka\t", 2012, 2173.1},
  81.         {"Parni\t\t", 2011, 49973.0},
  82.         {"Vodni\t\t", 2011, 2835.0},
  83.         {"Jaderna\t\t", 2011, 28282.6},
  84.         {"Fotovoltaicka\t", 2011, 2118.0},
  85.  
  86.     };
  87.  
  88. int Akce;
  89.     while (true) {
  90.         //Nabídka programu.
  91.         do {
  92.             printf("Vyberte operaci: (T)yp, (R)ok, (G)WH, Ty(p) + GWH, (K)onec\n");
  93.             Akce = getchar();
  94.             fflush(stdin);
  95.         } while (Akce != 't' && Akce != 'r' && Akce != 'g' && Akce != 'k');
  96.  
  97.         if (Akce == 'k')
  98.    
  99.             break;
  100.        
  101.  
  102.  
  103.  
  104.  
  105.         if(Akce == 'g')
  106.         {
  107.             printf("Vybrana operace %c\n", Akce);
  108.        
  109.         BubbleSortGWH(Seznam, Pocet);
  110.         Zobraz(Seznam, Pocet);
  111.         }
  112.  
  113.                 if(Akce == 'r')
  114.         {
  115.             printf("Vybrana operace %c\n", Akce);
  116.        
  117.         BubbleSortRok(Seznam, Pocet);
  118.         Zobraz(Seznam, Pocet);
  119.         }
  120.  
  121.  
  122.  
  123.  
  124.         if(Akce == 't')
  125.         {
  126.             printf("Vybrana operace %c\n", Akce);
  127.        
  128.         BubbleSortTyp(Seznam, Pocet);
  129.         Zobraz(Seznam, Pocet);
  130.         }
  131.  
  132.     }
  133.  
  134.    
  135.  
  136.  
  137.  
  138.  
  139.    
  140. printf("Stiskni ENTER\n");
  141. getchar();
  142. return 0;
  143. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement