Advertisement
Ahmet_Durmic

Studenti-struct

Mar 12th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. #include<iostream>
  2. #include<iostream>
  3. #include<string>
  4.  
  5.  
  6. using namespace std;
  7.  
  8.  
  9. struct student{
  10.  
  11. string ime;
  12. string prezime;
  13. double bodovi;
  14.  
  15. };
  16.  
  17. void ispis_studenata(student st[],int x){ //Pomocna funkcija koja ce nam sluziti za krajnji ispis
  18. cout<<"===================================\n";
  19. for(int i=0;i<x;i++){
  20. cout<<" "<<i+1<<". "<<st[i].ime<<" "<<st[i].prezime<<" "<<st[i].bodovi<<" [BODA]"<<endl; //ispis imena,prezimena, i vrijednosti bodova sa rotirane mem.lokacije
  21. }
  22. cout<<"===================================\n";
  23.  
  24. }
  25.  
  26. void zamjena(student *x,student *y){ //*x i *y su vrijednosti cijele strukture koje se nalaze na memorijskoj lokaciji
  27. student temp=*x;
  28. *x=*y;
  29. *y=temp;
  30. }
  31. student unesi_podatke(){
  32. student rez;
  33. cout<<"Unesite ime studenta: ";cin>>rez.ime;
  34. cout<<"Unesite prezime studenta: ";cin>>rez.prezime;
  35. cout<<"Unesite ostvarene bodove: ";cin>>rez.bodovi;
  36. cout<<endl;
  37. return rez;
  38. }
  39.  
  40. int main(){
  41.  
  42. int n;
  43. cout<<"==========================\n";
  44. cout<<"Unesite broj studenata: ";
  45. cin>>n;
  46. cout<<"==========================\n";
  47.  
  48. cout<<endl;
  49.  
  50. student s[n];
  51. for(int i=0;i<n;i++){
  52. cout<<"Unesite potrebne podatke o "<<i+1<<". "<<"studentu:\n";
  53. s[i]=unesi_podatke();
  54. }
  55.  
  56.  
  57. for(int i=0;i<n;i++){
  58. for(int j=0;j<n;j++)
  59. if(s[j].bodovi<s[j+1].bodovi){
  60.  
  61. zamjena(s+i,s+j);// Zamjena vrijednosti u odnosu na postavljeni uslov
  62.  
  63. }
  64. }
  65.  
  66. ispis_studenata(s,n); //Ispis studenata pomocu funkcije
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement