Advertisement
Ahmet_Durmic

Untitled

Apr 25th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. #include<iostream>
  2. #include<iostream>
  3. #include<string>
  4. #include<fstream>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. struct student{
  10. char ime[30];
  11. double bodovi;
  12. };
  13.  
  14. void ispis_studenata(student st[],int x){ //Pomocna funkcija koja ce nam sluziti za krajnji ispis
  15. cout<<"===================================\n";
  16. for(int i=0;i<x;i++){
  17. cout<<" "<<i+1<<". "<<st[i].ime<<" "<<" "<<st[i].bodovi<<" [BODA]"<<endl; //ispis imena,prezimena, i vrijednosti bodova sa rotirane mem.lokacije
  18. }
  19. cout<<"===================================\n";
  20.  
  21. }
  22.  
  23. void zamjena(student &x,student &y){ //*x i *y su vrijednosti cijele strukture koje se nalaze na memorijskoj lokaciji
  24. student temp=x;
  25. x=y;
  26. y=temp;
  27. }
  28. void sortiraj(student s[],int a){
  29. for(int i=0;i<a-1;i++){
  30. for(int j=0;j<a-1;j++)
  31. if(s[j].bodovi<s[j+1].bodovi){
  32. zamjena(s[j],s[j+1]);// Zamjena vrijednosti u odnosu na postavljeni uslov
  33. }
  34. }
  35.  
  36. }
  37. void unesi_podatke(student s[],int a){
  38. for(int i=0;i<a;i++){
  39. cout<<"Unesite potrebne podatke o "<<i+1<<". "<<"studentu:\n";
  40. cout<<"Unesite ime studenta: ";cin>>s[i].ime;
  41. cout<<"Unesite ostvarene bodove: ";cin>>s[i].bodovi;
  42. cout<<endl;
  43. }
  44. }
  45. void sacuvaj_trenutno_stanje(student s[], int n){
  46.  
  47. ofstream unosBrojaStudenata("broj_prijava1.dat", ios::out|ios::binary|ios::app);
  48. unosBrojaStudenata.write((char*)&n, sizeof(int));
  49. unosBrojaStudenata.close();
  50.  
  51. ofstream unosStudenata("studenti1.dat", ios::out|ios::binary|ios::app);
  52. for(int i(0); i<n; ++i){
  53. unosStudenata.write((char*)&s[i], sizeof(student));
  54. }
  55. unosStudenata.close();
  56. }
  57.  
  58. int main(){
  59.  
  60. ifstream brojPrijava("broj_prijava1.dat", ios::binary);
  61. student s[30];
  62. int n;
  63. brojPrijava.read((char*)(&n), sizeof(int));
  64. brojPrijava.close();
  65. ifstream citanje("studenti1.dat", ios::binary);
  66. for(int i=0; i<n; ++i){
  67. citanje.read((char*)&s[i], sizeof (student));
  68. }
  69. citanje.close();
  70.  
  71. cout<<"0)Unesi podatke\n1)Ipisi studente\n2)Sacuvaj i izadi\n";
  72. int izbor;cout<<"Unesite izbor: ";cin>>izbor;
  73. do{
  74. if(izbor==0){
  75. cout<<"==========================\n";
  76. cout<<"Unesite broj studenata: ";
  77. cin>>n;
  78. cout<<"==========================\n";
  79. cout<<endl;
  80. s[n];
  81. unesi_podatke(s,n);
  82. sacuvaj_trenutno_stanje(s,n);
  83. cout<<"Unesite izbor: ";cin>>izbor;
  84. }
  85. if(izbor==1){
  86. sortiraj(s,n);
  87. ispis_studenata(s,n);
  88. cout<<"Unesite izbor: ";cin>>izbor;
  89. }
  90.  
  91.  
  92. }while(izbor!=2);
  93. sacuvaj_trenutno_stanje(s,n);
  94.  
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement