#include<iostream.h>
#include<iomanip.h>
struct student
{
int fn;
double uspeh;
char name[30];
};

void input(student* st1,int n)
{
for(int i=0;i<=n-1;i++)
{
  cout<<"\n\nfnn";
  cin>>st1[i].fn;
  cout<<"uspeh";
  cin>>st1[i].uspeh;
  cout<<"name:";
  cin>>st1[i].name;
}
}

void output(student * st2, int n)
{
for(int i=0;i<=n-1;i++)
{
  cout<<st2[i].fn<<setw(4)<<st2[i].uspeh<<setw(10)<<st2[i].name;
  cout<<endl;
 
}
}

student sup_uspeh(student* st3, int n)
{
student max = st3[0];
for(int i=1; i<n; i++)
{

  if(st3[i].uspeh > max.uspeh)
  {
 
  max.uspeh = st3[i].uspeh;
  }
 
}
return max;
}

void sort(student* st4, int n)
{
student min;
for(int i = 0; i < n-1; i++)
{
  min = st4[i];
  int k = i;
  for(int j = i+1; j < n; j++)
  {
 
  if(st4[j].uspeh < min.uspeh)
  {
 
    k = j;
    min = st4[j];
  }
  }
  st4[k] = st4[i];
  st4[i] = min;
}
}

void pointer_sort(student** st4, int n)
{
    student * min;
for(int i = 0; i < n-1; i++)
{

  min = st4[i];
  int k = i;
  for(int j = i+1; j < n; j++)
  {
 
  if(st4[j]->uspeh < min->uspeh)
  {
 
    k = j;
    min = st4[j];
  }
  }
  st4[k] = st4[i];
  st4[i] = min;
}
}
void main()
{
student st[100];
student* stp[100];
int n;
cout<<"n=";
cin>>n;
for(int i=0; i<n; i++)
{
  stp[i] = &st[i];
}

input(st,n);
cout << endl;
output(st,n);
cout << endl;
cout << sup_uspeh(st,n).name;
cout << endl;
sort (st,n);
output(st,n);
pointer_sort(stp, n);
}
Последно модифициране: събота, 12 ноември 2011, 17:38