Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // cviko_smejk1.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- typedef struct {
- char Typ[100];
- int Rok;
- float GWH;
- } TVyroba;
- void Zobraz(TVyroba Seznam[], int pocet)
- {
- printf("hlavicka\n");
- for (int i = 0; i < pocet; i++)
- printf ("%s\t%d\t%f\n", Seznam[i].Typ, Seznam[i].Rok, Seznam[i].GWH);
- }
- void BubbleSortGWH(TVyroba *Data, int Count) {
- int i, j;
- for (i = 0; i < Count - 1; i++) //Vnější cyklus.
- {
- for (j = 0; j < Count - 1 - i; j++) //Vnitřní cyklus.
- {
- if (Data[j + 1].GWH < Data[j].GWH) //Porovnání položek.
- {
- TVyroba Temp = Data[j]; //Prohození položek.
- Data[j] = Data[j + 1];
- Data[j + 1] = Temp;
- }
- }
- }
- }
- void BubbleSortRok(TVyroba *Data, int Count) {
- int i, j;
- for (i = 0; i < Count - 1; i++) //Vnější cyklus.
- {
- for (j = 0; j < Count - 1 - i; j++) //Vnitřní cyklus.
- {
- if (Data[j + 1].Rok < Data[j].Rok) //Porovnání položek.
- {
- TVyroba Temp = Data[j]; //Prohození položek.
- Data[j] = Data[j + 1];
- Data[j + 1] = Temp;
- }
- }
- }
- }
- void BubbleSortTyp(TVyroba *Data, int Count) {
- int i, j;
- for (i = 0; i < Count - 1; i++) //Vnější cyklus.
- {
- for (j = 0; j < Count - 1 - i; j++) //Vnitřní cyklus.
- {
- if (Data[j + 1].Typ < Data[j].Typ) //Porovnání položek.
- {
- TVyroba Temp = Data[j]; //Prohození položek.
- Data[j] = Data[j + 1];
- Data[j + 1] = Temp;
- }
- }
- }
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- int pocet;
- const int Pocet = 12;
- TVyroba Seznam[Pocet] =
- {
- {"Parni\t\t", 2013, 44737.0},
- {"Vodni\t\t", 2013, 3761.7},
- {"Jaderna\t\t", 2013, 30745.3},
- {"Fotovoltaicka\t", 2013, 2070.2},
- {"Parni\t\t", 2012, 47261.0},
- {"Vodni\t\t", 2012, 2963.0},
- {"Jaderna\t\t", 2012, 30324.2},
- {"Fotovoltaicka\t", 2012, 2173.1},
- {"Parni\t\t", 2011, 49973.0},
- {"Vodni\t\t", 2011, 2835.0},
- {"Jaderna\t\t", 2011, 28282.6},
- {"Fotovoltaicka\t", 2011, 2118.0},
- };
- int Akce;
- while (true) {
- //Nabídka programu.
- do {
- printf("Vyberte operaci: (T)yp, (R)ok, (G)WH, Ty(p) + GWH, (K)onec\n");
- Akce = getchar();
- fflush(stdin);
- } while (Akce != 't' && Akce != 'r' && Akce != 'g' && Akce != 'k');
- if (Akce == 'k')
- break;
- if(Akce == 'g')
- {
- printf("Vybrana operace %c\n", Akce);
- BubbleSortGWH(Seznam, Pocet);
- Zobraz(Seznam, Pocet);
- }
- if(Akce == 'r')
- {
- printf("Vybrana operace %c\n", Akce);
- BubbleSortRok(Seznam, Pocet);
- Zobraz(Seznam, Pocet);
- }
- if(Akce == 't')
- {
- printf("Vybrana operace %c\n", Akce);
- BubbleSortTyp(Seznam, Pocet);
- Zobraz(Seznam, Pocet);
- }
- }
- printf("Stiskni ENTER\n");
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement