Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #include <time.h>
- using namespace std;
- struct student
- {
- int index;
- float ocena;
- };
- int flagapolska(student studenci[],int n)
- {
- int p=0, k=n-1, ostatniadobra=-1;
- while(p<k)
- {
- while(p<n-1 && studenci[p].ocena>=3) p++;
- while(k>=0 && studenci[k].ocena<3) k--;
- if(p<k)
- {
- swap(studenci[p],studenci[k]);
- }
- // p++;
- // k--;
- if(studenci[p].ocena > 3)ostatniadobra=p;
- else ostatniadobra=p-1;
- }
- return ostatniadobra;
- }
- void wyswietlaniezdanych(student studenci[],int ost)
- {
- for(int i=0;i<=ost;i++)
- {
- cout<<studenci[i].index<<endl;
- cout<<studenci[i].ocena<<endl;
- }
- }
- void wyswietlanieniezdanych(student studenci[],int ost,int n)
- {
- for(int i=ost+1;i<n;i++)
- {
- cout<<studenci[i].index<<endl;
- cout<<studenci[i].ocena<<endl;
- }
- }
- int main()
- {
- int n,ocn;
- srand( time( NULL ) );
- cout<<"Podaj ile jest studentow"<<endl;
- cin>>n;
- student studenci[n];
- for(int i=0;i<n;i++)
- {
- studenci[i].index=(rand()%99999+10000);
- do{
- cout<<"Podaj ocene studenta z indeksem: "<<studenci[i].index<<endl;
- cin>>ocn;
- if(ocn!=3 && ocn!=4 && ocn!=5 && ocn!=2 && ocn!=3.5 && ocn!=4.5) cout<<"Bledna ocena!"<<endl;
- }while(ocn!=3 && ocn!=4 && ocn!=5 && ocn!=2 && ocn!=3.5 && ocn!=4.5);
- studenci[i].ocena=ocn;
- }
- int ost=flagapolska(studenci,n);
- cout<<"Zdali: "<<endl;
- wyswietlaniezdanych(studenci,ost);
- cout<<"Niezdali: "<<endl;
- wyswietlanieniezdanych(studenci,ost,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement