Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- #include <windows.h>
- using namespace std;
- struct profesja{
- char nazwa[30];
- float atrybut;
- };
- void zamiana(profesja &a, profesja &b)
- {
- profesja temp=a;
- a=b;
- b=temp;
- }
- void sortowanie(profesja tab[], int n)
- {
- for(int j=n-1;j>0;j--)
- {
- for(int i=0;i<j;i++)
- {
- if(tab[i].atrybut<tab[i+1].atrybut) { zamiana(tab[i], tab[i+1]);}
- }
- }
- }
- int main()
- {
- profesja tab[5];
- for (int i=0;i<5;i++)
- {
- cout << "podaj nazwe " << i+1 << " klasy: ";
- cin >> tab[i].nazwa;
- cout << "podaj atrybut " << i+1 << " postaci: ";
- cin >> tab[i].atrybut;
- }
- cout << endl;
- for (int j=0;j<5;j++)
- {
- cout << j+1 << ". RASA: " << tab[j].nazwa << "\t" << "ATRYBUT: " << tab[j].atrybut << endl;
- }
- cout << endl;
- int a;
- do
- {
- cout << "ilosc postaci do konfrontacji: ";
- cin >> a;
- }while(a>=5);
- cout << endl;
- profesja tab2[5];
- int x;
- for(int i=0;i<a;i++)
- {
- cout << "podaj pozycje " << i+1 << " rasy: ";
- cin >> x;
- tab2[i]=tab[x-1];
- }
- sortowanie(tab2,a);
- cout << endl;
- for (int j=0;j<a;j++)
- {
- cout << j+1 << ". RASA: " << tab2[j].nazwa << "\t" << " ATRYBUT: " << tab2[j].atrybut << endl;
- }
- cin.ignore();
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement