当前位置:首页 » 考试成绩 » c语言课程设计学生成绩

c语言课程设计学生成绩

发布时间: 2021-03-03 14:18:11

㈠ C语言课程设计 学生成绩统计

http://wenku..com/view/92d3d138376baf1ffc4fad1a.html
我的文库里面有
我以前的实训

看你分这么高,给你做了个(可以正确运行),最近好多人找我要,是不是都是你们班的呀
#include<stdio.h>
#include<string.h>

struct Student {
char name[20];
int serial;
int scores[5];
};
main()
{
char ch,temp;
FILE *fpstu;
struct Student stu;
int i,sum=0;
float average;
printf("是否进行成绩录入(Y/N):");
ch=getchar();
temp=getchar();
if((fpstu=fopen("students.txt","a+"))==NULL)
{
printf("file open students.txt failed!\n");
system("pause");
exit(0);
}
if(ch=='Y' || ch=='y')
{
printf("姓名:");
scanf("%s",stu.name);
printf("学号:");
scanf("%d",&stu.serial);
for(i=0;i<5;i++)
{
printf("课程%d分数:",i+1);
scanf("%d",&stu.scores[i]);
}
printf("输入完毕!\n");
if(fwrite(&stu,sizeof(struct Student),1,fpstu)!=1)
{
printf("存盘失败!\n");
system("pause");
exit(0);
}
else
printf("存盘完毕!\n");
}
rewind(fpstu);
printf("姓名\t学号\t课程1\t课程2\t课程3\t课程4\t课程5\t总分\t平均\n");
while(!feof(fpstu))
{
if(fread(&stu,sizeof(struct Student),1,fpstu)!=1)
{
printf("读取完毕!\n");
system("pause");
exit(0);
}
printf("%s\t%d\t",stu.name,stu.serial);
sum = 0;
for (i = 0; i < 5; i++)
{
if(stu.scores[i] >= 90)
temp = 'A';
else if(stu.scores[i] >= 80)
temp = 'B';
else if(stu.scores[i] >= 70)
temp = 'C';
else if(stu.scores[i] >= 60)
temp = 'D';
else
temp = 'E';
printf("%c\t",temp);
sum += stu.scores[i];
}
average = (float)sum / 5;
printf("%d\t%f\n",sum,average);
}
}

㈡ C语言课程设计学生成绩统计

# include <iostream>
# include <fstream>
# include <string.h>
#include <conio.h>//用getch();
using namespace std;

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌Student类﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
class Student
{
public:
char name[20];
char Id[20];
int MTnum; //数学课程得分
int ENnum; //英语课程得分
int PHnum; //物理课程得分
int sum; //总分
Student * Next;
void Input()
{
cout<<"\t\t请输入学生的姓名:"; cin>>name;
cout<<"\t\t请输入学生的学号:"; cin>>Id;
cout<<"\t\t请输入数学课程的成绩:"; cin>>MTnum;
cout<<"\t\t请输入英语课程的成绩:"; cin>>ENnum;
cout<<"\t\t请输入物理课程的成绩:"; cin>>PHnum;
sum=MTnum+ENnum+PHnum;
}
void ReadFile(istream & in)
{
in>>name>>Id>>MTnum>>ENnum>>PHnum>>sum;
}
void Show()
{
cout<<"姓名:"<<name<<endl<<"学号:"<<Id<<endl<<"C++:"<<MTnum<<endl
<<"数学:"<<ENnum<<endl<<"外语:"<<PHnum<<endl<<"总成

绩:"<<sum<<endl<<endl<<endl;
}
};

//﹌﹌﹌﹌﹌﹌﹌﹌﹌Studentmassage类﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
class Studentmassage
{
public:
Studentmassage();
~Studentmassage();
void ShowMenu();
void Find();
void Save();
void ModifyItem();
void RemoveItem();
void Swap(Student *,Student *);
void Sort();
//void Unpass();
int ListCount();
//void Average();
void Display()
{
for(Student * p=Head->Next;p!=End;p=p->Next)
p->Show();
cout<<"输入任意字符!继续……";
getch();
}
void AddItem()
{
End->Input();
End->Next=new Student;
End=End->Next;
cout<<"添加成功!"<<endl;
cout<<"输入任意字符!继续……";
getch();
}
private:
Student * Head,* End;
ifstream in;
ofstream out;
Student *FindItem(char * name)
{
for(Student * p=Head;p->Next!=End;p=p->Next)//匹配成功则返回上一个指针,

不成功就返回空
if(!strcmp(p->Next->name,name))return p;
return NULL;
}
Student *FindID(char * Id)
{
for(Student * p=Head;p->Next!=End;p=p->Next)//匹配成功则返回上一个指针,

不成功就返回空
if(!strcmp(p->Next->Id,Id))return p;
return NULL;
}
};

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌构造函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
Studentmassage::Studentmassage()
{
Head=new Student;
Head->Next=new Student;
End=Head->Next;
in.open("sort.txt");
if(!in)
cout<<"这是一个新系统,无学生信息。请先输入。"<<endl;
else
{
while(!in.eof())
{
End->ReadFile(in);
if(End->name[0]=='\0')break;
End->Next=new Student;
End=End->Next;
}
in.close();
cout<<"\t\t读取学生信息成功!"<<endl;
}
}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌析构函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
Studentmassage::~Studentmassage()
{
Save();
for(Student * temp;Head->Next!=End;)
{
temp=Head->Next;
Head->Next=Head->Next->Next;
delete temp;
}
delete Head,End;
}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌菜单﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::ShowMenu()
{
cout<<"〓〓〓〓〓〓〓〓〓〓 ☆ 学 生 成 绩 管 理 系 统 ☆ 〓〓〓〓〓〓〓〓〓

〓"<<endl;
cout<<"〓〓〓〓〓〓〓★★★★★ ★★★★★★★ ★★★★★〓〓〓〓〓〓

〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 1.增加学生成绩 ☆ ★〓〓〓〓〓〓〓〓

〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 2.显示学生成绩 ☆ ★〓〓〓〓〓〓〓〓

〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 3.排序统计成绩 ☆ ★〓〓〓〓〓〓〓〓

〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 4.查找学生成绩 ☆ ★〓〓〓〓〓〓〓〓

〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 5.删除学生成绩 ☆ ★〓〓〓〓〓〓〓〓

〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 6.修改学生信息 ☆ ★〓〓〓〓〓〓〓〓

〓"<<endl;
cout<<"〓〓〓〓〓〓〓〓〓★ ☆ 0.安全退出系统 ☆ ★〓〓〓〓〓〓〓〓

〓"<<endl;

cout<<"\n\t\t\n\t\t请选择:";
}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌查找函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::Find()
{
char name[20] ,Id[10];
int x;
Student * p=NULL;
cout<<"\n\t\t*********************************\n";
cout<<"\t\t※ 1.按学生的姓名查找\n\t\t※ 2.按学生学号查找";
cout<<"\n\t\t*********************************\n请选择:";
cin>>x;
switch(x)
{
case 1:{cout<<"\t\t请输入要查找的学生的姓名:";cin>>name;
if(p=FindItem(name))
{
p->Next->Show();
cout<<"输入任意字符!继续……";
getch();
}
else
{
cout<<"\t\t没有找到该姓名的学生!"<<'\n'<<endl;
cout<<"输入任意字符!继续……";
getch();
}
}break;
case 2:
{
cout<<"\t\t请输入要查找的学生的学号:";cin>>Id;
if(p=FindID(Id))
{
p->Next->Show();
cout<<"输入任意字符!继续……";
getch();
}
else
{
cout<<"\t\t没有找到该学好的学生!"<<'\n'<<endl;
cout<<"输入任意字符!继续……";
getch();
}
}break;
}

}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌修改信息﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::ModifyItem() //修改信息
{
char name[20];
Student * p=NULL;
cout<<"\t\t请输入要修改的人的姓名:";cin>>name;
if(p=FindItem(name))
{
cout<<"\t\t已找到学生的信息,请输入新的信息!"<<endl;
p->Next->Input();
cout<<"修改成功!"<<endl;
cout<<"输入任意字符!继续……";
getch();
}
else
{
cout<<"\t\t没有找到!"<<endl;
cout<<"输入任意字符!继续……";
getch();
}
}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌删除信息﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::RemoveItem() // 删除信息
{
char name[20];
Student * p=NULL,*temp=NULL;
cout<<"\t\t请输入要删除的学生的姓名:"<<endl;cin>>name;
if(p=FindItem(name))
{
temp=p->Next;
p->Next=p->Next->Next;
delete temp;
cout<<"\t\t删除成功!"<<endl;
cout<<"输入任意字符!继续……";
getch();
}
else
{
cout<<"\t\t没有找到!"<<endl;
cout<<"输入任意字符!继续……";
getch();
}
}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::Swap(Student *p1, Student *p2)//交换两个combox变量的数据域
{
Student *temp=new Student;
strcpy(temp->name,p1->name);
strcpy(temp->Id,p1->Id);
temp->MTnum=p1->MTnum;
temp->ENnum=p1->ENnum;
temp->PHnum=p1->PHnum;
temp->sum=p1->sum;

strcpy(p1->name,p2->name);
strcpy(p1->Id,p2->Id);
p1->MTnum=p2->MTnum;
p1->ENnum=p2->ENnum;
p1->PHnum=p2->PHnum;
p1->sum=p2->sum;

strcpy(p2->name,temp->name);
strcpy(p2->Id,temp->Id);
p2->MTnum=temp->MTnum;
p2->ENnum=temp->ENnum;
p2->PHnum=temp->PHnum;
p2->sum=temp->sum;
}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
int Studentmassage::ListCount()//统计当前链表的记录总数,返回一个整数
{
if(! Head)
return 0;
int n=0;
for(Student * p=Head->Next;p!=End;p=p->Next)
{
n++;
}
return n;
}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::Sort()//对当前链表进行排序
{
cout <<"Sorting..."<<endl;
Student *p=NULL,*p1=NULL,*k=NULL;
int n=Studentmassage::ListCount();
if(n<2)
return;
for(p=Head->Next;p!=End;p=p->Next)
for(k=p->Next;k!=End;k=k->Next)
{
if(p->sum>k->sum)
{
Studentmassage::Swap(p,k);
}
}
cout <<"排序完成!"<<endl;
getch();
return;
}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌保存函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
void Studentmassage::Save()
{
out.open("sort.txt");
for(Student *p=Head->Next;p!=End;p=p->Next)
out<<p->name<<"\t"<<p->Id<<"\t"<<p->MTnum<<"\t"
<<p->ENnum<<"\t"<<p->PHnum<<"\t"<<p->sum<<'\n';
out.close();
}

//﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌主函数﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌﹌
int main()
{
int x,i=0;
bool quit=false;
cout<<"\t\t§§§§§§§§§§§§§§§§§§§§§§§§§§"<<endl;
for(i=0;i<3;i++)
cout<<"\t\t◎\t\t\t\t\t\t ◎"<<endl;
cout<<"\t\t◎★★★★【 欢迎进入学生成绩管理系统 】★★★★◎"<<endl;
for(i=0;i<3;i++)
cout<<"\t\t◎\t\t\t\t\t\t ◎"<<endl;
cout<<"\t\t§§§§§§§§§§§§§§§§§§§§§§§§§§\n"<<endl;;
Studentmassage Grade;
cout<<"按任意键开始……";
getch();
while(!quit)
{
system("cls");
Grade.ShowMenu();
cin>>x;
switch(x)
{
case 0:quit=true;break;
case 1:Grade.AddItem();break;
case 2:Grade.Display();break;
case 3:Grade.Sort();break;
case 4:Grade.Find();break;
case 5:Grade.RemoveItem();break;
case 6:Grade.ModifyItem();break;
}
}
return 0;
}

㈢ C语言课程设计 学生成绩管理系统 详情如下

结构体和相应操作稍加修改就是你那个 改下细节就能用
#include<iostream>
#include<string.h>
#include<iomanip>
#include<conio.h>
#include <stdlib.h>
using namespace std;
#define NULL 0
struct student
{
char name[30]; //姓名
char sex[30]; //性别
int num; //学号
int age; //年龄
double test_chinese; //语文成绩
double test_math; //数学成绩
double date; //总成绩
struct student *next;
};
student *put_information(student *); //创建学生信息库
student *del_information(student *); //删除学生信息
student *insert_information(student *); //添加学生信息
student *search_name(student *); // 按姓名查找学生信息
student *search_num(student *) ; //按学号查找
student *test_totol(student *); ////总体成绩
student *order(student *); // 排名
student *print_information(student *); //查看信息
int n;
int main()
{
int enternum;
student *head;
head=NULL;
cout<<"********************************************************************************"<<endl;

cout<<" 欢迎使用学生管理系统 "<<endl;

cout<<"********************************************************************************"<<endl;
cout<<" 按任意键执行主菜单! "<<endl;
getch();

while(1)
{
cout<<"***********************************主菜单*************************************"<<endl;
cout<<" 0键退出 "<<endl;
cout<<" 1键输入学生信息 "<<endl;
cout<<" 2键输出学习信息 "<<endl;
cout<<" 3键删除学生信息 "<<endl;
cout<<" 4键添加学生信息 "<<endl;
cout<<" 5键按姓名查找学生信息 "<<endl;
cout<<" 6键按学号查找学生信息 "<<endl;
cout<<" 7键查看学生总体成绩 "<<endl;
cout<<" 8键查看排名 "<<endl;
cin>>enternum;
switch(enternum)
{
case(0):cout<<"************************************************************************"<<endl;
cout<<endl;
cout<<" 谢谢使用高校学籍管理系统 "<<endl;
cout<<endl;
cout<<"************************************************************************"<<endl;
exit(0);
case(1):head=put_information(head);
break;
case(2):print_information(head);
break;
case(3):head=del_information(head);
break;
case(4):head=insert_information(head);
break;
case(5):head=search_name(head);
break;
case(6):head=search_num(head);
break;
case(7):head=test_totol(head);
break;
case(8):head=order(head);
break;
default:cout<<" 对不起,你只能输入0~7键,请重新输入 "<<endl;
break;
}
}
return 0;
}

student *put_information(student *head) ////////信息输入函数
{
student *p1,*p2;
int N, choose;
if(head!=NULL)
{
cout<<"你已经输入信息,如果还想输入,请进入添加信息项添加信息"<<endl;
return (head);
}
cout<<"输入你想输入学生信息的个数:";
cin>>N;
n=0;
head=NULL;
p1=p2=new student;
while(n<N)
{
n=n+1;
p1=new student; ///////开辟一个空间
cout<<"请输入第"<<n<<"个学生的信息:"<<endl;
{
cout<<" 姓名:";
cin>>p1->name;
loop: cout<<" 性别(1 男,2 女):";
cin>>choose;
switch(choose)
{
case(1):
strcpy(p1->sex,"男");break;
case(2):
strcpy(p1->sex,"女");break;
default:
cout<<"你的只能输入1或2,请重新输入!!!!";
goto loop;
}
cout<<" 学号:";
cin>>p1->num;
cout<<" 年龄:";
cin>>p1->age;
cout<<"语文成绩:";
cin>>p1->test_chinese;
cout<<"数学成绩:";
cin>>p1->test_math;
}
if(n==1)
{
head=p1;
}
else
{
p2->next=p1;
}
p2=p1;
}
p2->next=NULL;
cout<<"*******************************************************************************"<<endl;
cout<<endl;
cout<<" 你已经成功的输入了"<<N<<"个人的信息 "<<endl;
cout<<endl;
cout<<"*******************************************************************************"<<endl;
cout<<endl;
return (head);
}
student *del_information(student *head) //删除信息函数
{
char del_name[30]; //你想要删除学生的姓名
int input;
student *p1,*p2;
if (head==NULL) //没输入数据
{
cout<<"对不起,你还没输入学生的信息!"<<endl;
return(head);
}
else
{
p1=head; //使p1指向第一个结点
loop: cout<<"请输入你要删除该学生的姓名:";
cin>>del_name;
while(strcmp(p1->name,del_name)!=0&&p1->next!=NULL) //输入的姓名没找到且还有结点
{
p2=p1;
p1=p1->next; //p1后移一个结点
}
if(strcmp(del_name,p1->name)==0) //找到要删除的学生的信息
{
{
if(p1==head) head=p1->next; //若p1指向的是首结点,把第二个结点地址赋予head
else p2->next=p1->next; //否则将下一结点地址赋给前一结点地址
cout<<"***************************************************"<<endl;
cout<<" 删除成功,你删除的学生信息为: "<<endl;
cout<<" 姓名:" <<p1->name<<endl;
cout<<" 学号:" <<p1->num<<endl;
cout<<" 性别:" <<p1->sex<<endl;
cout<<" 年龄:" <<p1->age<<endl;
cout<<" 语文成绩:" <<p1->test_chinese<<endl;
cout<<" 数学成绩:" <<p1->test_math<<endl;
cout<<"***************************************************"<<endl;
n=n-1;
}
LOOP:cout<<"你是否想继续删除学生的信息(1继续,2返回主菜单)"<<endl;
cin>>input;
switch(input)
{
case(1):goto loop;
case(2):break;
default:cout<<"你只能输入1或2,请重新输入!"<<endl;
goto LOOP;
}
}
else
{
cout<<" 找不到 "<<del_name<<"的信息,请重新输入 "<<endl; //找不到信息
goto loop;
}
}
return(head);
}
student *insert_information(student *head) //添加信息函数
{
student *p1,*p2,*p;
int N=0;
head=NULL;
p=new student;
p1=p2=head;

cout<<"请输入添加到的位置(学号)"<<endl;
cin>>p->num;
cout<<"请输入添加学生的信息"<<endl;
{
cout<<" 姓名:";
cin>>p->name;
cout<<" 性别:";
cin>>p->sex;
cout<<" 年龄:";
cin>>p->age;
cout<<"语文成绩:";
cin>>p->test_chinese;
cout<<"数学成绩:";
cin>>p->test_math;
}
while(p1!=0)
{
p2=p1;
p1=p1->next;
}
if(head=NULL)
{
head=p;
p->next=NULL;
N++;
}
else
{
if(p->num==head->num)
{
p=head;
while(head!=NULL)
{
head=head->next;
head->num++;
}
N++;
}
else if(p->num==p1->num&&p->num!=head->num)
{
p2->next=p;
p->next=p1;
while(p1!=NULL)
{
p1->num++;
}
N++;
}
else if(p->num==(p1->num+1)&&p->next==NULL)
{
p=p1->next;
}
}
return (head);
}
student *search_name(student *head) //按姓名查找学生信息函数
{
student *p1,*p2;
int enternum1;
char find_name[30]; //按姓名查找所要输入的姓名
if(head==NULL) //为空表
{
cout<<"你还没输入该学生的信息,请返回输入!"<<endl;
return (head);
}
else
{
p1=head;
begin: cout<<"请输入你要查找学生的姓名:";
cin>>find_name;
while(strcmp(find_name,p1->name)!=0&&p1->next!=NULL) ///////输入的的姓名与已有的数据不同且后面还有学生信息
{
p2=p1;
p1=p1->next; // P1向后移一个节点
}
{
if(strcmp(find_name,p1->name)==0) ///找到了
{
cout<<"***************************************************"<<endl;
cout<<" 删除成功,你查找的学生信息为: "<<endl;
cout<<" 姓名:" <<p1->name<<endl;
cout<<" 学号:" <<p1->num<<endl;
cout<<" 性别:" <<p1->sex<<endl;
cout<<" 年龄:" <<p1->age<<endl;
cout<<" 语文成绩:" <<p1->test_chinese<<endl;
cout<<" 数学成绩:" <<p1->test_math<<endl;
cout<<"***************************************************"<<endl;
hand: cout<<" 是否继续删除(1继续2返回主菜单)";
cin>>enternum1;
switch(enternum1)
{
case(1):
goto begin;
case(2):
break;
default:
cout<<"你只能输入1或2,请重新输入!"<<endl;
goto hand;
}
}
else cout<<"**************学生信息库没该学生的信息!***********"<<endl;
}
}
return(head);
}
student *search_num(student *head)
{
student *p1,*p2;
int enternum2,find_num;
if(head==NULL) //为空表
{
cout<<"你还没输入该学生的信息,请返回输入!"<<endl;
return(head);
}
else
{
p1=head;
begin: cout<<"请输入你要查找学生的学号:";
cin>>find_num;
while(find_num!=p1->num&&p1->next!=NULL) ///////输入的的数与已有的数不同且后面还有学生信息
{
p2=p1;
p1=p1->next; //P1向后移一个节点
}
{
if(find_num==p1->num) /////如果找到了
{
cout<<"***************************************************"<<endl;
cout<<" 你查找的学生信息为: "<<endl;
cout<<" 姓名:" <<p1->name<<endl;
cout<<" 学号:" <<p1->num<<endl;
cout<<" 性别:" <<p1->sex<<endl;
cout<<" 年龄:" <<p1->age<<endl;
cout<<" 语文成绩:" <<p1->test_chinese<<endl;
cout<<" 数学成绩:" <<p1->test_math<<endl;
cout<<"***************************************************"<<endl;
hand: cout<<"按1键继续输入2键返回主菜单!"<<endl;
cin>>enternum2;
switch(enternum2)
{
case(1):
goto begin;break;
case(2):
break;
default:
cout<<"你只能输入1或2,请重新输入!"<<endl;
goto hand;break;
}
}
else cout<<"************学生信息库没该学生的信息!*********"<<endl;
}
}
return (head);
}
student *test_totol(student *head) //求学生总成绩,平均成绩和及格率
{
student *p1 ;
int pass1=0,pass2=0; //及格人数
double sum1=0,sum2=0,mean1,mean2,pass_rate1,pass_rate2;
if(head==NULL)
{
cout<<"对不起,你还没输入学生信息,请返回输入!"<<endl; //空表
return (head);
}
else
{
p1=head;
while(p1!=NULL)
{
sum1+=p1->test_chinese;
sum2+=p1->test_math;
if(p1->test_chinese>=60)pass1++;
if(p1->test_math>=60)pass2++;
p1=p1->next;
}
mean1=1.0*sum1/n;
mean2=1.0*sum2/n;
pass_rate1=(pass1/n)*100;
pass_rate2=(pass2/n)*100;
cout<<"*******************************************************"<<endl;
cout<<" 语文的平均成绩为: "<<mean1 <<endl;
cout<<" 语文的及格率为: "<<pass_rate1<<"%"<<endl;
cout<<"*******************************************************"<<endl;
cout<<" 数学的平均成绩为: "<<mean2 <<endl;
cout<<" 数学的及格率为: "<<pass_rate2<<"%"<<endl;
cout<<"*******************************************************"<<endl;
}
return (head);
}
student *order(student *head)
{
student *p,*q,*tail,*s;

int i=0;
tail=NULL;
while(head->next!=tail)
{
p=head;
p->date=p->test_chinese+p->test_math;
p->next->date=p->next->test_chinese+p->next->test_math;
q=p->next;
while(q->next!=tail)
{
if(p->next->date>q->next->date)
{
s=q->next;
p->next=q->next;
q->next=q->next->next;
p->next->next=q;
q=s;
}
p=p->next;
q=q->next;
}
tail=q;
cout<<"______________________________________"<<endl;
cout<<setw(8)<<"姓名"<<setw(8)<<"总分"<<setw(10)<<"名次"<<endl;
while(p!=NULL)
{
++i;
cout<<"______________________________________"<<endl;
cout<<setw(8)<<p->name<<setw(8)<<p->date<<setw(8)<<"第"<<i<<"名"<<endl;
p=p->next;
}
cout<<"______________________________________"<<endl;
}
return (head);
}
student *print_information(student *head) //查看信息函数
{
student *p1;
if(head==NULL)
{
cout<<"对不起,你还没输入学生信息,请返回输入!"<<endl;
return (head);
}
else
p1=head;
cout<<"____________________________________________________________________________"<<endl;
cout<<setw(8)<<"姓名"<<"|"<<setw(8)<<"学号"<<"|"<<setw(8)<<"性别"<<"|"<<setw(8)
<<"年龄"<<"|"<<setw(8)<<"语文成绩"<<"|"<<setw(8)<<"数学成绩"<<"|"<<endl;
cout<<"____________________________________________________________________________"<<endl;
while(p1!=NULL)
{
cout<<setw(8)<<p1->name<<"|"
<<setw(8)<<p1->num<<"|"
<<setw(8)<<p1->sex<<"|"
<<setw(8)<<p1->age<<"|"
<<setw(8)<<p1->test_chinese<<"|"
<<setw(8)<<p1->test_math<<"|"<<endl;
cout<<"____________________________________________________________________________"<<endl;
p1=p1->next;
}
return (head);
}

㈣ c语言课程设计之学生成绩管理系统设计的程序

#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include<string.h>

#define MAX 80
#define max 3

int nu=0;

struct classname
{
char name[20];
float score;
};

struct student
{
char no[20];
char std_name[20];
struct classname km[max];
float ave;
float sum;
int save;
};

struct student stu[MAX],*p;

void chushi()
{
int i,j;
for(i=0;i<MAX;i++)
{
for(j=0;j<20;j++)
{
stu[i].no[j]=NULL;
stu[i].std_name[j]=NULL;
stu[i].km[j].name[j]=NULL;
stu[i].km[j].score=0;
}
stu[i].ave=0;
stu[i].sum=0;
stu[i].save=0;
}
}

void av()/*求平均值*/
{
int i;
for(i=0;i<nu;i++)
{
stu[i].sum=stu[i].km[1].score+stu[i].km[2].score+stu[i].km[3].score;
stu[i].ave=stu[i].sum/3;
}
}

void first_check()
{
FILE *p;
int i,j;
struct classname frist[max];
for(i=0;i<max;i++)
{
for(j=0;j<20;j++)
frist[i].name[j]=NULL;
frist[i].score=0;
}
if ((p=fopen("c:\\kemu.txt","r"))==NULL)
{
printf("您好,欢迎使用学生成绩管理系统\n\n因为您是第一次使用,请输入科目名称(三科)\n\n");
p=fopen("c:\\kemu.txt","w");
printf("输入课程1名称:");
scanf("%s",frist[0].name);
fprintf(p,"%s\n",frist[0].name);
printf("输入课程2名称:");
scanf("%s",frist[1].name);
fprintf(p,"%s\n",frist[1].name);
printf("输入课程3名称:");
scanf("%s",frist[2].name);
fprintf(p,"%s\n",frist[2].name);
}
system("cls");
fclose(p);
}

void save_nu()
{
FILE *p;
p=fopen("c:\\renshu.txt","w");
fprintf(p,"%d\n",nu);
fclose(p);
}

void Save_add(int n)
{
FILE * p;
int i;
p= fopen("c:\\cheji.txt","at");
if (p == NULL)
{
printf("文件不存在!!\n");
exit(0);
}
save_nu();
for (i = 0;i<n;i++)
if(stu[i].save==1)
{
stu[i].sum=stu[i].km[1].score+stu[i].km[2].score+stu[i].km[3].score;
stu[i].ave=stu[i].sum/3;
fprintf(p,"%s %s %2.1f %2.1f %2.1f %2.1f %2.1f \n",stu[i].no,stu[i].std_name,stu[i].km[0].score,stu[i].km[1].score,stu[i].km[2].score,stu[i].ave,stu[i].sum);
}
fclose(p);
}

void Save()
{
FILE * p;
int i;
p= fopen("c:\\cheji.txt","w");
if (p == NULL)
{
printf("文件不存在!!\n");
exit(0);
}
save_nu();
for (i = 0;i<nu;i++)
if(stu[i].save==1)
{
av();
fprintf(p,"%s %s %2.1f %2.1f %2.1f %2.1f %2.1f \n",stu[i].no,stu[i].std_name,stu[i].km[0].score,stu[i].km[1].score,stu[i].km[2].score,stu[i].ave,stu[i].sum);
}
fclose(p);
}

int read_nu()
{
FILE *p;
char ch,s[10]={'\0'};
int i=0;
p=fopen("c:\\renshu.txt","r");
if(p==NULL)
{
save_nu();
return 0;
}
ch=fgetc(p);
while(ch!='\n')
{
s[i]=ch;
ch=fgetc(p);
i++;
}
nu=atoi(s);
fclose(p);
return 0;
}

int read_km()
{
FILE *p;
int i,j=0;
char s[20]={'\0'};
chushi();
p=fopen("c:\\kemu.txt","r");
if(p==NULL)
{
printf("ERROR read_km");
return 0;
}
fgets(s,20,p);
while(strlen(s)!=0)
{
for(i=0;i<strlen(s);i++)
if(s[i]==10)
{
s[i]='\0';
break;
}
for(i=0;i<=nu;i++)
strcpy(stu[i].km[j].name,s);
for(i=0;i<20;i++)
s[i]='\0';
j++;
fgets(s,20,p);
}
}

void read()
{
FILE *p;
int i,j,n,k,z=0;
char s[50]={'\0'};
char o[10]={'\0'};
p=fopen("c:\\cheji.txt","r");
if(p==NULL)
printf("ERROR_read");
chushi();
read_km();
fgets(s,50,p);
while(strlen(s)!=0)
{
j=0;
for(i=0;i<50;i++)
{
if(s[i]!='\n')
{
n=0;
while(j==0)
{
if(s[i]!=' ')
{
stu[z].no[n]=s[i];
n++;i++;
}
else
break;
}
while(j==1)
{
if(s[i]!=' ')
{
stu[z].std_name[n]=s[i];
n++;i++;
}
else
break;
}
while(j==2)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[0].score=atoi(o);
break;
}
}
while(j==3)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[1].score=atoi(o);
break;
}
}
while(j==4)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[2].score=atoi(o);
break;
}
}
while(j==5)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].ave=atoi(o);
break;
}
}
while(j==6)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].sum=atoi(o);
break;
}
}
for(k=0;k<10;k++)
o[k]='\0';
}
else
break;
j++;
}
for(i=0;i<50;i++)
s[i]='\0';
fgets(s,50,p);
z++;
}
}

void putin()
{
int n,i=0;
char ch;
read_km();
do
{
printf("\t\t\t\t录入学员信息\n输入第%d个学员的信息\n",i+1);
printf("\n输入学生编号:");
scanf("%s",stu[i].no);
printf("\n输入学员姓名:");
scanf("%s",stu[i].std_name);
printf("\n输入课程%s的分数:",stu[0].km[0].name);
scanf("%f",&stu[i].km[0].score);
printf("\n输入课程%s的分数:",stu[0].km[1].name);
scanf("%f",&stu[i].km[1].score);
printf("\n输入课程%s的分数:",stu[0].km[2].name);
scanf("%f",&stu[i].km[2].score);
stu[i].save=1;
printf("\n\n");
i++;
n=i;
printf("是否继续输入?(Y/N)");
fflush(stdin);
ch=getch();
system("cls");
}
while(ch!='n'&&ch!='N');
system("cls");
if(nu==0)
{
nu=n;
Save();
}
else
{
nu=n+nu;
Save_add(n);
}
}

