C++: OOP: chương trình của mình chạy xong nhưng nó lại xuất danh sách không theo thứ tự tổng điểm, ai có thể giúp mình với! Cảm ơn đã đọc!
#include<iostream>
#include<string>
using namespace std;
class thisinh
{
private:
string ho_ten;
string sbd;
string dia_chi;
string gioi_tinh;
int tuoi;
float diemly;
float diemhoa;
float diemtoan;
public:
void input();
void output();
float tong_diem();
thising()
{
}
~thisinh()
{
}
};
void thisinh::input()
{
fflush(stdin);
cout<<"\nNhap ten: ";
getline(cin, ho_ten);
fflush(stdin);
cout<<"\nNhap dia chi: ";
getline(cin, dia_chi);
fflush(stdin);
cout<<"\nNhap so bao danh: ";
getline(cin, sbd);
fflush(stdin);
cout<<"\nNhap gioi tinh: ";
getline(cin,gioi_tinh);
cout<<"\nNhap tuoi: ";
cin>>tuoi;
cout<<"\nNhap diem ly: ";
cin>>diemly;
cout<<"\nNhap diem toan: ";
cin>>diemtoan;
cout<<"\nNhap diem hoa: ";
cin>>diemhoa;
}
void thisinh::output()
{
cout<<sbd<<", ";
cout<<ho_ten<<", ";
cout<<dia_chi<<", ";
cout<<gioi_tinh<<", ";
cout<<"Tuoi: "<<tuoi<<", ";
cout<<"Diem ly: "<<diemly<<", ";
cout<<"Diem toan: "<<diemtoan<<", ";
cout<<"Diem hoa: "<<diemhoa<<"!";
}
float thisinh::tong_diem()
{
return diemhoa+diemly+diemtoan;
}
//void sapxep(thisinh *x, thisinh *y)
//{
// thisinh *tam= new thisinh();
// tam = x;
// x=y;
// y=tam;
//}
void menu(thisinh *x[],int n,int diemchuan)
{
while(true)
{
int luachon;
system("cls");
cout<<"---------------QUAN LI------------------";
cout<<"\n1.Nhap thong tin thi sinh.";
cout<<"\n2.Xem danh sach thong tin thi sinh.";
cout<<"\n----------------------------------------";
cout<<"\nNhap lua chon: ";
cin>>luachon;
if(luachon==1)
{
cout<<"\nThi sinh thu "<<n+1;
thisinh *k = new thisinh();
k->input();
x[n]=k;
system("pause");
n++;
}
if(luachon==2)
{
cout<<"\nDanh sach thong tin thi sinh\n";
for(int i=0;i<n;i++)
{
x[i]->output();
cout<<"\nTong diem: "<<x[i]->tong_diem();
if(x[i]->tong_diem()>diemchuan)
{
cout<<"( Trung tuyen)\n";
}
else cout<<"( Truot)\n";
}
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
if(x[i]->tong_diem() > x[j]->tong_diem())
{
thisinh *tam = new thisinh();
*tam = *x[i];
*x[i]=*x[j];
*x[j]=*tam;
}
}
}
system("pause");
}
}
}
int main()
{
float diemchuan;
cout<<"Nhap diem chuan:";
cin>>diemchuan;
thisinh *x[100];
int n=0;
menu(x,n,diemchuan);
return 0;
}


83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?