学生成绩管理系统 C语言编程

作者&投稿:蓬妻 (若有异议请与网页底部的电邮联系)
学生成绩管理系统,使用c语言程序编写。~

给一个我以前写过的吧,功能应该差不多
#include #include #include #include #include #include #include #include #include using namespace std;/*定义学生结构体*/struct Student{ char ID[20]; char Name[20]; float Mark1; float Mark2; float Mark3; float Average;};/*声明学生数组及学生数量*/struct Student students[1000];int num=0; /*求平均值*/float Avg(struct Student stu){ return (stu.Mark1+stu.Mark2+stu.Mark3)/3;} /*通过学号返回数组下标*/int Student_SearchByIndex(char id[]){ int i; for (i=0;i<num;i++) { if (strcmp(students[i].ID,id)==0) { return i; } } return -1;} /*通过姓名返回数组下标*/int Student_SearchByName(char name[]){ int i; for (i=0;i<num;i++) { if (strcmp(students[i].Name,name)==0) { return i; } } return -1;} /*显示单条学生记录*/void Student_DisplaySingle(int index){ printf("%10s%10s%8s%8s%8s%10s
","学号","姓名","成绩","成绩","成绩","平均成绩"); printf("-------------------------------------------------------------
"); printf("%10s%10s%8.2f%8.2f%8.2f%10.2f
",students[index].ID,students[index].Name, students[index].Mark1,students[index].Mark2,students[index].Mark3,students[index].Average);} /*插入学生信息*/void Student_Insert(){ while(1) { printf("请输入学号:"); scanf("%s",&students[num].ID); getchar(); printf("请输入姓名:"); scanf("%s",&students[num].Name); getchar(); printf("请输入成绩:"); scanf("%f",&students[num].Mark1); getchar(); printf("请输入成绩:"); scanf("%f",&students[num].Mark2); getchar(); printf("请输入成绩:"); scanf("%f",&students[num].Mark3); getchar(); students[num].Average=Avg(students[num]); num++; printf("是否继续?(y/n)"); if (getchar()=='n') { break; } } } /*修改学生信息*/void Student_Modify(){ //float mark1,mark2,mark3; while(1) { char id[20]; int index; printf("请输入要修改的学生的学号:"); scanf("%s",&id); getchar(); index=Student_SearchByIndex(id); if (index==-1) { printf("学生不存在!
"); } else { printf("你要修改的学生信息为:
"); Student_DisplaySingle(index); printf("-- 请输入新值--
"); printf("请输入学号:"); scanf("%s",&students[index].ID); getchar(); printf("请输入姓名:"); scanf("%s",&students[index].Name); getchar(); printf("请输入成绩:"); scanf("%f",&students[index].Mark1); getchar(); printf("请输入成绩:"); scanf("%f",&students[index].Mark2); getchar(); printf("请输入成绩:"); scanf("%f",&students[index].Mark3); getchar(); students[index].Average=Avg(students[index]); } printf("是否继续?(y/n)"); if (getchar()=='n') { break; } }} /*删除学生信息*/void Student_Delete(){ int i; while(1) { char id[20]; int index; printf("请输入要删除的学生的学号:"); scanf("%s",&id); getchar(); index=Student_SearchByIndex(id); if (index==-1) { printf("学生不存在!
"); } else { printf("你要删除的学生信息为:
"); Student_DisplaySingle(index); printf("是否真的要删除?(y/n)"); if (getchar()=='y') { for (i=index;i<num-1;i++) { students[i]=students[i+1];//把后边的对象都向前移动 } num--; } getchar(); } printf("是否继续?(y/n)"); if (getchar()=='n') { break; } }} /*按姓名查询*/void Student_Select(){ while(1) { char name[20]; int index; printf("请输入要查询的学生的姓名:"); scanf("%s",&name); getchar(); index=Student_SearchByName(name); if (index==-1) { printf("学生不存在!
"); } else { printf("你要查询的学生信息为:
"); Student_DisplaySingle(index); } printf("是否继续?(y/n)"); if (getchar()=='n') { break; } }} /*按平均值排序*/void Student_SortByAverage(){ int i,j; struct Student tmp; for (i=0;i<num;i++) { for (j=1;j<num-i;j++) { if (students[j-1].Average<students[j].Average) { tmp=students[j-1]; students[j-1]=students[j]; students[j]=tmp; } } }} /*显示学生信息*/void Student_Display(){ int i; printf("%10s%10s%8s%8s%8s%10s
","学号","姓名","成绩","成绩","成绩","平均成绩"); printf("-------------------------------------------------------------
"); for (i=0;i<num;i++) { printf("%10s%10s%8.2f%8.2f%8.2f%10.2f
",students[i].ID,students[i].Name, students[i].Mark1,students[i].Mark2,students[i].Mark3,students[i].Average); }} /*将学生信息从文件读出*/void IO_ReadInfo(){ FILE *fp; int i; if ((fp=fopen("Database.txt","rb"))==NULL) { printf("不能打开文件!
"); return; } if (fread(&num,sizeof(int),1,fp)!=1) { num=-1; } else { for(i=0;i<num;i++) { fread(&students[i],sizeof(struct Student),1,fp); } } fclose(fp);} /*将学生信息写入文件*/void IO_WriteInfo(){ FILE *fp; int i; if ((fp=fopen("Database.txt","wb"))==NULL) { printf("不能打开文件!
"); return; } if (fwrite(&num,sizeof(int),1,fp)!=1) { printf("写入文件错误!
"); } for (i=0;i<num;i++) { if (fwrite(&students[i],sizeof(struct Student),1,fp)!=1) { printf("写入文件错误!
"); } } fclose(fp);} /*主程序*/void main(){ int choice; IO_ReadInfo(); while(1) { /*主菜单*/ printf("
------ 学生成绩管理系统------
"); printf("1. 增加学生记录
"); printf("2. 修改学生记录
"); printf("3. 删除学生记录
"); printf("4. 按姓名查询学生记录
"); printf("5. 按平均成绩排序
"); printf("6. 退出
"); printf("请选择(1-6):"); scanf("%d",&choice); getchar(); switch(choice) { case 1: Student_Insert(); break; case 2: Student_Modify(); break; case 3: Student_Delete(); break; case 4: Student_Select(); break; case 5: Student_SortByAverage(); Student_Display(); break; case 6: exit(0); break; } IO_WriteInfo(); }}

