学生管理系统源代码

这是一个使用C语言编写的学籍管理系统源代码,包括学生和教师结构体定义,以及添加、删除、修改和查询学生信息的功能。系统支持文件读写,可以进行学生和教师的操作管理。
摘要由CSDN通过智能技术生成
/*
 * xjgl.h
 *
 *  Created on: 2014-12-5
 *      Author: yao
 */
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include<stdlib.h>
//#include"stu.c"
//#include"tea.c"
//学生结构体
typedef struct student
{
    int id;
    struct stuname
    {
    int passwd;
    char class[20];
    char name[20];
    char sex;
    int age;
    }stuna;
    float math;
    float c;
    float yuwen;
    float ave;
struct student *next;
}students;
typedef struct teacher{                        //教师结构体
    int tid;
    int tpasswd;
    char tsex;
    int tage;
    char tname[20];
    struct teacher *next;
}teachers;
students *listtofile_stu(students *phead);
students  *filetolist_stu();
teachers *listtofile_tea(teachers *phead);
teachers  *filetolist_tea();
 struct student *create();
 void serch_xh(students *phead);
void serch_xm(struct student *phead);
void chazhao_stu(struct student *phead);
struct student *add_stu(students *phead);
struct student *change_stu(students *phead);
void xianshi_stu(students *phead);
void del_stuxh(students *phead);
void del_stuxm(students *phead);
void del_stubj(students *phead);
void del_stu(students *phead);
void xs_stu_xh( students *phead );
void xs_stu_mc( students *phead );
void xs_stu_cj( students *phead );
struct teacher *tcreate();
struct teacher *add_tea(teachers *thead);
struct teacher *del_tea(teachers *thead);
void del_tea_gh(teachers *thead);
void del_teaxm(teachers *thead);
struct teacher *change_tea(teachers *thead);
void tprintall( teachers *head );
struct teacher *xianshi_tea(teachers *thead);
void xs_tea_gh( teachers *thead );
void manager(teachers *tphead,students *phead);
void caozuo_stu(students *phead);
void caozuo_tea(teachers *phead);
void print( students *head );
 void tprint( teachers *head );
void chazhao_tea(teachers *thead);
void serch_gh(teachers *thead);
void serch_txm( teachers *thead);
teachers *teacher(teachers *tphead,students *phead);
void tea_change(teachers *phead);
 void tea_change_tea(teachers *phead);
void tea_change_stu(students *phead);
 void tea_changestu(students *phead);
students *student(students *phead);
 void stu_change(students *phead);


========================================================
/*
 *
 *stu.c
 *  Created on: 2014-12-5
 *      Author: yaoshenjie
 */
#include"xjgl.h"
students *listtofile_stu(students *phead)
{

    FILE *fp;
    students *tmp;
     if((fp=fopen("student","wb"))==NULL)   /*打开文件*/
     {    printf("cannot open file\n");
        return 0;
     }
     for(tmp = phead;tmp != NULL;tmp = tmp->next)   /*遍历链表*/
     {
         fwrite(tmp,sizeof(students),1,fp); /*把数据写入文件*/
     }
     fclose(fp);
     return phead;
}
//从文件读入链表
students  *filetolist_stu(){
    FILE *fp=NULL;
    students *p,*p1;
    students *head;
     head = NULL;
    if((fp = fopen("student","rb"))==NULL)
     {
         printf("cannot open flie\n");
        return 0;
     }
    char c;
    c=fgetc(fp);
    if(c==EOF){return NULL;}
    else{rewind(fp);}
    p=malloc(sizeof(students));
    fread(p,sizeof(students),1,fp);
     while(!feof(fp))
     {
        // p = malloc(sizeof(students));
        // fread(p,sizeof(students),1,fp);
        if(head==NULL) {
            head=p;
            p->next=NULL;
         }
        else{
                    p1=head;
                    while(p1->next!=NULL){                    //求得尾指针p1
                                    p1=p1->next;
                                }

                    p1->next = p;
                    p->next = NULL;
                    p = malloc(sizeof(students));
                    fread(p,sizeof(students),1,fp);
                }
     }

    free(p);
    fclose(fp);
    return head;
}
//添加学生
struct student *add_stu(students *phead)
{
    FILE *fp=NULL;
    students *p;
    students *s,*r;
    p=phead;
    int nid,flag=0;
    int flag2=1;
    /*while(p->next!=NULL){            //求得尾指针
          p=p->next;
    }
    r=p;
    p=phead;*/
      fp=fopen("student","wb");
    while(flag==0)                             //控制是否继续添加
     {
        p=phead;
    printf("输入你要添加学生的学号\n");
      scanf("%d",&nid);
      while(p!=NULL){                      //是否存在重学号
           if(nid==p->id){
           printf("用户已存在,重新输入学号\n");flag2=0;
           break;
              }else{
              flag2=1;
              }
              p=p->next;
          }
            if(flag2==1){
                int nid,npasswd,nage;
                char nsex,nclass[20], nam[20];
                float ma,cyuy,yw;
                getchar();
                fflush(stdin);
                printf("请输入学生的学号,姓名,密码,性别,年龄,班级,"
                            "数学成绩,c语言成绩,语文成绩\n");
                scanf("%d",&nid);
                while(getchar()!='\n');
                gets(nam);
                scanf("%d",&npasswd);
                while(getchar()!='\n');
                nsex=getchar();
                scanf("%d",&nage);
                while(getchar()!='\n');
                gets(nclass);
                scanf("%f",&ma);
                scanf("%f",&cyuy);
                scanf("%f",&yw);
                s=malloc(sizeof(students));            //动态创建内存
                s->id=nid;
                s->stuna.passwd=npasswd;
                s->stuna.sex=nsex;
                s->stuna.age=nage;
                strcpy(s->stuna.class,nclass);
                strcpy(s->stuna.name,nam);
                s->math=ma;
                s->c=cyuy;s->yuwen=yw;
            //    fwrite(s,sizeof(students),1,fp);
            //    s=m;
                if(phead==NULL)
                {
                    phead=s;
                    phead->next=NULL;
                }
                else
                {
                    r=phead;
                    while(r->next!=NULL){            //求得尾指针
                              r=r->next;
                        }
                    r->next=s;
                    s->next=NULL;
                }
                //    printf("是否保存信息y/n\n");
                //    if(getchar()=='y'||getchar()=='Y'){listtofile_stu(r);}
                 }
               printf("是否继续插入学生信息y/n\n");
               while(getchar()!='\n');     //防止下面getchar取得\n
                    if((getchar()=='n')||(getchar()=='N')){
                        flag=1;break;
                        }
      }
                listtofile_stu(s);
                    fclose(fp);
                //    stu_listtofile(phead->next,"student");
                    return phead;
}
//修改学生信息
 students *change_stu(students *phead){
    students *p;
    students *r;
//    FILE *fp=NULL;
//    fp=fopen("student","wb");
    int nid;
    int flag=0;
    int flag2=0;
    while(flag==0){
    printf("输入要修改学生学号\n");
    scanf("%d",&nid);
    //while(getchar()!='\n');
    p = phead;
     while(p!=NULL){                                                    //是否存在此学生
        // fread(p,sizeof(students),1,fp);
               if(nid==p->id){
              flag2=0;
               break;
                  }else{
              flag2=1;                                        //不存在此学生
                  }
                  p=p->next;
              }r=p;    p=phead;
     if(flag2==1){
         printf("此学生不存在\n");
     }
     else{
                      int num;
                      int npasswd=0,nage=0;
                      char nsex,nclass[20],nam[20];
                        float ma=0,cyuy=0,yw=0;
                        printf("输入要修改学生的信息1.学号2.姓名,3.密码,4.性别,5.年龄,6.班级"
                                "7.数学成绩,8.c成绩,9.语文成绩\n");
                     scanf("%d",&num);
                     switch(num){
                     case 1:printf("输入新的学号\n");
                                scanf("%d",&nid);
                                 r->id=nid;//free(r);
                                break;
                     case 2:printf("输入新的姓名\n");
                                 scanf("%s",nam);
                                 strcpy(r->stuna.name,nam);
                                 break;
                     case 3:printf("输入新的密码\n");
                               scanf("%d",&npasswd);r->stuna.passwd=npasswd;
                               break;
                     case 4:printf("输入新的性别\n");
                                    while(getchar()!='\n');
                                   nsex=getchar();r->stuna.sex=nsex;
                                    break;
                     case 5:printf("输入新的年龄\n");
                                    scanf("%d",&nage);r->stuna.age=nage;
                                    break;
                     case 6:printf("输入新的班级名\n");
                                    scanf("%s",nclass);
                                    strcpy(r->stuna.class,nclass);//free(r);
                                    break;
                     case 7:printf("输入新的数学成绩\n");
                                scanf("%f",&ma);
                                r->math=ma;//free(r);
                                break;
                     case 8:printf("输入新的c语言成绩\n");
                                scanf("%f",&cyuy);
                                r->c=cyuy;//free(r);
                                break;
                     case 9:printf("输入新的语文成绩\n");
                                scanf("%f",&yw);
                                r->yuwen=yw;//free(r);
                                break;
                     default :printf("不做修改\n");break;
                     }

                //     fwrite(r,sizeof(students),1,fp);
                     //free(r);
                    // r=NULL;
          }            // getchar();
                     //   getchar();
                    //    fflush(stdin);
                         //     listtofile_stu(r);
                              printf("修改成功\n");
                       printf("是否继续修改学生信息y/n\n");
                       while(getchar()!='\n');     //防止下面getchar取得\n
                            if((getchar()=='n')||(getchar()=='N')){
                                break;
                    }else{
                        flag=0;
                    }
    }
    //fclose(fp);
    return phead;
}
 //删除学生
void del_stu(students *phead){
    students *p;
    //students *r=NULL;
    int num;
    p=phead;
    //FILE *fp=NULL;
    //fp=fopen("student","wb");
    //char nname[20],nclass[20];
 
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vs2015+数据库,需要建的数据表如下: 1. “考试成绩管理系统用户登录”功能 具体要求: (1) 按照图示排列相应的控件,控件名称自定义,其中,界面中的图片可以不加; (2) 当输入正确的用户名和密码时,登录到主系统,如图所示,并且用户名或密码输入不正确时系统有所提示;当单击【取消】按钮时,用户名和密码被清空; (3) 程序中用到的数据库名为SCOREINFO,数据表名为userinfo,数据表结构如下图所示: (4) 数据表中的用户名和密码如下图。 2. 点击主窗体的“密码修改”菜单,完成“密码修改”功能,程序运行如下图所示: 具体要求: (1)此题必须使用数据库连接完成,始密码必须为数据表里有的数据,不使用数据库完成的为0分。 (2)需要建立数据库SCOREINFO及数据表userinfo,表的结构及数据第一部分的内容: (3)要有“始密码输入错误”、“始密码不能为空”及“两次输入密码不一致”的错误提示; (4)当单击【保存】按钮,新密码被更新到数据表中,不能更新的为0分; (5)单击【关闭】按钮,窗口关闭。 (6)3个Label;3个TextBox;2个Button 3. 完成“成绩查询”功能,程序运行如下图所示: 具体要求: (1) 按照图示排列相应的控件,界面下方是DataGridView控件; (2)程序用到的数据库名为SCOREINFO,数据表名为score,表结构如下: (3)完成的MainForm_Load事件处理程序:当加载窗体时,直接在窗体的dataGridView1控件中显示数据表的所有记录; (4)可以设查询条件:首先在组合框comboBox1中选择查询条件,并在textBox1中输入条件值(可以模糊查询,如按照姓名查询时,输入“王”,可以查所有姓王的同学的成绩),单击查询将结果显示在dataGridView1控件中。 (5)所需控件及属性:1个GroupBox,1个Label,Text为选择查询条件;1个ComboBox(Items:学号、姓名);1个TextBox;1个Button,Text为查询;1个DataGridView 4. 完成“课程信息修改”功能,程序运行如下图所示: 具体要求: (1)按照图示排列相应的控件,控件名称自定义,其中,程序刚开始运行时,“学分”和“课程编码”的文本框是只读的; (2)在数据库名为SCOREINFO中,创建数据表名为course,表结构如下: (3)当单击【查询】时,直接在窗体的dataGridView2控件中显示数据表的所有记录; (4)当选中DataGridView控件中的某一行记录时(DataGridView控件的Mouse_Click事件),“课程名字”、“学分”、“课程代码”文本框中分别显示该项对应的课程信息; (5)当选中某一行记录并单击【编辑】按钮时,【编辑】按钮变为【保存修改】,同时“学分”和“课程编码”的文本框恢复正常(ReadOnly属性为false);在文本框中修改相应的信息后单击【保存修改】,将修改后的数据更新到数据表中。 (6)所需控件及属性:1个GroupBox,3个Label;3个TextBox(textBox2属性ReadOnly为True,textBox3属性ReadOnly为True);2个Button;1个DataGridView 5. 完成“课程信息删除”功能,程序运行如下图所示: 具体要求: (1)按照图示排列相应的控件,控件名称自定义,其中,程序刚开始运行时,“学分”和“课程编码”的文本框是只读的; (2)数据表名为course,表结构同第4部分: (3)当单击【查询】时,直接在窗体的dataGridView控件中显示数据表的所有记录; (4)当选中DataGridView控件中的某一行记录时,“课程名字”、“学分”、“课程代码”文本框中分别显示该项对应的课程信息; (5)当选中某一行记录并单击【删除】按钮时,则该行从数据表中删除。 (6)所需控件:3个Label;3个TextBox(textBox2属性ReadOnly为True,textBox3属性ReadOnly为True);2个Button;1个DataGridView 6. 完成“课程信息添加”功能,程序运行如下图所示: 具体要求: (1)按照图示排列相应的控件,控件名称自定义; (2)程序用到的数据库和数据表名为course,表结构如下同第四部分: (3)当单击【查询】时,直接在窗体的dataGridView1控件中显示数据表的所有记 (4)当选中DataGridView控件中的某一行记录时,“课程名字”、“学分”、“课程代码”文本框中分别显示该项对应的课程信息; (5)当单击【添加】按钮时,在文本框中添加新的内容并将新内容添加到数据表中,并且在DataGridView控件中显示出新的课程信息 (6)所需控件:3个Label;3个TextBox;2个Button;1个DataGridView
学生管理系统程序 #include <iostream> using namespace std; #include <stdlib.h> double avg=0;//统计总分和加平均分权 const int mathp=4;//数学学分 const int cppp=5;//C++学分 const sum=70;//设置总学分 class Student { private: int num; char *name; char *sex; char *phone; char *rphone; double math; double cpp; Student* next; public: Student() {next=NULL;} ~Student(); void Push(Student **refhead,int num,char *name,char *sex,char *phone,char *rphone,double math,double cpp); void Delete(Student *head,int data); Student* Find(Student* head,int data); void Display(Student* head); int Length(Student* head); void Math(Student* head,int data); void Update(Student* head,int data); void Insert(); }; Student* head=new Student;//带头结点的头指针 void Student::Push(Student **refhead,int num,char *name,char *sex,char *phone,char *rphone,double math,double cpp) { Student* newnode=new Student;//新增加结点 newnode->num=num; newnode->name=name; newnode->sex=sex; newnode->phone=phone; newnode->rphone=rphone; newnode->math=math; newnode->cpp=cpp; newnode->next=*refhead; *refhead=newnode;//重置表头 } //遍历 void Student::Display(Student* head) { Student* temp; temp=head; if(temp->next==NULL)//判断空表 cout<<"没有学生!"; else {while(temp!=NULL)// { cout<<"学号:"<<temp->num<<"姓名:"<<temp->name<<"性别:"<<temp->sex<<"手机:"<<temp->phone<<"宿舍电话:"<<temp->rphone<<"数学成绩:"<<temp->math<<"C++成绩:"<<temp->cpp<<endl; temp=temp->next; } } return; } //人数 int Student::Length(Student* head) { Student* cur; cur=head; int count=0; while(cur!=NULL) { count++;//通过累加统计人数 cur=cur->next; } return count; } //查找 Student* Student::Find(Student* head,int data) { Student* cur=head; bool bo=false; while(cur!=NULL) { if(cur->num=data) { bo=true;//如果找到则改变bo的值 cout<<"学号:"<<cur->num<<"姓名:"<<cur->name<<"性别:"<<cur->sex<<"手机:"<<cur->phone<<"宿舍电话:"<<cur->rphone<<"数学成绩:"<<cur->math<<"C++成绩:"<<cur->cpp<<endl; break; } cur=cur->next; } if(bo==false)//通过判断bo的值判断找到与否 cout<<"没有这个人!"<<endl; return cur; } //删除 void Student::Delete(Student* head,int data) { Student *bef,*cur; bef=cur=head; while(cur!=NULL) { if(cur->num==data) break; else {bef=cur;cur=cur->next;} } if(cur==head)//如果是头结点则删除头结点 { head=cur->next; delete cur; } else { bef->next=cur->next; delete cur; } } //修改 void Student::Update(Student* head,int data) { Student* cur=head; bool bo=false; while(cur!=NULL) { if(cur->num==data) { bo=true; int a,b; char *c; double d; for(;;) //找到后提供各字段的修改 { cout<<"1修改学号|2修改姓名|3修改性别|4修改手机号|5修改宿舍电话号|6修改数学成绩|7修改C++成绩|8退出\n"; cin>>a; switch(a) { case 1:cout<<"输入新学号:"; cin>>b; cur->num=a; break; case 2:cout<<"输入新姓名:"; cin>>c; cur->name=c; break; case 3:cout<<"输入新性别:"; cin>>c; cur->sex=c; break; case 4:cout<<"输入新手机号:"; cin>>c; cur->phone=c; break; case 5:cout<<"输入新宿舍电话号:"; cin>>c; cur->rphone=c; break; case 6:cout<<"输入新数学成绩:"; cin>>d; cur->math=d; break; case 7:cout<<"输入C++成绩:"; cin>>d; cur->cpp=d; break; case 8:exit(1); break; default:cout<<"操作错误"; break; } } break; } } if(bo==false) cout<<"没有这个人!"<<endl; return; } //统计 void Student::Math(Student* head,int data) { Student* cur=head; bool bo=false; while(cur!=NULL) { if(cur->num=data) { bo=true; avg=cur->math*(mathp/sum)+cur->cpp*(cppp/sum);//计算总分和加平均分权的公式 break; } cur=cur->next; } if(bo==false){ cout<<"没有这个人!"<<endl; return; } cout<<"该生的总分和加平均分权="<<avg<<endl; return; } //录入 void Student::Insert() { head=NULL; int num; char name[8]; char sex[4]; char phone[11]; char rphone[7]; double math; double cpp; cout<<"请输入基本信息:\n"; cout<<"学号:"; cin>>num; cout<<"姓名:"; cin>>name; cout<<"性别:"; cin>>sex; cout<<"手机号:"; cin>>phone; cout<<"宿舍电话:"; cin>>rphone; cout<<"数学成绩:"; cin>>math; cout<<"C++成绩:"; cin>>cpp; Push(&head,num,name,sex,phone,rphone,math,cpp);//调用函数Push建立有序链表 } //用释构函数逐个释放空间 Student::~Student() { while(head!=NULL) { delete head; head=head->next; } } //程序主入口 void main() { for(;;) { head=NULL; Student s; int x; int data; cout<<"|1录入|2查找|3删除|4修改|5统计|6退出|\n"; cout<<"请作选择:\n"; cin>>x; switch(x) { case 1: start: s.Insert(); cout<<"继续吗?[Y/N]"; char ch; cin>>ch; if(ch=='y' || ch=='Y') goto start; s.Display(head); int l; l=s.Length(head); cout<<"一共有"<<l<<"个学生。"<<endl; break; case 2: cout<<"请输入你要查找的学生的学号:"; cin>>data; s.Find(head,data); break; case 3: cout<<"请输入你要删除的学生的学号:"; cin>>data; s.Delete(head,data); break; case 4: cout<<"请输入你要修改的学生的学号:"; cin>>data; s.Update(head,data); break; case 5: cout<<"请输入你要统计的学生的学号:"; cin>>data; s.Math(head,data); break; case 6: exit(1); break; default:cout<<"操作错误!"<<endl; break; } }}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值