c语言源程序——学生成绩管理系统,能查询男女生人数,查询各科平均成绩,查询学生信息

我就三十分,全给了,大哥大姐帮帮忙啊
就是c语言的源程序,作业,还有插入删除等功能,我就做这一部分

你可以直接用excel编写就行了,没有必要用C语言

如果是上C语言课倒是可以。

这里有个C++学生管理程序。

#include<iostream.h>
#include<string.h>
#include<fstream.h>
class stu
{
char name[20];
double math,chinese,english,average,sum;
public:
stu()
{
}
stu(char n[20],double ma,double chin,double eng)
{
strcpy(name,n);
math=ma;
chinese=chin;
english=eng;
}
double getsum()
{
sum=chinese+english+math;
return sum;
}
double getaver()
{
average=getsum()/3;
return average;
}
friend void main();
};

void main()
{
cout<<"请选择您需要的操作!"<<endl;
cout<<"操作:"<<endl;
cout<<"(0)数据录入"<<endl;
cout<<"(1)增加人员"<<endl;
cout<<"(2)删除人员"<<endl;
cout<<"(3)修改数据"<<endl;
cout<<"查询:"<<endl;
cout<<"(4)按总成绩查询"<<endl;
cout<<"(5)按姓名查询"<<endl;
cout<<"(6)输出所有学生的数据"<<endl;
cout<<"成绩名词"<<endl;
cout<<"(7)按总分查询排名"<<endl;
cout<<"(8)按语文查询排名"<<endl;
cout<<"(9)按数学查询排名"<<endl;
cout<<"(y)按英语查询排名"<<endl;
cout<<"选择相关操作请输入相对的括号里的阿拉伯数字!"<<endl;
char p;char w;
stu *s[50];
ofstream *file[50];
int i=0;
int j=0;
bool flag2=0;
do
{
cin>>p;
if((p>='0'&&p<='10'))
flag2=1;
else
cout<<"指令错误!请重新输入:"<<endl;
}while(flag2==0);
do{
switch(p)
{
case '0':
{
char c;
char name[20];double math,chinese,english;
do{
cout<<"请输入姓名"<<endl;
cin>>name;
cout<<"请输入数学成绩:"<<endl;
cin>>math;
cout<<"请输入语文成绩:"<<endl;
cin>>chinese;
cout<<"请输入外语成绩:"<<endl;
cin>>english;
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"姓名"<<name<<"数学成绩"<<math<<"语文成绩"<<chinese<<"外语成绩"<<english<<endl;
j++;
s[i]=new stu(name, math, chinese, english);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
flag2=0;
do
{
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
else
flag2=1;
}while(flag2==0);
}while(c=='y');
break;
}
case '4':
{
double t;char c;
do
{
int flag1=0;
cout<<"请输入你要查询学生的总成绩"<<endl;
cin>>t;
for(int q=0;q<i;q++)
{
if(s[q]->getsum()==t)
{
flag1=1;
cout<<"您要查询的学生是:"<<(*s[q]).name<<endl;
}
}
if(flag1==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}

case '5':
{
char n[20];int j=0;char c;
do{
int flag=0;
cout<<"请输入你要查询的学生姓名"<<endl;
cin>>n;
for(int j=0;j<i;j++)
{
if(strcmp(n,(*s[j]).name)==0)
{
flag=1;
cout<<"您要查询的学生是:"<<(*s[j]).name<<endl;
cout<<(*s[j]).name<<"的总成绩成绩是"<<(*s[j]).getsum()<<endl<<"平均成绩是:"<<(*s[j]).getaver()<<endl;
}
}
if(flag==0)
cout<<"对不起!您要查询的学生不存在!"<<endl;
cout<<"您想继续查询吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}
while(c=='y');
break;
}
case '1':
{
char name[20];double math,chinese,english;
char c;
do
{
cout<<"请输入您要增加的学生的姓名:"<<endl;
cin>>name;
cout<<"请输入数学成绩:"<<endl;
cin>>math;
cout<<"请输入语文成绩:"<<endl;
cin>>chinese;
cout<<"请输入外语成绩:"<<endl;
cin>>english;
file[j]=new ofstream("d:\\document",ios::ate);
*file[j]<<"姓名"<<name<<"数学成绩"<<math<<"语文成绩"<<chinese<<"外语成绩"<<english<<endl;
j++;
s[i]=new stu(name, math, chinese, english);
i++;
cout<<"数据录入成功,想继续录入吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '2':
{
char name[20];bool flag3=0;char c;
do{
cout<<"请输入您要删除的学生姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
{
if(strcmp(name,s[h]->name)==0)
{
flag3=1;
i--;
do{
s[h]=s[h+1];
h++;
}while(h<=i);
}
}
if(flag3==0)
cout<<"您要求删除的对象本来就不存在!请检查输入的正确性!";
cout<<"要继续删除吗?(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}
case '3':
{
char name[20];double mat,chin,eng;flag2=0;
char c;
do
{
cout<<"请输入您要修改的学生的姓名:"<<endl;
cin>>name;
for(int h=0;h<i;h++)
{
if(strcmp(name,s[h]->name)==0)
{
flag2=1;
cout<<"请输入新的数学成绩:"<<endl;
cin>>mat;
cout<<"请输入新的语文成绩:"<<endl;
cin>>chin;
cout<<"请输入新的外语成绩:"<<endl;
cin>>eng;
s[h]->chinese=chin;
s[h]->math=mat;
s[h]->english=eng;
cout<<"数据修改成功!";
}
}
if(flag2==0)
{
cout<<"您要修改的学生本来就不存在!请检查重新输入!"<<endl;
}
cout<<"想继续修改吗(y/n)"<<endl;
cin>>c;
if(c!='y'&&c!='n')
{
cout<<"指令错误!请重新输入!"<<endl;
cin>>c;
}
}while(c=='y');
break;
}

case '6':
{
cout<<"本系统所有学生数据如下:"<<endl;
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!"<<endl;
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<
"语文:"<<" "<<s[k]->chinese<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english<<"总分:"<<" "<<(*s[k]).getsum()
<<"平均分:"<<" "<<(*s[k]).getaver()<<endl;
}
break;
}
case '7':
{
int t;stu b;

cout<<"本系统所以学生排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->getsum())<(s[y]->getsum()))
t=y;
if(t!=x)
{
b=*s[x];
*s[x]=*s[t];
*s[t]=b;
}
}
}
if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<
"语文:"<<" "<<s[k]->chinese<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()<<endl;
}
break;
}
case '8':
{
int t;stu b;

cout<<"本系统所以学生语文排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->chinese)<(s[y]->chinese))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}

if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<
"语文:"<<" "<<s[k]->chinese<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()<<endl;
}
break;
}
case '9':
{
int t;stu b;

cout<<"本系统所以学生数学排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->math)<(s[y]->math))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}

if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<
"语文:"<<" "<<s[k]->chinese<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()<<endl;
}
break;
}
case 'y':
{
int t;stu b;

cout<<"本系统所以学生英语排名如下:"<<endl;
for(int x=0;x<i-1;x++)
{
t=x;
for(int y=x+1;y<i;y++)
{
if((s[t]->english)<(s[y]->english))
t=y;
if(t!=x)
{
b=*s[t];
*s[t]=*s[x];
*s[x]=b;
}
}
}

if(i==0)
cout<<"管理系统中没有录入数据或者数据已经被删除!";
for(int k=0;k<i;k++)
{
cout<<k+1<<" "<<"姓名:"<<" "<<s[k]->name<<
"语文:"<<" "<<s[k]->chinese<<"数学:"<<" "<<s[k]->math
<<"外语:"<<" "<<s[k]->english<<"总分:"<<" "<<s[k]->getsum()
<<"平均分:"<<" "<<s[k]->getaver()<<endl;
}
}
break;
}

cout<<"您想继续进行其他操作吗?(y/n)"<<endl;
bool flag4=0;
do
{
cin>>w;
if(w!='y'&&w!='n')
cout<<"指令错误!请重新输入!"<<endl;
else
flag4=1;
}while(flag4==0);
if(w=='y')
cout<<"请输入操作代码(0 录入/4 按总分查询/5 按姓名查询/1 增加人员/2 删除人员/3 修改数据/6 显示所有成员数据/7 按总分排名/8 按语文排名/9按数学排名/y按英语排名)"<<endl;
cin>>p;
}while(w=='y');
for(int x=0;x<i;x++)
{
delete s[x];
cout<<"delete all members!"<<endl;
}

}

参考资料:http://zhidao.baidu.com/question/29960627.html

温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-03-12
这里是C语言实现的
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>

void read_func(void);
void write_func(void);
void insert_func(void);
void sort_func(void);
void delete_func(void);
void display_func(void);
void modify_func(void);
void anykey_func(void);

struct student
{
char name[20];
int score;
struct student *next;
};

struct student *ptr, *head, *current, *prev;//全部声明为全局变量

int main(void)
{
char option1;

system("cls");//清屏
read_func();
while(1)
{
printf("****************************************\n");
printf(" 1.insert\n");
printf(" 2.delete\n");
printf(" 3.display\n");
printf(" 4.modify\n");
printf(" 5.quit\n");
printf("****************************************\n");
printf(" Please enter your choice (1-5)...");
option1=getche();
printf("\n");
switch(option1)
{
case '1':
insert_func();
break;
case '2':
delete_func();
break;
case '3':
display_func();
break;
case '4':
modify_func();
break;
case '5':
// write_func();
exit(0);//这里也处理的比较好
}
}
}

void read_func(void)
{
FILE *fptr;

head=(struct student *) malloc(sizeof(struct student));
head->next = NULL;

/* 开始时,若表中不存在数据,则要求输入第一笔数据 */
if((fptr=fopen("slist.dat","r")) == NULL)
{
printf(" Data file not exist\n");
printf(" Press any key to edit first record...\n");
getch();
insert_func();//不存在就实行插入操作
}
else
{
ptr=(struct student *) malloc(sizeof(struct student));
while(fscanf(fptr, "%s %d", ptr->name, &ptr->score) != EOF)
{
sort_func();
ptr=(struct student *) malloc(sizeof(struct student));
}
fclose(fptr);
}
}

void write_func(void)
{
FILE *fptr;

fptr=fopen("slist.dat","w");
current=head->next;
while(current != NULL)
{
fprintf(fptr, "%s %d\n", current->name, current->score);
current = current->next;
}
fclose(fptr);
}

void insert_func(void) //一插入就比较字符串(2 2想比较很简单) 不是等到全部插完了才比较
{
char s_temp[4];
ptr=(struct student *) malloc(sizeof(struct student));
printf(" Student name : ");
gets(ptr->name);
printf(" Student score: ");
gets(s_temp);
ptr->score = atoi(s_temp);//把字符串转化为 整数 为什么不直接把成绩存在ptr->score ???

sort_func();
}

/*以分数高低由大到小排列*/
void sort_func(void)
{
//插入数据
prev = head;
current = head->next;
while ((current != NULL) && (current->score > ptr->score))
{
prev = current;
current = current->next;
}
ptr->next = current;
prev->next = ptr;
}

void delete_func(void)
{
char del_name[20];
printf(" Delete student name: ");
gets(del_name);

prev = head;
current = head->next;
while ((current != NULL) && (strcmp(current->name , del_name)!=0))//用到了strcmp 比较字符串
{
prev = current;
current = current->next;
}
if (current != NULL)
{
prev->next = current->next;
free(current);
printf(" %s student record deleted\n",del_name);
}
else
printf(" Student %s not found\n",del_name);

anykey_func();
}

void modify_func(void)
{
char n_temp[20],s_temp[4];
printf(" Modify student name: ");
gets(n_temp);//这样输入姓名
current=head->next;

while ((current != NULL) && (strcmp(current->name , n_temp)!=0))
{
prev = current;
current = current->next;
}
if (current != NULL)
{
printf(" **************************\n");
printf(" Student name : %s\n",current->name);
printf(" Student score: %d\n",current->score);
printf(" **************************\n");
printf(" Please enter new score: ");
gets(s_temp);
current->score = atoi(s_temp);
printf(" %s student record modified\n",n_temp);
}
else
printf(" Student %s not found\n",n_temp);

anykey_func();
}

void display_func(void)
{
int count=0;
system("cls");
if(head->next == NULL)
{
printf(" No student record\n");
}
else
{
printf(" NAME SCORE\n");
printf(" ---------------------------\n");
current=head->next;
while(current != NULL)
{
printf(" %-20s %3d\n", current->name, current->score);
count++;
current=current->next;
if(count % 20 == 0) getch();
}
printf(" ---------------------------\n");
printf(" Total %d record(s) found\n", count);
}
anykey_func();
}

void anykey_func(void)//任何键继续
{
printf(" Press any key to continue...");
getch();
printf("\n");
}本回答被提问者采纳
第2个回答  2009-03-10
c语言源程序