#include "conio.h"
#include "stdlib.h"
#include "string.h"
int studentNum = 0
#define MAXSTUDENT (1024)
#define CheckData()\
{\
if(!studentNum)\
{\
printf("没有学生数据,按任意键返回……\n")\
getch()\
return\
}\
}\
typedef struct Student
{
int id
int cScore
int mathScore
}Student
void ClearStudent(Student* student)
{
memset((void*)student,0,sizeof(*student))
}
void ShowMainMenu()
{
system("cls")
printf("1.增加记录\n2.计算每个学生的总成绩\n3.计算每门课程的平均成绩\n4.按座号查询学生的成绩\n5.按总分排名\n6.输出前n名的学生的成绩\n7.修改成绩\n0.退出\n")
}
void ShowCountScore(const Student* student)
{
system("cls")
CheckData()
for(int i = 0i <studentNumi++)
printf("学生%04d的总成绩:%d\n",(student+i)->id,(student+i)->cScore+(student+i)->mathScore)
printf("\n按任意键继续……")
getch()
}
void ShowClassAvg(const Student* student)
{
system("cls")
CheckData()
double sumc = 0
double summath = 0
for(int i = 0i <studentNumi++)
{
sumc += (student+i)->cScore
summath += (student+i)->mathScore
}
printf("C语言平均成绩为:%lf\n",sumc/studentNum)
printf("数学平均成绩为:%lf\n",summath/studentNum)
printf("\n按任意键继续……")
getch()
}
void AddStudent(Student* student)
{
system("cls")
if(studentNum == MAXSTUDENT)
{
printf("人数已满,按任意键返回……\n")
getch()
}
printf("分别录入座号、C语言成绩、数学成绩:\n")
int id = 0
int cScore = 0
int mathScore = 0
scanf("%d%d%d",&id,&cScore,&mathScore)
for(int i = 0 i <studentNumi++)
if((student+i)->id == id)
{
printf("座号重复,按任意键返回……\n")
getch()
return
}
(student+studentNum)->id = id
(student+studentNum)->cScore = cScore
(student+studentNum)->mathScore = mathScore
studentNum++
}
void SelectFromID(const Student* student)
{
system("cls")
CheckData()
printf("输入查询ID:\n")
int id = 0
scanf("%d",&id)
printf("查询结果:\n")
for(int i = 0i<studentNumi++)
if(id == (student+i)->id)
{
printf("C语言成绩为:%d\n数学成绩为:%d\n",(student+i)->cScore,(student+i)->mathScore)
break
}
printf("\n按任意键继续……")
getch()
}
void SortForCount(Student* student)
{
system("cls")
CheckData()
for(int i = 0i <studentNumi++)
{
for(int j = studentNum -1j >ij--)
if(((student+j)->cScore+(student+j)->mathScore) >((student+j-1)->cScore+(student+j-1)->mathScore))
{
Student stu
stu = *(student+j)
*(student+j) = *(student+j-1)
*(student+j-1) = stu
}
}
}
void SortForN(Student* student,int n)
{
SortForCount(student)
if(!studentNum)
return
n = n>studentNum?studentNum:n
for(int i = 0i<ni++)
printf("第%d名:\nID:%d\nC语言成绩为:%d\n数学成绩为:%d\n总分为:%d\n\n",i+1,(student+i)->id,(student+i)->cScore,(student+i)->mathScore,(student+i)->cScore+(student+i)->mathScore)
printf("\n按任意键继续……")
getch()
}
void UpdateScore(Student* student)
{
system("cls")
CheckData()
printf("输入修改ID:\n")
int id = 0
scanf("%d",&id)
int i = 0
for(i<studentNumi++)
if(id == (student+i)->id)
break
if(i == studentNum)
printf("\n查无此人,按任意键继续……")
else
{
printf("输入欲修改的C语言成绩、数学成绩:\n")
int cScore = 0
int mathScore = 0
scanf("%d%d",&cScore,&mathScore)
(student+i)->cScore=cScore
(student+i)->mathScore = mathScore
printf("\n按任意键继续……")
}
getch()
}
void RunStudent(Student* student)
{
while(1)
{
ShowMainMenu()
char chGet = getch()
switch(chGet)
{
case '1':
AddStudent(student)
break
case '2':
ShowCountScore(student)
break
case '3':
ShowClassAvg(student)
break
case '4':
SelectFromID(student)
break
case '5':
SortForCount(student)
for(int i =0i<studentNumi++)
printf("第%d名:\nID:%d\nC语言成绩为:%d\n数学成绩为:%d\n总分为:%d\n\n",i+1,(student+i)->id,(student+i)->cScore,(student+i)->mathScore,(student+i)->cScore+(student+i)->mathScore)
printf("\n按任意键继续……")
getch()
break
case '6':
{
int n = 0
printf("输入N:\n")
scanf("%d",&n)
SortForN(student,n)
}
break
case '7':
UpdateScore(student)
break
case '0':
return
default:
break
}
}
}
int main()
{
Student* allStudent = (Student*)malloc(MAXSTUDENT*sizeof(Student))
memset((void*)allStudent,0,MAXSTUDENT*sizeof(Student))
RunStudent(allStudent)
return 0
}
你的意思是在下拉框中显示你员工的姓名吧?那应该这样做
<select name="name">
在这里搜索数据库,例如:select name from mian order by name
返回搜索结果ResultSet或者List
while(rs.hasnext())或者while(list.hasnext()){
<option value="姓名">姓名</option>
}
</select>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)