Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C++ by KhanhToan ( 5 years ago )
#include "Header.h"
QLKH::QLKH()
{
pHead = pTail = NULL;
}
QLKH::~QLKH()
{
Node* temp;
while (pHead != NULL)
{
temp = pHead;
pHead = pHead->pNext;
delete temp;
}
}
Node* QLKH::getNode(const Student& x)
{
Node* p = new Node;
if (p == NULL)
{
cout << "Khong du bo nho. \n";
return NULL;
}
p->Data = x;
p->pNext = NULL;
return p;
}
void QLKH::PushBack(const Student& x)
{
Node* p = getNode(x);
if (pHead == NULL)
{
pHead = pTail = p;
}
else
{
pTail->pNext = p;
pTail = p;
}
}
void QLKH::CalculateGrade(Student& x)
{
if (x.score < 50)
x.grade = 'F';
else if (x.score < 60)
x.grade = 'D';
else if (x.score < 70)
x.grade = 'C';
else if (x.score < 80)
x.grade = 'B';
else
x.grade = 'A';
}
istream& operator>>(istream& in, Student& x)
{
in >> x.id;
in >> x.name;
in >> x.score;
return in;
}
ostream& operator<<(ostream& out, Student x)
{
out << x.id << "\t" << x.name << "\t" << x.score << "\t" << x.grade;
return out;
}
void QLKH::Print()
{
cout << "id\t name\t score\t grade\t";
for (Node* p = pHead; p != NULL; p = p->pNext)
{
cout << p->Data;
}
}
Revise this Paste