C语言程序:
#include #include typedef struct student{char name[20];/* 姓名 */int code;/* 学号 */int kor, eng, math;/* 3门课程的成绩 */}STUDENT;/* 返回输入数据 */STUDENT Input();/* 输出所有输入的数据 */void Output(STUDENT info[], int cnt);/* 将输入分数转换为A-F */char grade(int score);int main(){STUDENT S[10];int cnt = 0, select;int i, j;int code;while(1){printf("学生信息管理系统

");printf("1添加
");printf("2删除
");printf("3查询
");printf("0结束
");printf("您的选择[0-3]:");scanf("%d", &select);if(select 3)continue;if(select == 0){printf("退出系统!
");break;}if(select == 1)/* 添加 */{S[cnt++] = Input();}else if(select == 2)/* 删除 */{printf("待删除学生的学号:");scanf("%d", &code);for(i=0; i= cnt){printf("学号不存在,删除失败!
");}else {for(j=i+1; j= cnt){printf("学号不存在,查找失败!
");}else{printf("查询结果:
");Output(S, i);}}}return 0;}/* 返回输入数据 */STUDENT Input(){STUDENT stu;printf("新学生信息
");printf("学号:");scanf("%d", &stu.code);printf("姓名:");getchar();gets(stu.name);printf("3门课程成绩(以空格分隔):");scanf("%d%d%d", &stu.kor, &stu.eng, &stu.math);return stu;}/* 输出所有输入的数据 */void Output(STUDENT info[], int cnt){printf("学号:%d
",info[cnt].code);printf("姓名:");puts(info[cnt].name);printf("成绩:%c %c %c
", grade(info[cnt].kor), grade(info[cnt].eng), grade(info[cnt].math));}/* 将输入分数转换为A-F */char grade(int score){if(score 100)return 'F';if(score >= 90)return 'A';if(score >= 80)return 'B';if(score >= 70)return 'C';if(score >=60)return 'D';elsereturn 'E';}
运行测试:

//用C++编的,基本能运行,可能有些冗余,你可以自己改一下

#include<iostream>
#include<fstream>
#include<string>
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#include<iomanip>
using namespace std;

class student
{
public:
char *GET_name(){return name;}
char *GET_sex(){return sex;}
int GET_num(){return number;}
int GET_mat(){return Math;}
int GET_eng(){return English;}
protected:
int number,Math,English;
char name[20],sex[5];
};

class student_computer:public student
{
public:
void assign();
int GET_dat() {return datastruct;}
int GET_ele() {return electric;}
int GET_c() {return C;}
float GET_total() {return English+Math+C+datastruct+electric;}
void display();
protected:
int C,datastruct,electric;
float total;

};

typedef struct point_pc
{
student_computer *node;
point_pc *next;
}PT_pc;

void student_computer::display()
{
cout<<"学号:"<<setw(2)<<number<<" 姓名:"<<setw(4)<<name<<" 性别:"<<setw(2)<<sex<<"\n 数学:"<<setw(3)<<Math<<" 英语:"<<setw(3)<<English<<" C语言:"<<setw(3)<<C<<" 数据结构:"<<setw(3)<<datastruct<<" 电子电路:"<<setw(3)<<electric<<" 总分:"<<setw(4)<<GET_total()<<endl;

}

void student_computer::assign()
{
cout<<"输入姓名:";
getchar();
if(strcmp(gets(name),"#")!=0)
{
cout<<"学号:";
cin>>number;
cout<<"性别:";
getchar();
gets(sex);
cout<<"英语:";
cin>>English;
cout<<"数学:";
cin>>Math;
cout<<"C语言:";
cin>>C;
cout<<"数据结构:";
cin>>datastruct;
cout<<"电子电路:";
cin>>electric;

}
}

PT_pc *build_pc()
{int n=0;
student_computer *ppc=NULL;

PT_pc *head,*pm1,*pm2;
ppc=(student_computer *)malloc(sizeof(student_computer));
ppc->assign();
head=pm1=pm2=(PT_pc *)malloc(sizeof(PT_pc));
pm1->node=ppc;
cout<<"输入#为结束!"<<endl;
while(strcmp(ppc->GET_name(),"#"))
{if(n++!=0)pm2->next=pm1;
pm2=pm1;
ppc=(student_computer *)malloc(sizeof(student_computer));
ppc->assign();
pm1=(PT_pc*)malloc(sizeof(PT_pc));
pm1->node=ppc;
}
pm2->next=NULL;
if(strcmp(head->node->GET_name(),"#")==0)
head=NULL;
return head;
}

PT_pc *rank_pc(PT_pc *head)
{
PT_pc *p,*q,*temp;
temp=(PT_pc *)malloc(sizeof(PT_pc));
p=head;
for(;p->next!=NULL;p=p->next)
for(q=p->next;q!=NULL;q=q->next)
{
if((p->node->GET_total())<(q->node->GET_total()))
{
temp->node=p->node;
p->node=q->node;
q->node=temp->node;

}
}
return head;
}

PT_pc *add_pc(PT_pc *head)
{
PT_pc *pi;
pi=(PT_pc *)malloc(sizeof(PT_pc));
student_computer *p;
p=(student_computer *)malloc(sizeof(student_computer));
p->assign();
pi->node=p;
pi->next=head;
head=pi;
return head;
}

PT_pc *del_pc(PT_pc *head)
{
PT_pc *p_move=head;
int number;
cout<<"输入删除者学号:";
cin>>number;
if(head==NULL) {cout<<"without message to delete or rework!"<<endl; return head;}
if(head->node->GET_num()==number) {head=NULL;return head;}
while(p_move->next!=NULL)
{
if((p_move->next)->node->GET_num()==number) break;
p_move=p_move->next;
}
if(p_move->next==NULL) {cout<<"\n\n没有此信息!\n\n";return head;}
p_move->next=(p_move->next)->next;
return head;
}

PT_pc *rework_pc(PT_pc *head)
{
PT_pc *p_move;
student_computer *pi;
pi=(student_computer*)malloc(sizeof(student_computer));
int number;
cout<<"输入要修改者学号:"<<endl;
cin>>number;
p_move=head;
while(p_move!=NULL)
{
if(p_move->node->GET_num()==number)
{pi->assign(); break;}
else p_move=p_move->next;
}
if(p_move==NULL) {cout<<"没有此信息!"<<endl;}
else p_move->node=pi;
return head;
}

void find_pc(PT_pc *head)
{int number;
PT_pc *p_move;
cout<<"输入学号:";
cin>>number;
p_move=head;
while(p_move!=NULL)
{if(p_move->node->GET_num()==number)
{p_move->node->display();
break;
}
p_move=p_move->next;
}
if(p_move==NULL) cout<<"没有此信息!"<<endl;
}

void save_pc(PT_pc *head)
{
PT_pc *p;
p=head;
ofstream outfile("student_computer.txt",ios::binary);
if(!outfile)
{cerr<<"open file fail!"<<endl;
exit(1);
}
while(p!=NULL)
{outfile.write((char*)(p->node),sizeof(student_computer));
p=p->next;
}
outfile.close();
cout<<"保存成功!"<<endl;
}

PT_pc *read_pc()
{
int n=0, i=0;
student_computer *ppc;
PT_pc *head,*p_move1,*p_move2;
ppc=(student_computer *)malloc(sizeof(student_computer));
head=p_move1=p_move2=(PT_pc *)malloc(sizeof(PT_pc));
ifstream infile("student_computer.txt",ios::binary);
if(!infile)
{
cerr<<"打开文件失败!"<<endl;
getchar();

}
while(!infile.eof())
{if((i++)!=0) p_move2->next=p_move1;
p_move2=p_move1;
infile.read((char*)ppc,sizeof(student_computer));
p_move1->node=ppc;
ppc=(student_computer *)malloc(sizeof(student_computer));
p_move1=(PT_pc*)malloc(sizeof(PT_pc));
}
infile.close();
p_move1=NULL;
ppc=NULL;
p_move2->next=NULL;

{
i=0;
p_move1=p_move2=head;
while(p_move1->next!=NULL)
{if((i++)!=0) {p_move2->next=p_move1;p_move2=p_move1;}
p_move1=p_move1->next;
}
p_move2->next=NULL;
}
return head;
}

void display_pc(PT_pc *head)
{PT_pc *p=head;
int i=0;
while(p!=NULL)
{cout<<++i<<" ";
p->node->display();
p=p->next;
}
}

void main()
{char c='0',t='0';
PT_pc *headpc;

system("cls");
ifstream infile("student_computer.txt",ios::binary);
if(!infile)
{cerr<<"请建立新信息!"<<endl;
headpc=build_pc();
}
else headpc=read_pc();
while(t!='8')
{
while(t<'1'||t>'8')
{cout<<"请选择菜单:\n1.打印所有。\n2.添加部分数据.\n3.删除部分数据.\n4.修改数据.\n5.查找数据.\n6.成绩排名.\n7.建立新数据.\n8.退出.\n\n 选择:";
cin>>t;
}
switch(t)
{
case '1': system("cls"); display_pc(headpc); break;
case '2': system("cls"); headpc=add_pc(headpc); display_pc(headpc); break;
case '3': system("cls"); headpc=del_pc(headpc); display_pc(headpc); break;
case '4': system("cls"); headpc=rework_pc(headpc); display_pc(headpc); break;
case '5': system("cls"); find_pc(headpc); break;
case '6': system("cls"); headpc=rank_pc(headpc); display_pc(headpc); break;
case '7': system("cls"); headpc=build_pc(); break;

}
if(t!='8') t='0';
}

while(c!='y'&&c!='n')
{cout<<"是否保存修改后的信息(y or n):"<<endl;
cin>>c;
}
if(c=='y') save_pc(headpc);

}

啥意思?

这是一点,别的我发到你邮箱
cout<<"请输入您要增加的学生的姓名:"<
>name;
cout<<"请输入数学成绩:"<
>math;
cout<<"请输入语文成绩:"<
>chinese;
cout<<"请输入外语成绩:"<
>english;
file[j]=new
ofstream("d:\\document",ios::ate);
*file[j]<<"姓名"<
>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<
评论
0
0
加载更多


甘泉县17683423356: 编程如何用C语言编写一个学生成绩管理系统程序 -
全卷来曲: 我们才做了这个作业... #include <malloc.h> #include <stdio.h> #include <stdlib.h> #define LEN sizeof(struct scorenode) #define DEBUG #include <string.h> struct scorenode { int number;/*学号*/ char name[8];/*姓名*/ float cj1;/*成绩1*/ ...

甘泉县17683423356: C语言编程 学生成绩管理系统 -
全卷来曲: 这是我们大一时候课程设计做的,学生成绩管理系统,功能比楼主需要的稍多一些,你看一下,不需要的函数删掉它好了.#include<stdio.h> #include<malloc.h> #include<string.h>struct stu {long num;char name[20];float score1,score2,score...

甘泉县17683423356: 求一个学生成绩管理系统的C语言代码!!急!! -
全卷来曲: #includestruct student { char num[10];char name[20];char sex[5];float grade[7];float v;float sum;}stu[50]; int k=0;void input(); void output(); void search(); void average(); void sort(); void save(); void main() { int a;do{printf("\n\n **************...

甘泉县17683423356: 如何用C语言编一个学生成绩管理系统 -
全卷来曲: #include "stdio.h"#include "stdlib.h"#include "string.h"#define NULL 0 int shoudsave=0; struct student { char num[10]; char name[20]; char sex[4]; int cgrade; int mgrade; int egrade; int totle; int ave; char neartime[10]; }; typedef struct node { ...

甘泉县17683423356: c语言编写学生成绩管理系统 -
全卷来曲: #include <stdio.h> void main() { /*输入资料*/ int student[5][4],i; for (i=0; i<=4; i++); scanf("%d,%d,%d \n",student[i][0],student[i][1],student[i][2],student[i][3]) /*平均分*/ for (i=0; i<=4; i++); printf("%f",(float)((student[i][1]+student[i][2]+student[i][3]...

甘泉县17683423356: 怎么用c语言编写一个学生成绩管理系统啊?急…… -
全卷来曲: C语言课程设计报告-------学生成绩简单管理程序 一、系统菜单的主要功能 (1)输入若干条记录 (2)显示所有记录 (3)按学号排序 (4)插入一条记录 (5)按姓名查找,删除一条记录 (6)查找并显示一条记录 (7)输出统计信息 (新增)...

甘泉县17683423356: c语言设计学生成绩管理系统 -
全卷来曲: #include<iostream> #include<cstdio> #include<cmath> #include<vector> #include<list> #include<cstring> #include<map> #include<set> #include<algorithm> #include<queue> using namespace std; int n; struct birth {int year,month,day; };struct ...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网