em chạy code trên dev c thì chạy được mà trên tubo C nó không dịch được, báo lỗi ạ.mọi người giúp em với.
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
struct date
{
int ngay, thang, nam;
};
class sinhvien
{
private:
string ten, gt, lop;
date ns;
float toan, ly, hoa, tbc;
public:
void nhap();
void in();
void tinhtbc(sinhvien a[200], int);
void sapxep(sinhvien a[200], int);
};
void sinhvien::nhap()
{
cout << "Nhap ho ten:";
cin.ignore();
getline(cin, ten);
cout << "Nhap ngay sinh:" << endl;
cout << "Ngay:";
cin >> ns.ngay;
cout << "Thang:";
cin >> ns.thang;
cout << "Nam:";
cin >> ns.nam;
cout << "Nhap gioi tinh:";
cin.ignore();
getline(cin, gt);
cout << "Nhap lop:";
cin.ignore();
getline(cin, lop);
cout << "Nhap diem:\nToan:";
do
{
cin >> toan;
if (toan < 0 || toan>10)
cout << "Diem khong hop le.Nhap lai:\n";
} while (toan < 0 || toan >10);
do
{
cout << "Ly:";
cin >> ly;
if (ly < 0 || ly>10)
cout << "Diem khong hop le.Nhap lai:\n";
} while (ly < 0 || ly>10);
do
{
cout << "Hoa:";
cin >> hoa;
if (hoa < 0 || hoa>10)
cout << "Diem khong hop le.Nhap lai:\n";
} while (hoa < 0 || hoa>10);
}
void sinhvien::in()
{
cout << setw(20) << ten << setw(10)<<ns.ngay << "/" << ns.thang << "/" << ns.nam << setw(17) << gt << setw(10) << lop;
cout << setw(10) << toan << setw(10) << ly << setw(10) << hoa << setw(10) << tbc << endl;
}
void sinhvien::tinhtbc(sinhvien a[200], int n)
{
for (int i = 0; i < n; i++)
a[i].tbc = (a[i].toan + a[i].ly + a[i].hoa) / 3;
}
void sinhvien::sapxep(sinhvien a[200], int n)
{
sinhvien temp;
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
if (a[i].tbc < a[j].tbc)
{
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
main()
{
sinhvien sv[200];
int n, i;
cout << "Nhap so sinh vien :";
cin >> n;
for (i = 0; i < n; i++)
{
cout << "sinh vien " << i + 1 << ":\n";
sv[i].nhap();
}
system("cls");
sv[0].tinhtbc(sv, n);
sv[0].sapxep(sv, n);
cout << setw(20) << "Ten" << setw(18) << "Ngay Sinh" << setw(17) << "Gioi Tinh" << setw(10) << "Lop";
cout << setw(10) << "Toan" << setw(10) << "Ly" << setw(10) << "Hoa" << setw(10) << "TBC" << endl;
cout << "=========================================================================================================\n";
for (i = 0; i < n; i++)
sv[i].in();
system("pause");
}