#include
#include
#include
#include
#include
#include
using namespace std;
void Sort();
void Output();
char stu_no[6];
struct STUDENT
{
char class_no[20];
char student_no[6];
char name[8];
float cpp_prog;
float media;
float english;
float math;
float ave_score;
int order;
bool operator stu;
int size;
bool COMPARE(const STUDENT& x)
{
int flag;
flag = strcmp(x。
student_no, stu_no);
if (flag == 0)
{
return true;
}
else
{
return false;
}
}
void Input(void)
{
int num;
STUDENT temp;
cout > num;
size = num;
for (int i=0; i> temp。
class_no >> temp。student_no >> temp。name
>> temp。cpp_prog >> temp。media >> temp。english
>> temp。math;
stu。push_front(temp); //从前端添加元素
}
}
void Statistic(void)
{
int i;
i=0;
list::iterator p;
for (p=stu。
begin(); p!=stu。end(); p++)
{
(*p)。ave_score = ((*p)。cpp_prog + (*p)。english
+ (*p)。math + (*p)。media) / 4;
}
for (p=stu。
begin(); p!=stu。end(); p++)
{
cout >stu_no;
cout::const_iterator iter;
iter = find_if(stu。begin(),stu。end(),COMPARE);
if(iter == stu。
end() )
cout >stu_no;
STUDENT temp;
list::iterator p;
p = find_if(stu。begin(),stu。end(),COMPARE);
if(p == stu。
end() )
cout > temp。cpp_prog;
cout > temp。media;
cout > temp。english;
cout > temp。math;
(temp)。ave_score = ((temp)。
cpp_prog + (temp)。english
+ (temp)。math + (temp)。media) / 4;
replace_if(stu。begin(),stu。end(),COMPARE,temp);
Sort ();
}
}
void Delete(void)
{
cout >stu_no;
list::iterator p;
p = find_if(stu。
begin(), stu。end(), COMPARE);
stu。erase(p);
Sort();
Output();
}
void Sort(void)
{
int i;
i = 1;
stu。sort();
list::iterator p;
for (p=stu。
begin(); p!=stu。end(); p++)
{
(*p)。order = i;
i++;
}
Output();
}
void Insert(void)
{
STUDENT temp;
cout > temp。
class_no >> temp。student_no >> temp。name
>> temp。cpp_prog >> temp。media >> temp。english
>> temp。math;
temp。ave_score = (temp。
cpp_prog + temp。english +temp。math + temp。media )/4;
stu。push_front(temp);
Sort();
}void Output()
{
list::iterator p ;
int i;
i = 0;
for(p=stu。
begin(); p!=stu。end(); p++)
{
cout > flag;
cin。
ignore();
switch(flag)
{
case '1': Input(); break;
case '2': Output(); break;
case '3': Statistic(); break;
case '4': Sort(); break;
case '5': Lookup(); break;
case '6': Modify(); break;
case '7': Delete(); break;
case '8': Insert(); break;
case '0': exit(0);
}
cout << "*********************************************** " << endl;
cout << endl << endl;
}
return 0;
}
。
全部