Advertisement
kanciastopantalones

skonczone

Nov 29th, 2011
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <string.h>
  3. #include <windows.h>
  4. using namespace std;
  5. struct profesja{
  6.        char nazwa[30];
  7.        float atrybut;
  8.        };
  9.        
  10. void zamiana(profesja &a, profesja &b)
  11. {
  12.     profesja temp=a;
  13.     a=b;
  14.     b=temp;
  15. }
  16.  
  17. void sortowanie(profesja tab[], int n)
  18. {
  19.     for(int j=n-1;j>0;j--)
  20.     {
  21.         for(int i=0;i<j;i++)
  22.         {
  23.             if(tab[i].atrybut<tab[i+1].atrybut) { zamiana(tab[i], tab[i+1]);}
  24.         }
  25.     }
  26. }  
  27.  
  28. int main()
  29. {
  30.     profesja tab[5];
  31.     for (int i=0;i<5;i++)
  32.     {
  33.         cout << "podaj nazwe " << i+1 << " klasy: ";
  34.         cin >> tab[i].nazwa;
  35.         cout << "podaj atrybut " << i+1 << " postaci: ";
  36.         cin >> tab[i].atrybut;
  37.     }
  38.     cout << endl;
  39.     for (int j=0;j<5;j++)
  40.     {
  41.         cout << j+1 << ". RASA: " << tab[j].nazwa << "\t" << "ATRYBUT: " << tab[j].atrybut << endl;
  42.        
  43.     }
  44.     cout << endl;
  45.     int a;
  46.     do
  47.     {
  48.         cout << "ilosc postaci do konfrontacji: ";
  49.         cin >> a;
  50.     }while(a>=5);
  51.    
  52.     cout << endl;
  53.     profesja tab2[5];
  54.     int x;
  55.     for(int i=0;i<a;i++)
  56.     {
  57.         cout << "podaj pozycje " << i+1 << " rasy: ";
  58.         cin >> x;
  59.         tab2[i]=tab[x-1];
  60.     }    
  61.    
  62.     sortowanie(tab2,a);
  63.     cout << endl;
  64.     for (int j=0;j<a;j++)
  65.     {
  66.         cout << j+1 << ". RASA: " << tab2[j].nazwa << "\t" << " ATRYBUT: " << tab2[j].atrybut << endl;
  67.        
  68.     }
  69.  
  70.    
  71.    
  72.            
  73.    
  74.             cin.ignore();
  75.             getchar();
  76.             return 0;
  77. }
  78.  
  79.  
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement