<<" 1.输入/添加学生资料 "<<endl <<"
2.输出学生资料" <<endl <<"
3.查找 " <<endl <<"
4.删除" <<endl <<"
5.总分排序" <<endl <<"
6.退出" <<endl <<endl <<"
请选择你要的服务(1-6)"<<endl cin >>chose if(chose=='6') { break } switch(chose) { case '1': //
输入学生信息 { do { cout <<"
请输入学生姓名:" <<endl ch1=new char[]ch2=new char[]cin >>ch1 cout <<"
请输入学号:" <<endl cin >启告>num while(st.check_num(num)) { cout <<"
学号重复,请重新输入" <<endl cin >>num } cout <<"
请输入地址:"<<endl cin >>ch2 cout <<"
请输入高数成绩:"<<endl cin >>x cout <<"
请输入英语成绩:" <<endl cin >>y cout <<"
请输入计算机成绩:" <<endl cin >>z st.input(ch1,num,ch2,x,y,z)printf("\n
是否继续输入学生信息?(\"y\"继续)")scanf("%s", flag) }while(strcmp(flag, "y") == 0) }break case '2'://
输出学生资料 { temp=countcount=1 cout <<"
序号\t姓名\t学号\t\t地址\t\t\t高数\t英语\t计算机" <<endl while(count<=temp) { st.show()count++ } count--getch()}break case '3': { cout <<"
请输入你要查找学生的学号" <<endl cin >>find st.find(find) }break case '4': { cout <<"
请输入你要删除的学生学号" <<endl cin >>del st.del(del) }break case '5': { st.taxis()}break
default: { cout <<"输入错误!!!,请重新输入" <<endl getch() } } } cout <<"感谢你的使用!\n" <<endl getch()
}
#include <stdio.h>
#include <windows.h>
#include <大哪string.h>
struct worker
{
int num
char name[20]
char zhicheng[10]
int wages
int reward
long birth
int salary
}work[500],work1/*定义结构体*/
void menu()//声明菜单函数
void type_in()//声明录悄仿明入函数
void baocun(int)//声明保存函数
void scan()//声明浏览函数
void del()//声明删除函数
void search()//声明查询函数
void search_zhicheng()//声明按职称查询函数
void search_name()//声明按姓名查找函数
void change()//声明修改函数
void order()//声明排序函数
void add()//声明添加函数
void order_wages()
void order_name()
void menu() /*菜单函数*/
{
printf("\n")
printf(" welcome to \n")
printf(" 职工信息管理系统 ")
printf("******************************************************************************\n")
printf(" 1.录入职工信息\n")
printf(" 2.浏览职工信息\n")
printf(" 3.查询职工信息\n")
printf(" 4.删除职工信息\n")
printf(" 5.修改职工信息\n")
printf(" 6.职工信息排序\n")
printf(" 7.添加职工信息\n")
printf(" 8.退出\n")
printf("*******************************************************************************\n")
printf("\n")
}
/********************************************************************************************/
void main()
{
int n,f
while(1)
{
do
{
menu()/*调用菜单函数*/
printf("请输入你需要 *** 作的序号(1—8):\n")
scanf("%d",&n)
if(n>=1&&n<=8)
{
f=1
break
}
else
{
f=0
printf("您输入有误,请重新选择!")
}
}while(f==0)
switch(n)
{
case 1:printf(" 录入职工信息\n")printf("\n")type_in()break
case 2:printf(" 浏览职工信息\n")printf("\n")system("cls")scan()break
case 3:printf(" 查询职工信息\n")printf("\n")system("cls")search()break
case 4:printf(" 删除职工信息\n")printf("\n")system("cls")del()break
case 5:printf(" 修改职工信息\n")printf("\n")system("cls")change()break
case 6:printf(" 职工信息排序\n")printf("\n")system("cls")order()break
case 7:printf(" 添加职工信息\n")printf("\n")system("sls")add()break
case 8:goto loop/*用goto语句跳至跳至指定的行*/
default :break
}
}
loop://行标
system("cls")
printf("\n\n\n\n\n\n -----
#include"stdio.h"#include"string.h"
#define N 1000
void menu()
int password()
int dedao()
int uninque(struct STUDENT shu[],int len,int xuehao)
void shuchu(struct STUDENT shu[],int len)
void send(struct STUDENT shu[],int len)
int readFromFile(struct STUDENT shu[])
void chaxun(struct STUDENT shu[],int len)
void paixu(struct STUDENT shu[],int len)
struct STUDENT
{
int num
char name[10]
int score
} shu[N]
main()
{ int len=0,key,choice
do {
key=password()
}while(key==0)
while(1)
{ menu()
printf("请输入选项<1,2,3,4,5,6,7>\n")
scanf("%d",&choice)
switch(choice)
{
case 1:printf("输入信息函数\n")len=dedao(shu,len)break
case 2:printf("输出函数被调用\n") shuchu(shu,len) break
case 3:printf("保存到孙余文件函数被调用\n")send(shu,len) break
case 4:printf("从文件读函数被调用\n") len=readFromFile( shu)break
case 5:printf("按学号查询函数被调用\n")chaxun(shu,len) break
case 6:printf("按成绩排序函数被调用\n")paixu(shu,len)break
case 7:exit(0)break
}
}
}
void menu()
{
printf("\n")
printf(" *******************************************\n")
printf(" * 学生成绩管理系统2.0 *\巧运n")
printf(" * 1.输入信息 *\n")
printf(" * 2.输出信息 *\n")
printf(" * 3.保存到文件 *\n")
printf(" * 4.从文件读 *\n")
printf(" * 5.按学号查询 *\n")
printf(" * 6.按成绩排序(由大到小) *\n")
printf(" * 7.程序结束 *\n")
printf(" *******************************************\n")
}
int password()
{
char a[100]
char key[]="asd"
printf("请输入密码\n")
scanf("%s"则宽滚,&a)
if(strcmp(a,key)==0)
return 1
else
return 0
}
int dedao(struct STUDENT shu[],int len)
{ int i=len
int flag=0
int xuehao,bank,chengji
while(i<N)
{
while(1)
{
printf("学号")
scanf("%d",&xuehao)
if(xuehao==0)
{ flag=1
break
}
bank=uninque(shu,i,xuehao)
if(bank==0)
{ shu[i].num=xuehao
break}
}
if(flag==1)
break
printf("姓名")
scanf("%s",&shu[i].name)
while (1)
{
printf("成绩")
if(scanf("%d",&chengji)==1)
{break}
printf("输入格式错误,请重新输入!")
while(getchar()!='\n')
continue
}
while(getchar()!='\n')
continue
shu[i].score=chengji
i++
}
return i
}
int uninque(struct STUDENT shu[],int len,int xuehao)
{ int i
int bank=0
for (i=0i<leni++)
{
if(xuehao==shu[i].num)
bank=1
}
return bank
}
void shuchu(struct STUDENT shu[],int len)
{
int i
printf("%-4s %-10s %-3s","学号","姓名","成绩\n\n")
for(i=0i<leni++)
{
printf("%-4d %-10s %-3d",shu[i].num,shu[i].name,shu[i].score)
printf("\n")
}
printf("\n\n")
}
void send(struct STUDENT shu[],int len)
{
int i
FILE *fp
fp=fopen("d:\\chegnji.txt","wb")
if(fp==NULL)
{
printf("打开文件出错!\n")
exit(0)
}
for(i=0i<leni++)
fwrite(shu+i,sizeof(struct STUDENT),1,fp)
fclose(fp)
}
int readFromFile(struct STUDENT shu[])
{
FILE *fp=NULL
int i=0
fp=fopen("d:\\chegnji.txt","rb")
if(fp!=NULL)
{
printf("%-4s %-10s %-3s","学号","姓名","成绩\n\n")
while(!feof(fp))
{
if(i>=N)
break
if(fread(shu+i,sizeof(struct STUDENT),1,fp))
printf("%-4d %-10s %-3d",shu[i].num,shu[i].name,shu[i].score)
printf("\n")
i++
}
fclose(fp)
}
i=i-1
return i
}
void chaxun(struct STUDENT shu[],int len)
{
int i,nue,b=0
while(1)
{printf("input the student number (input'0' close) ")
scanf("%d",&nue)
b=0
if(nue==0)
break
for (i=0i<leni++)
{
if(nue==shu[i].num)
{ printf("%-4s %-10s %-3s","学号","姓名","成绩\n\n")
printf("%-4d %-10s %-3d\n",shu[i].num,shu[i].name,shu[i].score)
b=1
}
}
if(b==0)
printf("The number is not exist!\n")
}
}
void paixu(struct STUDENT shu[],int len)
{
int i,j
struct STUDENT temp
printf("%-4s %-10s %-3s","学号","姓名","成绩\n\n")
for(i=0i<leni++)
{
for(j=ij<lenj++)
{
if(shu[j].score>shu[i].score)
{
temp=shu[j]
shu[j]=shu[i]
shu[i]=temp
}
}
printf("%-4d %-10s %-3d\n",shu[i].num,shu[i].name,shu[i].score)
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)