Đề bài là: cho 1 danh sách các học sinh :yêu cầu nhập tên và điểm vào và hãy xắp xếp chúng theo thứ tự giảm dần !
mọi người giúp mình bài này với hàm hàm đổi void hoandoi(xx *a,int n) ngay chổ vòng lặp j có gì sai không vậy !
#include<iostream>
using namespace std;
#include<string>
struct Xap_Xep
{
char ten[30];
long diem;
};
typedef struct Xap_Xep xx;
#include<string.h>
void Nhap(xx *a,int n)
{
for(int i=0;i<n;i++)
{
fflush(stdin);
cout<<"Vui Long Nhap Thong tin Sinh Vien Thu "<<i+1;
cout<<"\nVui Long Nhap Ten ";cin.get(a[i].ten,30);
cout<<"\nVui Long Nhap Diem";cin>>a[i].diem;
}
}
void Xuat(xx *a,int n)
{
for(int i=0;i<n;i++)
{
cout<<"\nThong tin Sinh Vien Thu "<<i+1;
cout<<"\nTen Ho"<<a[i].ten;
cout<<"\nDiem"<<a[i].diem;
}
}
void HoanViChuoi(char &s1,char &s2)
{
char s3=s1;
s1=s2;
s2=s3;
}
void HoanViSo(long &a,long &b)
{
long c=a;
a=b;
b=c;
}
void HoanDoiChuoi(char *s1,char *s2)
{
int i,j;
int lenth1=strlen(s1);
int lenth2=strlen(s2);
for(int i=0,j=0;i<lenth1,j<lenth2;i++,j++)
{
HoanViChuoi(s1[i],s2[j]);
}
s1[lenth2]='\0';
s2[lenth1]='\0';
}
void HoanDoi(xx *a,int n) //chổ này nè
{
char *c=new char[40];
char *d=new char[40];
for(int i=0,j=1;i<n,j<n;i++,j++) //chổ này nè
{
if(a[i].diem>a[j].diem) //chổ này nè
{
HoanViSo(a[i].diem,a[j].diem);
HoanDoiChuoi(c=a[i].ten,d=a[j].ten);
}
}
Xuat(a,n);
}
int main()
{
xx *a=new xx[30];
int n;
system("cls");
cout<<"\nVui Long Nhap So Luong Sinh Vien ";cin>>n;
Nhap(a,n);
HoanDoi(a,n);
delete a;
system("pause");
return 0;
}