Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<iostream>
- #include<string>
- using namespace std;
- struct student{
- string ime;
- string prezime;
- double bodovi;
- };
- void ispis_studenata(student st[],int x){ //Pomocna funkcija koja ce nam sluziti za krajnji ispis
- cout<<"===================================\n";
- for(int i=0;i<x;i++){
- cout<<" "<<i+1<<". "<<st[i].ime<<" "<<st[i].prezime<<" "<<st[i].bodovi<<" [BODA]"<<endl; //ispis imena,prezimena, i vrijednosti bodova sa rotirane mem.lokacije
- }
- cout<<"===================================\n";
- }
- void zamjena(student *x,student *y){ //*x i *y su vrijednosti cijele strukture koje se nalaze na memorijskoj lokaciji
- student temp=*x;
- *x=*y;
- *y=temp;
- }
- student unesi_podatke(){
- student rez;
- cout<<"Unesite ime studenta: ";cin>>rez.ime;
- cout<<"Unesite prezime studenta: ";cin>>rez.prezime;
- cout<<"Unesite ostvarene bodove: ";cin>>rez.bodovi;
- cout<<endl;
- return rez;
- }
- int main(){
- int n;
- cout<<"==========================\n";
- cout<<"Unesite broj studenata: ";
- cin>>n;
- cout<<"==========================\n";
- cout<<endl;
- student s[n];
- for(int i=0;i<n;i++){
- cout<<"Unesite potrebne podatke o "<<i+1<<". "<<"studentu:\n";
- s[i]=unesi_podatke();
- }
- for(int i=0;i<n;i++){
- for(int j=0;j<n;j++)
- if(s[j].bodovi<s[j+1].bodovi){
- zamjena(s+i,s+j);// Zamjena vrijednosti u odnosu na postavljeni uslov
- }
- }
- ispis_studenata(s,n); //Ispis studenata pomocu funkcije
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement