当前位置:首页 » 操作系统 » 学生管理系统的源码

学生管理系统的源码

发布时间: 2024-03-06 15:34:03

Ⅰ c++课程设计源代码

c++课程设计 学生管理系统源代码
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
using namespace std;
typedef struct stu
{
char name[20];
long int number;
int snum;
char sex[20];
char add[30] ;
char time[20];
char tel[20];
struct stu *next;
}stu,*student;
int init(student &s);
void insert(student &s);
void print(student &s);
int delete(student &s);
void find (student &s);
void findname(student &s);
void findnum(student &s);
void modifay(student &s);
void putfile(student &s);
void getfile(student &s);

void main()
{
student s;
init(s);
cout<<"欢迎使用学生管理系统."<<endl;
cout<<" "<<endl;
cout<<endl;
while(1)
{
int i;
mainint:
cout<<"请选择相关操作:"<<endl<<"1.建立学生资料文件."<<endl<<"2.浏览."<<endl<<"3.删除."<<endl;
cout<<"4.查询."<<endl<<"5.修改."<<endl<<"6.打开学生文件."<<endl<<"7.退出管理系统." <<endl<<"请选择:";
cin>>i;
if(i<0||i>7)
{
cout<<"输入了错误的数字,Again!"<<endl<<endl;
goto mainint;
}
switch(i)
{
case 1: insert(s);break;
case 2: print(s);
putfile(s);
break;
case 3: ldelete(s);break;
case 4: find(s);break;
case 5: modifay(s);
break;
case 6: getfile(s);break;
case 7: exit(0);
}
}

}
int init(student &s)
{
s=(student)malloc(sizeof(stu));
if (s)
{
s->next=NULL;
return 0;
}
else return -1;
}
void insert(student &s) //insert
{
cout<<endl;
student p,q;
p=(student)malloc(sizeof(stu));
cout<<"请输入学生信息:"<<endl;
cout<<"姓名:";
cin>>p->name;
cout<<endl;
cout<<"学号:";
cin>>p->number;
cout<<endl;
cout<<"性别:";
cin>>p->sex;
cout<<endl;
cout<<"家庭住址:" ;
cin>>p->add;
cout<<endl;
cout<<"出生年月:" ;
cin>>p->time;
cout<<endl;
cout<<"宿舍号:";
cin>>p->snum;
cout<<endl;
cout<<"宿舍号码:";
cin>>p->tel;
q=s;
while(!(q->next==NULL)&&(q->next->number<p->number))
q=q->next;
p->next=q->next;
q->next=p;
//if()p->next=NULL;
//free(p);

}
int ldelete(student &s) //delete
{
cout<<endl;
student p,a;
p=s ;
cout<<"请输入删除的学号:";
long int number;
cin>>number;
while(p)
{ if (p->number==number)
{
a->next=p->next;
free(p); return(0);}
else
{ a=p;
p=p->next;} }
cout<<"没有找到你要删除的选项!"<<endl<<endl;return(-1);
}
void print(student &s)
{
int a;
a=0;
student p;
p=s->next;
cout<<"姓名 "<<"学号 " <<"性别 "<<"家庭住址 "<<"出生年月 "<<"宿舍号"<<"宿舍号码"<<endl;
while(p)
{
a++;
cout<<p->name<<" "<<p->number<<" "<<p->sex<<" "<<p->add<<" "<<p->time<<" "<<p->snum<<" "<<p->tel<<" "<<endl;
p=p->next;
}
cout<<endl;
if (a==0)
cout<<"还没有学生信息!"<<endl<<endl ;
}
void find (student &s) //find
{
findl:
cout<<"请选择查找方法:"<<endl<<"1.按姓名查找."<<endl<<"2.按学号查找."<<endl;
cout<<"请选择:";
int k;
cin>>k;
if(k<0||k>3)
{
cout<<"输了入错误数字,Again!"<<endl<<endl;
goto findl;
}

switch(k)
{
case 1: findname(s);break;
case 2: findnum(s);break;
}
}

void findname(student &s) //find by name
{
student p;
p=s->next;
cout<<"请输入姓名:";
char name[20];
int j;
j=0;
cin>>name;
cout<<"你要查找的资料是:"<<endl;
cout<<"姓名 "<<"学号 " <<"性别 "<<"家庭住址 "<<"出生日期 "<<"宿舍号 "<<"宿舍号码"<<endl;
while(p)
{
if (strcmp(p->name,name)==0)
{
cout<<p->name<<" "<<p->number<<" "<<p->sex<<" "<<p->add<<" "<<p->time<<" "<<p->snum<<" "<<p->tel<<" "<<endl;
j++;
}
p=p->next;
}
cout<<endl;
if(j==0)
cout<<"对不起,没找到你要的信息!"<<endl<<endl ;
}
void findnum(student &s) //find by number
{
student p;
p=s->next;
cout<<"请输入学号:";
long int number;
int j;
j=0;
cin>>number;
cout<<"你要查找的资料是:"<<endl;
cout<<"姓名 "<<"学号 "<<"性别 "<<"家庭住址 "<<"出生日期 "<<"宿舍号 "<<"宿舍电话"<<endl;
while(p)
{
if (p->number==number)
{
cout<<p->name<<" "<<p->number<<" "<<p->sex<<" "<<p->add<<" "<<p->time<<" "<<p->snum<<" "<<p->tel<<" "<<endl;
j++;
}
p=p->next;
}
cout<<endl;
if(j==0)
cout<<"对不起,没找到你要的信息"<<endl<<endl ;
}
void modifay(student &s) //modifay
{
student q,p,l,m;
int j;
j=0;
q=s->next;
l=s;
m=s;
cout<<"请输入要修改的学号:" ;
long int num;
cin>>num;
cout<<"姓名 "<<"学号 "<<"性别 "<<"家庭住址 "<<"入学时间 "<<"宿舍号 "<<"电话号码"<<endl;
while(q)
{
if (q->number==num)
{
cout<<"你要修改的信息是:"<<endl;
cout<<q->name<<" "<<q->number<<" "<<q->sex<<" "<<q->add<<" "<<q->time<<" "<<q->snum<<" "<<q->tel<<" "<<endl;
j++;
p=(student)malloc(sizeof(stu));
cout<<"请输入新的学生信息:"<<endl;
cout<<"姓名:";
cin>>p->name;
cout<<endl;
cout<<"学号:";
cin>>p->number;
cout<<endl;
cout<<"年龄:";
cin>>p->age;
cout<<endl;
cout<<"性别:";
cin>>p->sex;
cout<<endl;
cout<<"家庭住址:" ;
cin>>p->add;
cout<<endl;
cout<<"入学时间:" ;
cin>>p->time;
cout<<endl;
cout<<"电话号码:";
cin>>p->tel;
l->next=q->next;
free(q);
goto tt;
}
else
{
l=q;
q=q->next;
}
}
cout<<endl;
if (j==0) cout<<"没找到你要的数据!"<<endl<<endl ;
tt:
while(!(m->next==NULL)&&(m->next->number<p->number))
m=m->next;
p->next=m->next;
m->next=p;
}
void putfile(student &s)
{
student p;
p=s->next;
FILE *fp;
if((fp=fopen("information.txt","w"))==NULL)
{
cout<<"打不开文件"<<endl<<endl;
exit(0);
}
while(p)
{
if(fwrite(p,sizeof(struct stu),1,fp)!=1 )
{
cout<<"文件写入错误"<<endl<<endl;
return;
}
p=p->next;
}
fclose(fp) ;
}
void getfile(student &s)
{
student p,q;
q=s;
FILE *fp1 ;
if((fp1=fopen("information.txt","r"))==NULL)
{
cout<<"打不开文件"<<endl;
exit(0);
}
cout<<"姓名 "<<"学号 "<<"性别 "<<"家庭住址 "<<"入学时间 "<<"宿舍号 "<<"电话号码"<<endl;
p=(student)malloc(sizeof(stu));
while(fread(p,sizeof(struct stu),1,fp1)!=0)
{
cout<<p->name<<" "<<p->number<<" "<<p->sex<<" "<<p->add<<" "<<p->time<<" "<<p->age<<" "<<p->tel<<endl;
while(!(q->next==NULL)&&(q->next->number<p->number))
q=q->next;
p->next=q->next;
q->next=p;
p=(student)malloc(sizeof(stu));
}
fclose(fp1);
cout<<endl;
}

Ⅱ 学生信息管理系统C++源代码

#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<malloc.h>
#define INIT_SIZE 10
#define INCRE_SIZE 10
#define SUBJECT_NUM 3
#define LEN 3

void show_Start();

void show_Table();

void addRecord();

void Info_delete();
void deleteRecord();
void delete_Num(int);
void delete_Name(char tarName[]);

void Info_modify();
void modifyRecord();
void modify_Num(int);
void modify_Name(char[]);

void Info_query();
void queryRecord();
void query_Num(int);
void query_Name(char[]);

void display();

void quit();

void menu_CMD();

char *subject[SUBJECT_NUM] = {"高代","数分","c语言"};

struct STUDENT
{
int num;
char name[20];
char sex;
float score[SUBJECT_NUM];
};

//struct STUDENT stu[LEN + 1];

//STUDENT *record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);

int static stuNum = 0;
//先暂时定义三个学生吧...

STUDENT *record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);;

int main()
{
//record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);
//STUDENT *record = (STUDENT*)malloc(sizeof(STUDENT)*INIT_SIZE);

/*
record[1].num = 1001;
strcpy(record[1].name,"Jason");
record[1].sex = 'M';
record[1].score[0] = 85.0;
record[1].score[1] = 90.0;
record[1].score[2] = 95.0;

record[2].num = 1002;
strcpy(record[2].name,"Jerry");
record[2].sex = 'M';
record[2].score[0] = 85.0;
record[2].score[1] = 90.0;
record[2].score[2] = 95.0;

record[3].num = 1003;
strcpy(record[3].name,"Jessie");
record[3].sex = 'F';
record[3].score[0] = 85.0;
record[3].score[1] = 90.0;
record[3].score[2] = 95.0;
*/

/*
Info_modify();
int key;
cout<<"请输入您的选择 : ";
cin>>key;

if(key == 1)
{
int targetNum;
cout<<"请输入您欲修改的学生的学号 : ";
cin>>targetNum;

modify_Num(targetNum);
cout<<endl;

display();
}

if(key == 2)
{
char targetName[20];
cout<<"请输入您欲修改学生的姓名 : ";
cin>>targetName;

modify_Name(targetName);
cout<<endl;

display();
}

if(key == 3)
{
exit(0);
}
*/

show_Start();

menu_CMD();

return 0;

}

//修改完后还应该显示
void show_Start()
{
//cout<<endl;
cout<<" **************************************** "<<endl;
cout<<" 这是一个 "<<endl;
cout<<" 学生成绩管理系统 "<<endl;
cout<<" 可以对学生成绩进行管理 "<<endl;
cout<<" 欢迎大家使用 "<<endl;
cout<<" Made by Jason "<<endl;
cout<<" **************************************** "<<endl;
}

// 显示表头信息,即是 : 学号,姓名,性别,高代,数分,C语言.
void show_Table()
{
cout<<"学号"<<"\t"<<"姓名"<<"\t"<<"性别";
cout<<"\t"<<subject[0]<<"\t"<<subject[1]<<"\t"<<subject[2];
cout<<endl;
}

void menu_CMD()
{
int key;
while(1)
{
cout<<"1. 增加学生信息"<<endl;
cout<<"2. 删除学生信息"<<endl;
cout<<"3. 修改学生信息"<<endl;
cout<<"4. 查询学生信息"<<endl;
cout<<"5. 显示学生信息"<<endl;
cout<<"6. 退出"<<endl;
cout<<"请输入您的选择 : ";
cin>>key;
while(1)
{
if((key < 1)||(key > 6))
{
int key;
cout<<"您的输入有误,请重新输入!"<<endl;
cout<<"请选(1 - 5) : ";
cin>>key;
}
else
{
break;
}
}
switch(key)
{
case 1:
addRecord();
break;
case 2:
deleteRecord();
break;
case 3:
modifyRecord();
break;
case 4:
queryRecord();
break;
case 5:
display();
break;
case 6:
quit();
break;
}

}
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

//增加学生信息
void addRecord()
{

if(stuNum == 0)
{
cout<<"原来没有记录,现在建立新表!"<<endl;
stuNum++;
}
else
{
cout<<"现在在当前表的末尾添加新的信息!"<<endl;
stuNum++;
}

//如果数组空间不够,重新申请空间
if(stuNum > INIT_SIZE)
{
cout<<"内存空间不够,现在重新申请新的内存空间!"<<endl;
record = (STUDENT*)realloc(record,(INIT_SIZE + INCRE_SIZE)*sizeof(STUDENT));
cout<<"空间申请完成!"<<endl;
}

cout<<"您现在要添加一组新的信息,您确定吗?"<<endl;
cout<<"请输入您的选择(Y/N) : ";
char choi;
cin>>choi;
if((choi == 'Y')||(choi == 'y'))
{
cout<<"请输入学号 : ";
cin>>record[stuNum].num;
cout<<"请输入姓名 : ";
cin>>record[stuNum].name;
cout<<"请输入性别(M为男,F为女) : ";
cin>>record[stuNum].sex;

int i;
for(i = 0;i < SUBJECT_NUM;i++)
{
cout<<"请输入"<<subject[i]<<"的成绩 : ";
cin>>record[stuNum].score[i];
}
}

if((choi == 'N')||(choi == 'n'))
{
cout<<"退出添加新学生信息!"<<endl;
cout<<endl;
}

cout<<"现在已经有"<<stuNum<<"条学生的信息了!"<<endl;
cout<<endl;
}

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//删除信息 晚上完成...

//显示deleteRecord的表头信息
void Info_delete()
{
cout<<"请输入删除方式 : "<<endl;
cout<<"1. 按学号删除"<<endl;
cout<<"2. 按姓名删除"<<endl;
cout<<"3. 退出删除"<<endl;
}

//删除学生的信息,包含两个子函数
void deleteRecord()
{
int key;
cout<<endl;
Info_delete();
cout<<"请输入您的选择 : ";
cin>>key;

if(key == 1)
{
int targetNum;
cout<<"请输入您欲删除学生的学号 : ";
cin>>targetNum;

//按学号删除
delete_Num(targetNum);
cout<<endl;
}

if(key == 2)
{
char targetName[20];
cout<<"请输入您欲删除学生的姓名 : ";
cin>>targetName;

//按姓名删除
delete_Name(targetName);
cout<<endl;
}

if(key == 3)
{
while(1)
{
menu_CMD();

}
}
}

//按学号删除学生信息
//只用完成删除操作,而不必输出. 输出的操作可以在主菜单中进行

void delete_Num(int tarNum)
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(record[i].num == tarNum)
{
//删除还要分两种情况讨论
//1. 欲删除的学生信息是最后一位
//2. 欲删除的学生信息不是最后一位

//第一种情况,欲删除的学生是最后一位
if(i = stuNum)
{
cout<<"您所要删除的学生信息是 : "<<endl;
show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"
<<record[i].score[0]<<record[i].score[1]<<"\t"<<record[i].score[2];
cout<<endl;

cout<<endl<<"删除后学生信息表为 : "<<endl;
show_Table();
for(int i = 1;i <= stuNum - 1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
//显示信息应该放在后面
/*
stuNum--;
cout<<"现在还剩下"<<stuNum<<"条学生的信息";
cout<<endl;
*/
}

//2.第二种情况,欲删除的学生不是最后一位
if(i != stuNum)
{

cout<<"您所要删除的学生信信息是 : "<<endl;
show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"
<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];

for(int j = i+1;j <= stuNum;j++)
{
record[j-1] = record[j];
}

//接着完成输出

cout<<endl;
cout<<"删除后学生信息表为 : "<<endl;
show_Table();
for(int i = 1;i <= stuNum-1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
/*
stuNum--;
cout<<"现在还剩下"<<stuNum<<"条学生的信息";
cout<<endl;
*/
}

stuNum--;
cout<<"现在还是剩下"<<stuNum<<"条学生的信息";
cout<<endl;
}
}
}

/*

//方法同上
void delete_Name(char tarName[])
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(strcmp(record[i].name,tarName) == 0)
{
//删除还要分两种情况讨论
//1. 欲删除的学生信息是最后一位
//2. 欲删除的学生信息不是最后一位

//第一种情况 : 欲删除学生是最后一位
if(i = stuNum)
{
cout<<"您所要删除的学生信息是 : "<<endl;
show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"
<<record[i].score[0]<<record[i].score[1]<<"\t"<<record[i].score[2];
cout<<endl;

cout<<endl<<"删除后学生信息表为 : "<<endl;
show_Table();
for(int i = 1;i <= stuNum - 1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
}

//第二种情况 : 欲删除学生不是最后一位
if(i != stuNum)
{

cout<<"您所要删除的学生信信息是 : "<<endl;
show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"
<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];

//整体往前 前移一位
for(int j = i+1;j <= stuNum;j++)
{
record[j-1] = record[j];
}
cout<<endl;

//接着完成输出
cout<<"删除后学生信息表为 : "<<endl;
show_Table();
for(int i = 1;i <= stuNum-1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}

cout<<endl;
}
}

}

}

*/

void delete_Name(char tarName[])
{
int i;
for(i = 1;i <= stuNum;i++)
{

//删除还要分两种情况讨论
//1. 欲删除的学生信息是最后一位
//2. 欲删除的学生信息不是最后一位

//当欲删除的学生是最后一位,直接输出前面LEN-1位学生的信息

if(strcmp(record[i].name,tarName) == 0)
{
if(i == stuNum)
{
cout<<"您所要删除的学生信息是 : "<<endl;
show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t"
<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];

cout<<endl;

cout<<"删除后学生信息表为 : "<<endl;
show_Table();
for(int i = 1;i <= stuNum-1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
/*
stuNum--;
cout<<"现在还剩下"<<stuNum<<"条学生的信息";
cout<<endl;
*/
}

//当欲删的学生不是最后一位,整体往前前移一位
if(i != stuNum)
{
cout<<"您所要删除的学生信息是 : "<<endl;

show_Table();
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex<<"\t";
cout<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];
cout<<endl;

//整体往前前移一位
for(int j = i+1;j <= stuNum;j++)
{
record[j-1] = record[j];
}

//然后输出
cout<<endl;
cout<<"删除后学生信息表为 : "<<endl;

show_Table();
for(int i = 1;i <= stuNum-1;i++)
{
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(int j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
/*
stuNum--;
cout<<"现在还剩下"<<stuNum<<"条学生的信息";
cout<<endl;
*/
}

stuNum--;
cout<<"现在还剩下"<<stuNum<<"条学生的信息";
cout<<endl;
}
}
}

/*****************************************************************************
******************************************************************************/

//显示modifyRecord的表头信息
void Info_modify()
{
cout<<"请输入修改方式 : "<<endl;
cout<<"1. 按学号修改"<<endl;
cout<<"2. 按姓名修改"<<endl;
cout<<"3. 退出修改"<<endl;
}

//查询学生的成绩,当然里面包括两个子函数
void modifyRecord()
{
int key;
cout<<endl;
Info_modify();
cout<<"请输入您的选择 : ";
cin>>key;

//按学号修改
if(key == 1)
{
int targetNum;
cout<<"请输入您欲修改的学生的学号 : ";
cin>>targetNum;

modify_Num(targetNum);
cout<<endl;

//display();
}

//按姓名修改
if(key == 2)
{
char targetName[20];
cout<<"请输入您欲修改学生的姓名 : ";
cin>>targetName;

modify_Name(targetName);
cout<<endl;

//display();
}

//退出修改
if(key == 3)
{
while(1)
{
menu_CMD();
}
}
}

//按学号修改
void modify_Num(int tarNum)
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(record[i].num == tarNum)
{
cout<<endl<<"请修改该学生的信息"<<endl;
cout<<"请输入该学生的学号 : ";
cin>>record[i].num;
cout<<"请输入该学生的姓名 : ";
cin>>record[i].name;
cout<<"请输入该学生的性别 : ";
cin>>record[i].sex;
cout<<"请输入"<<subject[0]<<"的成绩 : ";
cin>>record[i].score[0];
cout<<"请输入"<<subject[1]<<"的成绩 : ";
cin>>record[i].score[1];
cout<<"请输入"<<subject[2]<<"的成绩 : ";
cin>>record[i].score[2];
}
}
}

//按姓名修改
void modify_Name(char tarName[])
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(strcmp(record[i].name,tarName) == 0)
{
cout<<endl<<"请修改该学生的信息 : "<<endl;
cout<<"请输入该学生的学号 : ";
cin>>record[i].num;
cout<<"请输入该学生的姓名 : ";
cin>>record[i].name;
cout<<"请输入该学生的性别 : ";
cin>>record[i].sex;
cout<<"请输入"<<subject[0]<<"的成绩 : ";
cin>>record[i].score[0];
cout<<"请输入"<<subject[1]<<"的成绩 : ";
cin>>record[i].score[1];
cout<<"请输入"<<subject[2]<<"的成绩 : ";
cin>>record[i].score[2];
}
}
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

//显示queryRecord的表头信息
void Info_query()
{
cout<<"请输入查询方式 : "<<endl;
cout<<"1. 按学号查询"<<endl;
cout<<"2. 按姓名查询"<<endl;
cout<<"3. 退出查询"<<endl;
}

//查询学生信息queryRecord
void queryRecord()
{
int key;
cout<<endl;
Info_query();
cout<<"请输入您的选择 : ";
cin>>key;

if(key == 1)
{
int targetNum;
cout<<"请输入您欲查询学生的学号 : ";
cin>>targetNum;

query_Num(targetNum);
cout<<endl;
}

if(key == 2)
{
char targetName[20];
cout<<"请输入您欲查询学生的学号 : ";
cin>>targetName;

query_Name(targetName);
cout<<endl;
}

//退出查询,退回到主菜单吧...
if(key == 3)
{
while(1)
{
menu_CMD();
}
}
}

//按学号查询
void query_Num(int tarNum)
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(record[i].num == tarNum)
{
//如果表中有该学生信息的话,仅用输出该学生的信息即可.
//输出该学生的信息
cout<<"该学生的信息如下 : "<<endl;

//显示表头信息
show_Table();

//显示该学生具体的信息
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
cout<<"\t"<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];
cout<<endl;
}
}
}

//按姓名查询
void query_Name(char tarName[])
{
int i;
for(i = 1;i <= stuNum;i++)
{
if(strcmp(record[i].name,tarName) == 0)
{
cout<<"该学生的信息如下 : "<<endl;

show_Table();

cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
cout<<"\t"<<record[i].score[0]<<"\t"<<record[i].score[1]<<"\t"<<record[i].score[2];
cout<<endl;
}
}
}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

//先显示所有学生的信息吧
//显示record里所有学生的成绩
void display()
{
show_Table();
int i,j;
for(i = 1;i <= stuNum;i++)
{
//cout<<"学号"<<"\t"<<"姓名"<<"\t"<<"性别";
cout<<record[i].num<<"\t"<<record[i].name<<"\t"<<record[i].sex;
for(j = 0;j < SUBJECT_NUM;j++)
{
cout<<"\t"<<record[i].score[j];
}
cout<<endl;
}
cout<<endl;
}

//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

//退出
void quit()
{
char choi;
cout<<"您确定要退出吗?"<<endl;
cout<<"请输入您的选择(Y/N) : ";
cin>>choi;
if((choi == 'Y')||(choi == 'y'))
{
cout<<"现在退出学生信息管理系统"<<endl;
exit(0);
}
//如果不是退出,则接着退回到主界面
else
{
cout<<endl;
menu_CMD();
}

}

这个是原创的... 在C-Free 4.0里跑过,可以正常运行
你可以试着跑一下,如果有什么问题可以和我联系

Ⅲ c语言学生成绩管理系统1000行源代码

/*首次使用,新建score.in文件,在里面打入0
可用程序
#include<stdio.h>
FILE *fin
main()
{
fin=fopen("score.in","r");
fprintf(fin,"0");
return 0;
}
完成
*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<windows.h>
#include<time.h>
#define n 999
FILE *fin;
main()
{
int a[n]={0},ori=0,i=0,b=0,add[n]={0},con=0,orix[n]={0},t=0,te[n]={0},TRUEt,ixi,fx,abc=0,sum,TURE,xx;
long long f[n]={0},tex[n]={0};
printf("\n\n\n\n\n\n\n\n\n\n\n\t\t\t\t\t\t学生成绩管理系统\n\t\t\t\t\t\t Please wait...");
Sleep(2000);system("cls");
int xp,xi;
fin=fopen("score.in","r+");
fscanf(fin,"%d",&xp);
i=xp;
for(xi=1;xi<=xp;xi++)
{fscanf(fin,"%d%d%d",&f[xi],&a[xi],&te[xi]);te[xi]--;
printf("Id:%lld score:%d ranking:%d\n",f[xi],a[xi],te[xi]+1);
add[xi]=xi;orix[xi]=a[xi];
}
fclose(fin);
int TRUE1;
pe:
while(1)
{ TRUE1=1;i++;
printf("Id(输入-1:删除,输入-2:修改成绩,输入-3:删除所有内容,输入-4:保存到score.in并退出):");
scanf("%lld",&f[i]);
for(sum=1;sum<i;sum++)
if(f[sum]==f[i])
{system("cls");for(con=1;con<=i;con++) {if(a[con]==0)continue;printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}TRUE1=0;i--;printf("Error with two same id.\n");continue;}
if(TRUE1==0)
continue;
if(f[i]==-3)
{int r;
for(r=0;r<n;r++)
{
a[r]=0;ori=0;i=0;b=0;add[r]=0;con=0;orix[r]=0;t=0;te[r]=0;abc=0;
f[r]=0;tex[r]=0;
}
system("cls");
goto pe;
}
if(f[i]==-2)
{TURE=0;i--;
system("cls");
for(con=1;con<=i;con++)
{if(a[con]==0)continue; printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}
printf("修改学号_____________号的分数.\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b",f[con],a[con],te[con]+1);
scanf("%d",&xx);
for(sum=1;sum<=i;sum++)
if(f[sum]==xx)
{
TURE=1;
printf("\n修改为___________.\b\b\b\b\b\b\b\b\b\b\b\b");
scanf("%d",&a[sum]);
printf("\n修改成功!将在下一次输入后更新名次。\n\n");
continue;
}
if(TURE==0)
printf("No id is %d\n",xx);
continue;
}
if(f[i]==-4)
{
i--;
fin=fopen("score.in","r+");
fprintf(fin,"%d\n",i);
for(xi=1;xi<=i;xi++)fprintf(fin,"%d %d %d\n",f[xi],a[xi],te[xi]+1);
for(xi=i+1;xi<=xp;xi++)fprintf(fin," \n");
fclose(fin);
return 0;
}
if(f[i]==-1)
{TRUEt=0;
system("cls");
i--;
for(con=1;con<=i;con++){if(a[con]==0)continue;printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}
printf("删除学号_____________号.\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
scanf("%lld",&fx);
for(con=1;con<=i;con++)
if(f[con]==fx)
{TRUEt=1;abc++;
f[con]=0;
a[con]=0;
tex[abc]=te[con];
for(ixi=1;ixi<=i;ixi++)
if(te[ixi]>te[con])
te[ixi]--;
te[con]=0;
break;}
system("cls");
for(con=1;con<=i;con++){
if(a[con]==0)continue;
printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}
if(TRUE==0)
printf("No Id is %lld\n",fx);
continue;
}
system("cls");
for(con=1;con<i;con++)
{if(a[con]==0)continue; printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}
printf("Id:%lld score:",f[i]);
scanf("%d",&ori);system("cls");
a[i]=ori;add[i]=i;orix[i]=a[i];
system("cls");
for(b=1;b<=i;b++)
for(con=i;con>=b;con--)
if(orix[con]>orix[con-1])
{t=orix[con];orix[con]=orix[con-1];orix[con-1]=t;
t=add[con];add[con]=add[con-1];add[con-1]=t;}
for(con=1;con<=i;con++) te[add[con]]=con;
for(con=1;con<=abc;con++)
for(ixi=1;ixi<=i;ixi++)
if(te[ixi]>tex[con])
te[ixi]--;
if(te[i]==te[i-1])te[i]=0;
for(con=1;con<=i;con++)
{if(a[con]==0)continue;printf("Id:%lld score:%d ranking:%d\n",f[con],a[con],te[con]+1);}
}
return 0;
}
//求采纳

Ⅳ 如何用C语言编写学生信息管理系统

参考如下学生信息管理系统的C源代码吧。

#include<stdio.h>
#include<string.h>
/*定义学生结构体*/
structStudent
{
charID[20];
charName[20];
floatMark1;
floatMark2;
floatMark3;
floatAverage;
};
/*声明学生数组及学生数量*/
structStudentstudents[1000];
int腔源num=0;
/*求平均值*/
floatAvg(structStudentstu)
{
return(stu.Mark1+stu.Mark2+stu.Mark3)/3;
}
/*通过学号返回数组下标*/
intStudent_SearchByIndex(charid[])
{
inti;
for(i=0;i<num;i++)
{
if(strcmp(students[i].ID,id)==0)
{
returni;
}
}
return-1;
}
/*通过姓名返回数组下标*/
intStudent_SearchByName(charname[])
{
inti;
for(i=0;i<num;i++)
{
if(strcmp(students[i].Name,name)==0)
{
returni;
}
}
return-1;
}
/*显示单条学生记录*/
voidStudent_DisplaySingle(intindex)
{
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);
}
/*插入学生信息*/
voidStudent_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;
}
}
}
/*修改学生信息*/
voidStudent_Modify()
{
//floatmark1,mark2,mark3;
while(1)
{
charid[20];
intindex;
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;
}
}
}
/*删除学生信息*/
voidStudent_Delete()
{
inti;
while(1)
{
charid[20];
intindex;
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;
}
}
}
/*按姓名查询*/
voidStudent_Select()
{
while(1)
{
charname[20];
intindex;
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;
}
}
}
/*按平均值排序*/
voidStudent_SortByAverage()
{
inti,j;
structStudenttmp;
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;
}
}
}
}
/*显示学生信息*/
voidStudent_Display()
{
inti;
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);
}
}
/*将学生信息从文件读出*/
voidIO_ReadInfo()
{
FILE*fp;
inti;
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(structStudent),1,fp);
}
}
fclose(fp);
}
/*将学生信息写入文件*/
voidIO_WriteInfo()
{
FILE*fp;
inti;
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(structStudent),1,fp)!=1)
{
printf("写入文件错误! ");
}
}
fclose(fp);
}
/*主程序*/
voidmain()
{
intchoice;
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)
{
case1:
Student_Insert();
break;
case2:
Student_Modify();
break;
case3:
Student_Delete();
break;
case4:
Student_Select();
break;
case5:
Student_SortByAverage();
Student_Display();
break;
case6:
exit(0);
break;
}
IO_WriteInfo();
}
}
热点内容
redis永久缓存 发布:2024-11-28 12:37:40 浏览:55
php是自学网 发布:2024-11-28 12:33:57 浏览:732
php采集系统 发布:2024-11-28 12:32:04 浏览:907
数据库恢复的实现技术 发布:2024-11-28 12:25:26 浏览:5
压缩图档 发布:2024-11-28 12:25:23 浏览:423
自定义缓存 发布:2024-11-28 12:25:07 浏览:235
怎么进电脑的服务器 发布:2024-11-28 12:23:57 浏览:830
服务器2s1u是什么意思 发布:2024-11-28 12:22:54 浏览:511
服务器怎么当做挂机宝 发布:2024-11-28 12:16:49 浏览:45
ga算法nn 发布:2024-11-28 12:12:17 浏览:50