学生成绩管理程序。
1。添加:在文件末添加学生记录。(每位学生应该有学号、姓名、性别、三门功课成绩)
2。显示:显示所有学生成绩
3。修改:输入要修改的学生姓名,显示该学生的信息后,修改相应数据
4。删除:删除指定姓名的学生记录
5。排序:分别可以按单科成绩、总分成绩有高到低排序
6。插入:在指定位置插入一条记录
#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 ...全部
#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;
}
。收起