int putout()
{
int i;char s;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
read();
do
{
printf("学生成绩信息:\n\n");
for(i=0;i<nu;i++)
printf("学号:%s 姓名:%s\n%s分数:%2.1f\t%s分数:%2.1f\t%s分数:%2.1f\n平均分数:%2.1f\t总成绩:%2.1f\n\n",stu[i].no,stu[i].std_name,stu[i].km[0].name,stu[i].km[0].score,stu[i].km[1].name,stu[i].km[1].score,stu[i].km[2].name,stu[i].km[2].score,stu[i].ave,stu[i].sum);
printf("\t\t按任意键返回主菜单");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
}

int sort()/*排序数据函数*/
{
struct student temp;
int i,j;
char s;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
chushi();
read();
for(i=1;i<nu;i++)
{
for(j=1;j<=nu-i;j++)
{
if(stu[j-1].ave<stu[j].ave)
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
}
}
}
do
{
printf("学生成绩信息:\n\n");
for(i=0;i<nu;i++)
printf("学号:%s 姓名:%s 平均成绩:%2.1f\n\n",stu[i].no,stu[i].std_name,stu[i].ave);
printf("\t\t按任意键返回主菜单");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
}

void find()/*查询函数*/
{
int j,i=0;
int c=0;
char search[10]={'\0'};
char as;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
chushi();
read();
do
{
printf("输入要查询课程名称:");
scanf("%s",search);
for(j=0;j<max;j++)
if(!strcmp(stu[i].km[j].name,search))
{
c=1;
printf("\n该课程不及格学生姓名:\n");
for(i=0;i<nu;i++)
if(stu[i].km[j].score<60)
printf("%s\n",stu[i].std_name);
}
if(c==0)
printf("无此课程!");
printf("\n\t\t按任意键返回主菜单");
fflush(stdin);
as=getch();
}
while(!as);
system("cls");
}

void tongji()
{
int j,m,z,i=0;
char s;
if(nu==0)
{
printf("学生信息为零!请录入...");
return 0;
}
chushi();
read();
for(z=0;z<max;z++)
{
m=stu[i].km[z].score;j=0;
printf("%s 最高分: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(m<stu[i].km[z].score)
{
m=stu[i].km[z].score;
j=i;
}
printf("%s\t",stu[j].std_name);
j=0;i=0;m=stu[i].km[z].score;
printf("%s 最低分: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(m>stu[i].km[z].score)
{
m=stu[i].km[z].score;
j=i;
}
printf("%s\t",stu[j].std_name);
m=0;j=0;i=0;
printf("%s 平均分: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
m=m+stu[i].km[z].score;
printf("%d\n",m/nu);
m=0;i=0;
printf("%s 分数低于的60人数: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(stu[i].km[z].score<60)
m++;
printf("%d\t",m);
m=0;j=0;i=0;
printf("%s 分数高于60的人数: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(stu[i].km[z].score>60)
m++;
printf("%d\n\n",m);
}
do
{
printf("\t\t按任意键返回主菜单");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
}

void main()/*主函数*/
{
int as;
first_check();
start: printf("\n\t\t\t欢迎使用学生成绩管理系统\n");
/*一下为功能选择模块*/
do
{
printf("\n\t\t\t\t1.录入学员信息\n\t\t\t\t2.显示学员信息\n\t\t\t\t3.成绩排序信息\n\t\t\t\t4.查询不及格学生\n\t\t\t\t5.统计信息\n\t\t\t\t6.退出\n");
printf("\t\t\t\t选择功能选项:");
fflush(stdin);
read_nu();
scanf("%d",&as);
switch(as)
{
case 1:system("cls");putin();break;
case 2:system("cls");putout();break;
case 3:system("cls");sort();break;
case 4:system("cls");find();break;
case 5:system("cls");tongji();break;
case 6:system("exit");exit(0);
default:system("cls");goto start;
}
}
while(1);
/*至此功能选择结束*/
}

㈤ C语言课程设计 学生成绩管理系统

楼主 ,留个邮箱,发给你一个本人自己写的....有什么问题可以问我啊......

㈥ c语言课程设计学生成绩管理系统

直接在网络上搜 有 你不必在提问了

㈦ c语言课程设计 学生成绩管理系统

我来帮你~\(≧▽≦)/~啦,请问问题解决了吗?

㈧ 求(C语言课程设计)学生成绩管理系统

#include "stdio.h"
#include "conio.h"
#include "string.h"
#include "stdlib.h"
#define CMD_START printf("\n\n######### Start a command #########\n");
/* 用来标记一个命令执行的开始 */
#define CMD_END printf( "\n######### End a command #########\n\n");
/* 用来标记一个命令执行的结束
,这两个语句是为了提供更好的用户界面而写的 */
#define DATA_FILE "data.dat"
/* 这是 数据文件名 */
#define TEMP_FILE "temp.dat"
/* 这是一个临时的文件的名字,在删除记录的函数中使用的,
详细内容参考 Delete() 函数 */
typedef struct tagStudent
{
char ID[30]; /* 学号 */
char Name[30]; /* 姓名 */
char Class[255]; /* 班级 */
char Sex; /* 性别 ,值为 F 或 f 或 M 或 m */
int Math; /* 数学成绩 */
int English; /* 英语成绩 */
int Compute; /* 计算机成绩 */
int Philosophy; /* 哲学成绩 */
int PE; /* 体育成绩 */
} Student;
/* 这是学生信息结构体 */
int ShowMenu(); /* 在屏幕上打印 主菜单

的函数,它的返回值为 所选
菜单的 项目编号 */
int ReadData(FILE *, Student *); /* 从一个
打开的数据文件中读取
记录的函数,错误返回 0 */
int WriteData(FILE *, Student *); /* 向一个数据文件中 写入
记录的函数,错误返回 0 */
void Output_Rec(Student *); /* 在屏幕上 打印 一条记录 */
void Input_Rec(Student *); /* 让用户输入 记录的 各个项目的
值,在添加记录时用到了 */
void CopyRec(Student *, Student *); /* 复制一条记录 到
另一个记录中 */
/* 题目中要求的函数 */
void Print(); /* 实现查看数据文件内容的函数 */
void Add(); /* 添加记录的函数 */
void Delete(); /* 删除记录的函数 */
void Statistics(); /* 对数据进行统计分析的函数 */
void Find(int); /* 实现查找功能的函数,参数决定
是按 ID 查找 还是按 Name 查找 */
int quit; /* 一个全局变量,在下面的 main()
函数中,用来决定何时退出主循环
*/
main()
{
int cmd; /* 用户所选的 菜单 项目 的标号 */
quit = 0; /* 初始化 为 不退出 */
/* 这是程序的主循环,每次都将 主菜单打印出来,
供用户选择相应的 序号 来执行相应的功能 */
while (!quit)
{
cmd = ShowMenu(); /* 显示
主菜单,并返回用户所选择的
菜单项 的 编号 */
CMD_START /* 在屏幕上打印一行分隔符,告诉用户这是一个子功能的开始
*/
switch (cmd) /* 用多项分支 根据 用户的选择
调用 相应的函数 */
{
case 1:
Print();
break; /* 用户选择 1 号菜单,程序执行
查看的数据文件的函数 */
case 2:
Add();
break; /* 用户选择 2 号菜单,程序执行
添加记录的函数 */
case 3:
Delete();
break; /* 用户选择 3 号菜单,程序执行
删除记录的函数 */
case 4:
Statistics();
break; /* 用户选择 4 号菜单,程序执行
统计数据的函数 */
case 5:
Find(5);
break; /* Find_ID ,5 号菜单执行 按
ID(学号)查找的功能 */
case 6:
Find(6);
break; /* Find_Name,6 号菜单执行 按
Name(姓名)查找的功能 */
case 7:
quit = 1; /* 用户选择了退出菜单 */
printf
(" Thank you for your using .\n\n Happy everyday !!\n\n Bye Bye ....\n");
break;
default:
printf(" Please Input a number between\t1\tto\t7.\n");
/* 用户所输入的 序号不在所处理的范围内 */
}
CMD_END /* 打印一行分隔符,告诉用户
他所选择的菜单的功能已经执行完毕
*/
if (quit != 1) /* 检查用户是否 要求 退出 */
{
printf(" Press any key to Return Main Menu ....\n");
getch(); /* 用 一个 无回显 的 字符输入函数
来实现暂停执行,按 任意键
继续的功能 */
}
}
}

int ShowMenu()
{
int cmd = 0; /* 保存用户的选择 */
/* 定义 程序所支持的菜单项目 */
char Menu_SeeData[] = "\t1 .\tView the Records in the data file\n"; /* 查看数据文件
*/
char Menu_Add[] = "\t2 .\tAdd New Record\n"; /* 添加记录 */
char Menu_Delete[] = "\t3 .\tDelete an old Record\n"; /* 删除记录 */
char Menu_Statistics[] = "\t4 .\tMake a Statistics\n"; /* 统计分析 */
char Menu_Find_ID[] = "\t5 .\tFind a Record from the ID\n"; /* 按
学号(ID)
查找 */
char Menu_Find_Name[] = "\t6 .\tFind a Record from the Name\n"; /* 按
姓名(Name)
查找 */
char Menu_Quit[] = "\t7 .\tQuit\n"; /* 退出 */
/* 在屏幕上打印 主菜单 */
printf("\n\n############ Main Menu ###############\n");
printf("##############################################\n\n");
printf(Menu_SeeData);
printf(Menu_Add);
printf(Menu_Delete);
printf(Menu_Statistics);
printf(Menu_Find_ID);
printf(Menu_Find_Name);
printf(Menu_Quit);
printf("\n##############################################");
printf("\n\n Input the index of your choice : ");
scanf("%d", &cmd); /* 接受用户 选择 */
printf("\n");
return cmd; /* 返回用户的输入,交给主循环处理
*/
}

void Print() /* 打印 数据文件的 记录内容 */
{
FILE *fp = NULL; /* 文件指针 */
Student rec; /* 存放从文件中读取的记录 */
int i = 0; /* 实现 计数 和 分屏打印的功能 */
fp = fopen(DATA_FILE, "rb"); /* 以 二进制读 方式
打开数据文件 */
if (fp == NULL) /* 打开文件出错 */
{
printf(" Can not open the data file : %s\n", DATA_FILE);
return;
}
while (ReadData(fp, &rec)) /* ReadData()
函数出错或到文件末尾时返回
0,可以做循环条件 */
{
Output_Rec(&rec); /* 正确读取,将记录输出 */
printf(" ------------------------------------------");
/* 打印一行分隔符,营造好的用户界面 */
i ; /* 计数器 加一 */
if (i % 4 == 0) /* 显示 4 个暂停一下 */
{
printf("\n Press any key to continue ... \n");
getch();
}
}
printf("\n The current data file have\t%d\trecord .\n", i);
fclose(fp); /* 关闭文件 */
}

void Add() /* 添加记录 */
{
Student rec;
FILE *fp = NULL;
Input_Rec(&rec); /* 让用户输入新记录的各项内容 */
fp = fopen(DATA_FILE, "ab"); /* 以 添加 方式打开数据文件 */
if (fp == NULL)
{
printf(" Can not open the data file to write into ... \n");
return;
}
if (WriteData(fp, &rec) == 1) /* 将 新记录 写入文件,并检查
是否正确写入 */
printf("\n\n Add New Record Success \n\n");
else
printf("\n\n Failed to Write New Record into the data file \n");
fclose(fp);
}

void Delete() /* 删除记录 */
{
Student rec;
FILE *fpr, *fpw; /* 两个文件指针,分别用于 读 和
写 */
char buf[30]; /* 接受 用户输入的 ID 缓冲区 */
char cmd[255]; /* 执行的系统命令 */
int del_count; /* 实际 删除的 记录数目 */
del_count = 0;
printf("\n Please type the ID of the record you want me to delete .");
printf("\n The ID : "); /* 提示用户 输入 */
scanf("%s", buf);
fpr = fopen(DATA_FILE, "rb"); /* 从
原来的记录文件中读取数据,跳过将要删除的记录
*/
if (fpr == NULL)
{
printf(" Can not open the data file to read record ... \n");
return;
}
fpw = fopen(TEMP_FILE, "wb"); /* 打开一个 临时文件
保存不删除的记录 */
if (fpw == NULL)
{
printf(" Can not open the data file to write into ... \n");
return;
}
while (ReadData(fpr, &rec)) /* 读取 要保留的记录 */
{
if (strcmp(rec.ID, buf) != 0)
{
WriteData(fpw, &rec); /* 写入临时文件 ,然后删除
原数据文件,
再将临时文件该名为原数据文件的名字
*/
}
else
{
del_count ; /* 跳过的记录数目,即删除的数目 */
}
}
fclose(fpr);
fclose(fpw);
strcpy(cmd, "del "); /* 构造命令串,用 system() 函数执行
*/
strcat(cmd, DATA_FILE);
system(cmd);
rename(TEMP_FILE, DATA_FILE); /* 直接调用 C
语言的改名函数将临时文件改名为数据文件的名字
*/
printf("\n I have delete\t%d\trecord .\n", del_count);
}

void Statistics() /* 统计分析函数 */
{
int i50, i60, i70, i80, i90; /* 平均分小于60
,60-69,70-79,80-89,>=90
的分数段的学生数目 */
float avg; /* 平均分 */
int sum, sum_high, sum_low; /* 总分,总分最高分,总分最低分 */
Student stu_high, stu_low; /* 总分最高和最低 学生的信息 */
Student stu_math_high, stu_english_high; /* 各科
最高分的学生记录副本
*/
Student stu_compute_high, stu_philosophy_high, stu_PE_high;
Student stu_math_low, stu_english_low; /* 各科最低的学生记录副本
*/
Student stu_compute_low, stu_philosophy_low, stu_PE_low;
FILE *fp;
Student rec;
int count; /* 一个计数器,用于判断是否第一次读取数据
*/
count = sum = sum_high = sum_low = i50 = i60 = i60 = i70 = i80 = i90 = 0;
fp = NULL; /* 对 数据初始化 */
fp = fopen(DATA_FILE, "rb");
if (fp == NULL)
{
printf("\nCan not open the data file to read ...\n");
return;
}
while (ReadData(fp, &rec)) /* 读取数据 */
{
count ; /* 计数器 加一 */
sum = rec.Math rec.English rec.Compute rec.PE rec.Philosophy; /* 求和
*/
/* average */
avg = ((float)sum) / 5; /* 平均分 */
/* 下面对各个分数段进行统计 */
if (avg < 60)
i50 ;
else if (avg < 70)
i60 ;
else if (avg < 80)
i70 ;
else if (avg < 90)
i80 ;
else
i90 ;
/* highest and loeest */
if (count <= 1) /* 第一次读取,执行初始化,不进行比较
*/
{
sum_high = sum_low = sum;
CopyRec(&stu_high, &rec);
CopyRec(&stu_low, &rec);
}
else
{
if (sum > sum_high)
{
sum_high = sum; /* 得到最高总分 */
CopyRec(&stu_high, &rec); /* 保存总分最高的学生的信息
*/
}
if (sum < sum_low)
{
sum_low = sum; /* 得到最低分 */
CopyRec(&stu_low, &rec); /* 保存总分最低的学生的信息
*/
}
}
/* subject highest and low */
if (count == 1) /* 同上面一样,执行初始化 */
{
CopyRec(&stu_math_high, &rec);
CopyRec(&stu_english_high, &rec);
CopyRec(&stu_compute_high, &rec);
CopyRec(&stu_philosophy_high, &rec);
CopyRec(&stu_PE_high, &rec);
CopyRec(&stu_math_low, &rec);
CopyRec(&stu_english_low, &rec);
CopyRec(&stu_compute_low, &rec);
CopyRec(&stu_philosophy_low, &rec);
CopyRec(&stu_PE_low, &rec);
}
else
{
/* High */
/* 保存各科的最高分的学生的信息 */
if (rec.Math > stu_math_high.Math)
CopyRec(&stu_math_high, &rec);
if (rec.English > stu_english_high.English)
CopyRec(&stu_english_high, &rec);
if (rec.Compute > stu_compute_high.Compute)
CopyRec(&stu_compute_high, &rec);
if (rec.Philosophy > stu_philosophy_high.Philosophy)
CopyRec(&stu_philosophy_high, &rec);
if (rec.PE > stu_PE_high.PE)
CopyRec(&stu_PE_high, &rec);
/* low */
/* 保存各科的最低分的学生的信息 */
if (rec.Math < stu_math_low.Math)
CopyRec(&stu_math_low, &rec);
if (rec.English < stu_english_low.English)
CopyRec(&stu_english_low, &rec);
if (rec.Compute < stu_compute_low.Compute)
CopyRec(&stu_compute_low, &rec);
if (rec.Philosophy < stu_philosophy_low.Philosophy)
CopyRec(&stu_philosophy_low, &rec);
if (rec.PE < stu_PE_low.PE)
CopyRec(&stu_PE_low, &rec);
}
} /* While End */
if (count < 1)
{
printf("\n There is no record in the data file .\n");
}
else
{
/* average */
/* 输出平均分的分段统计信息 */
printf("\n The count in each segment :\n");
printf("\t < 60\t:\t%d\n", i50);
printf("\t60 - 69\t:\t%d\n", i60);
printf("\t70 - 79\t:\t%d\n", i70);
printf("\t80 - 90\t:\t%d\n", i80);
printf("\t >= 90\t:\t%d\n", i90);
printf(" ------------------------------------------");
getch();
/* highest and loeest */
/* 输出总分最高的学生的信息 */
printf("\n The Highest Mark Student:\n");
printf(" The Mark is : %d\n", sum_high);
printf(" The student is :\n");
Output_Rec(&stu_high);
/* 输出总分最高的学生的信息 */
printf("\n The Lowest Mark Student:\n");
printf(" The Mark is : %d\n", sum_low);
printf(" The student is :\n");
Output_Rec(&stu_low);
printf(" ------------------------------------------\n");
getch();
/* subject highest and low */
/* 输出各科最高和最低分的统计信息 */
printf(" The Highest\tMath :\n");
Output_Rec(&stu_math_high);
printf(" The Lowest Math :\n");
Output_Rec(&stu_math_low);
printf(" ------------------------------------------\n");
getch(); /* 暂停 ,按任意键继续 */
printf(" The Highest English :\n");
Output_Rec(&stu_english_high);
printf(" The Lowest English :\n");
Output_Rec(&stu_english_low);
printf(" ------------------------------------------\n");
getch();
printf(" The Highest Compute :\n");
Output_Rec(&stu_compute_high);
printf(" The Lowest Compute :\n");
Output_Rec(&stu_compute_low);
printf(" ------------------------------------------\n");
getch();
printf(" The Highest Philosophy :\n");
Output_Rec(&stu_philosophy_high);
printf(" The Lowest Philosophy :\n");
Output_Rec(&stu_philosophy_low);
printf(" ------------------------------------------\n");
getch();
printf(" The Highest PE :\n");
Output_Rec(&stu_PE_high);
printf(" The Lowest PE :\n");
Output_Rec(&stu_PE_low);
printf(" ------------------------------------------\n");
}
fclose(fp);
}

void Find(int isFind_From_ID) /* 查找函数 */
{
char buf[30]; /* 接受用户输入的条件的缓冲区 */
Student rec;
int find_count; /* 查找到的记录数目 */
FILE *fp;
find_count = 0;
fp = fopen(DATA_FILE, "rb");
if (fp == NULL)
{
printf("\n Can not open the data file to search ...\n");
return;
}
switch (isFind_From_ID)
{
case 5: /* ID,按 学号查找 */
printf("\n Please Input the ID : ");
scanf("%s", buf); /* 提示用户输入 */
while (ReadData(fp, &rec)) /* 读取数据 */
{
if (strcmp(rec.ID, buf) == 0) /* 比较 */
{
find_count ;
Output_Rec(&rec); /* 输出符合条件的记录 */
printf(" ------------------------------------------\n");
}
}
break;
case 6: /* Name ,按 姓名 查找 */
printf("\n Please Input the Name : ");
scanf("%s", buf);
while (ReadData(fp, &rec))
{
if (strcmp(rec.Name, buf) == 0)
{
find_count ;
Output_Rec(&rec);
printf(" ------------------------------------------\n");
}
}
break;
default:
printf(" \nPlease type right index ...\n"); /* 处理isFind_From_ID既不是5也不是6的情况
*/
}
if (find_count > 0) /* 输出找到的记录数目 */
{
printf("\n Have find out\t%d\trecord\n", find_count);
}
else
{
printf
("\n I'm very sorry .\n I failed to find out the one you want .\n");
printf("\n I suggest that you change some other key words .\n");
}
fclose(fp);
}

int ReadData(FILE * fp, Student * Dest_Rec) /* 读取数据记录 */
{
int r;
if ((fp == NULL) || (Dest_Rec == NULL))
return 0; /* ERROR */
r = fread(Dest_Rec, sizeof(Student), 1, fp);
if (r != 1)
return 0;
return 1;
}

int WriteData(FILE * fp, Student * Src_Rec) /* 写入数据记录 */
{
int r;
if ((fp == NULL) || (Src_Rec == NULL))
return 0; /* ERROR */
r = fwrite(Src_Rec, sizeof(Student), 1, fp);
if (r != 1)
return 0;
return 1;
}

void Output_Rec(Student * stu) /* 在屏幕上输出 一个学生的信息 */
{
printf("\n");
printf(" Name : %s", stu->Name);
printf("\t\tSex : ");
if (stu->Sex == 'M' || stu->Sex == 'm')
printf("Male");
else
printf("Female");
printf("\n ID : %s\t\tClass : %s\n", stu->ID, stu->Class);
printf("Math = %d\tEnglish = %d\tCompute = %d\n", stu->Math, stu->English,
stu->Compute);
printf("Philosophy = %d\t\tPE = %d\n", stu->Philosophy, stu->PE);
printf("\n");
}

void Input_Rec(Student * stu) /* 让用户输入 一个学生的各项信息
*/
{
if (stu == NULL)
return;
printf("\n Name = ");
scanf("%s", stu->Name);
/* 下面这段代码实现只能输入 F ,f ,M ,m 的功能 */
printf("\tSex = (F|M) ");
while (1)
{
stu->Sex = getch(); /* 无回显输入 */
if (stu->Sex == 'F' || stu->Sex == 'f' || stu->Sex == 'M'
|| stu->Sex == 'm')
{
printf("%c", stu->Sex); /* 将用户输入的字符输出,模拟正常输入数据时的回显
*/
break;
}
}
/* 下面 给出提示,让用户输入结构体的各项内容 */
printf("\n ID = ");
scanf("%s", stu->ID);
printf("\n Class = ");
scanf("%s", stu->Class);
printf("\n Math = ");
scanf("%d", &(stu->Math));
printf("\n English = ");
scanf("%d", &(stu->English));
printf("\n Compute = ");
scanf("%d", &(stu->Compute));
printf("\n Philosophy = ");
scanf("%d", &(stu->Philosophy));
printf("\n PE = ");
scanf("%d", &(stu->PE));
printf("\n");
}

/* 因为结构体不能直接用 等号(=)赋值,写一个赋值函数 */
void CopyRec(Student * dest_stu, Student * src_stu)
{
/* 复制 源记录 的各项到 目标记录 */
strcpy(dest_stu->Name, src_stu->Name);
strcpy(dest_stu->ID, src_stu->ID);
strcpy(dest_stu->Class, src_stu->Class);
dest_stu->Sex = src_stu->Sex;
dest_stu->Math = src_stu->Math;
dest_stu->English = src_stu->English;
dest_stu->Compute = src_stu->Compute;
dest_stu->Philosophy = src_stu->Philosophy;
dest_stu->PE = src_stu->PE;
}

/*
题目分析 及 算法设计 :
题目中的各个功能都是相对独立的,所以我将各项功能以
带 编号 的菜单形式组织在屏幕上,用户通过 输入 编号
执行相应的功能。显示菜单的代码处于一个循环之中,当执行完一个子功能后,就又回到循环,显示主菜单,直到用户选择
退出 菜单。 这种操作方式比其它机制(如:主程序
程序参数)更简捷,不必每次用不同的参数重新运行程序,以实现相应的功能。
1. 查看文件记录内容的实现: 用循环读取文件内容,然后显示在屏幕上。
因为我们的数据是以结构体的形式存放在文件中的,所以
代码中用了块读取和块写入函数。 在循环中设置计数器来统计记录的个数。 2.
添加记录的实现:
让用户根据屏幕提示输入数据,完成对学生信息结构体各项的赋值,待取得足够数据后,将数据文件以“追加”方式打开,执行块写入,将整个结构体写入文件。
3. 删除记录的实现:
学号(ID)一般不会重复,所以我在程序中让用户输入想要删除的记录的学号(ID),然后在文件中查找,如果不是用户想要删除的记录(即ID不同),就保存在一个临时的文件中,这样,就将想要删除的记录与其它记录分离开了,最后,删除原来的数据文件,将临时文件的名字改为
原来数据文件的名字。 4. 统计功能的实现:
统计功能模块分为三个小模块:平均分的分数段统计,总分的最高和最低分统计,各科的最高和最低分统计。但我并不想分别来写,因为它们都要对所有记录进行扫描,而它们又互不干扰,所以我把它们组织在一个循环中,各自都有自己的计算代码和变量,所以这个
函数 中的局部变量 很多。 5. 查找功能的实现: 题目要求两种查找方式:按 学号(ID) , 按 姓名(Name)。 两者是独立的,所以我用了一个参数 isFind_From_ID
来表明是哪种查找方式,进而在在程序内部由一个 switch() 选择分支转向不同的代码段去执行。
具体的查找就是比较相应的项目是否与用户输入的一样,若一样就输出到屏幕。 */

热点内容
武汉大学学生会辅导员寄语 发布:2021-03-16 21:44:16 浏览:612
七年级学生作文辅导学案 发布:2021-03-16 21:42:09 浏览:1
不屑弟高考成绩 发布:2021-03-16 21:40:59 浏览:754
大学毕业证会有成绩单 发布:2021-03-16 21:40:07 浏览:756
2017信阳学院辅导员招聘名单 发布:2021-03-16 21:40:02 浏览:800
查询重庆2018中考成绩查询 发布:2021-03-16 21:39:58 浏览:21
结业考试成绩怎么查询 发布:2021-03-16 21:28:40 浏览:679
14中医医师资格笔试考试成绩查分 发布:2021-03-16 21:28:39 浏览:655
名著赏析课程标准 发布:2021-03-16 21:27:57 浏览:881
北京大学商业领袖高端培训课程 发布:2021-03-16 21:27:41 浏览:919