You are on page 1of 3

#include <iostream>

#include <string>

using namespace std;


class Candidate {
private:
int mssv;
string hoten;
string dob;
float diemToan;
float diemVan;
float diemAnh;

public:
Candidate() : mssv(0), hoten(""), dob(""), diemToan(0), diemVan(0), diemAnh(0)
{}

Candidate(int mssv, string hoten, string dob, float diemToan, float diemVan,
float diemAnh)
: mssv(mssv), hoten(hoten), dob(dob), diemToan(diemToan), diemVan(diemVan),
diemAnh(diemAnh) {}

float DiemCaoNhat() const {


return diemToan + diemVan + diemAnh;
}

void XuatThongTin() const {


cout << endl ;
cout << "Candidate mssv: " << mssv << endl;
cout << "hoten: " << hoten << endl;
cout << "Date of Birth: " << dob << endl;
cout << "Math Score: " << diemToan << endl;
cout << "Literature Score: " << diemVan << endl;
cout << "English Score: " << diemAnh << endl;
cout << "Total Score: " << DiemCaoNhat() << endl;
}

bool operator<(const Candidate& other) const {


return DiemCaoNhat() < other.DiemCaoNhat();
}
};

class ListCandidate {
private:
static const int MAX_CANDIDATES = 100;
Candidate candidates[MAX_CANDIDATES];
int count;

public:
ListCandidate() : count(0) {}

void addCandidate(const Candidate& candidate) {


if (count < MAX_CANDIDATES) {
candidates[count] = candidate;
count++;
} else {
cerr << "List is full, cannot add more candidates!" << endl;
}
}
void XuatTongDiemCaoHon15(float threshold) const {
for (int i = 0; i < count; ++i) {
if (candidates[i].DiemCaoNhat() > threshold) {
candidates[i].XuatThongTin();
}
}
}

Candidate findCandidateWithHighestTotalScore() const {


Candidate highest = candidates[0];
for (int i = 1; i < count; ++i) {
if (candidates[i].DiemCaoNhat() > highest.DiemCaoNhat()) {
highest = candidates[i];
}
}
return highest;
}

void SapXepGiamDan() {
for (int i = 0; i < count - 1; ++i) {
for (int j = i + 1; j < count; ++j) {
if (candidates[j] < candidates[i]) {
Candidate temp = candidates[i];
candidates[i] = candidates[j];
candidates[j] = temp;
}
}
}
}
};

int main() {
ListCandidate list;

// Nhập vào số lượng thí sinh


int n;
cout << "Enter the number of candidates: ";
cin >> n;

// Nhập thông tin các thí sinh


for (int i = 0; i < n; ++i) {
int mssv;
string hoten, dob;
float diemToan, diemVan, diemAnh;

cout << "Candidate " << i + 1 << ":" << endl;


cout << "Enter mssv: ";
cin >> mssv;
cin.ignore(); // Clear the input buffer
cout << "Enter hoten: ";
getline(cin, hoten);
cout << "Enter date of birth (DD/MM/YYYY): ";
getline(cin, dob);
cout << "Enter math score: ";
cin >> diemToan;
cout << "Enter literature score: ";
cin >> diemVan;
cout << "Enter English score: ";
cin >> diemAnh;

Candidate candidate(mssv, hoten, dob, diemToan, diemVan, diemAnh);


list.addCandidate(candidate);
}

// Xuất thông tin các thí sinh có tổng điểm lớn hơn 15
cout << "\nCandidates with total score greater than 15:\n";
list.XuatTongDiemCaoHon15(15);

// Cho biết thí sinh có tổng điểm cao nhất


Candidate ThiSinhDiemCaoNhat = list.findCandidateWithHighestTotalScore();
cout << "\nCandidate with the highest total score:\n";
ThiSinhDiemCaoNhat.XuatThongTin();

// Sắp xếp danh sách thí sinh giảm dần theo tổng điểm
list.SapXepGiamDan();
cout << "\nSorted list of candidates by total score (descending order):\n";
list.XuatTongDiemCaoHon15(0);

return 0;
}

You might also like