zoukankan      html  css  js  c++  java
  • C语言学生管理系统(C语言课程设计/精简版)

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


    typedef struct student{
    char name[10];
    int num;
    int score;
    struct student* pnext;
    }STU;






    void input(STU* phead){
    STU* node = NULL;
        node = (STU*)malloc(sizeof(STU));
    node->pnext = NULL;
    printf("请输入该同学的姓名 ");
    scanf("%s",node->name);
    printf("请输入该同学的学号 ");
    scanf("%d",&node->num);
    printf("请输入该同学的成绩 ");
    scanf("%d",&node->score);
    FILE* fp = fopen("e:\Student_info.dat","a");
    if(fp == NULL)
    printf("文件打开失败 "); 
    if(phead->pnext == NULL){
    phead->pnext = node;
    fwrite(phead->pnext,sizeof(STU),1,fp);
    }
    else{
    while(phead->pnext != NULL){
    phead = phead->pnext;
    }
    phead->pnext = node;
    fwrite(phead->pnext,sizeof(STU),1,fp);
    }
    fclose(fp);
    }




    void viewer(STU* phead){
    FILE* fp = fopen("e:\Student_info.dat","r");
    STU* plist = NULL;
    plist = (STU*)malloc(sizeof(STU));
    plist->pnext = NULL;
    fread(plist,sizeof(STU),1,fp);
    if(fp == NULL){
    printf("未找到数据文件 ");
    Sleep(3000);
    }
    else{
    while(feof(fp) == 0){
    printf("该同学的姓名为: %s " , plist->name);
    printf("该同学的学号为: %d " , plist->num);
    printf("该同学的成绩为: %d " , plist->score);
    printf(" ");
    fread(plist,sizeof(STU),1,fp);
    }
    printf("请按任意键进行下一步操作 ");
    getch(); 
    }
    }




    void menu(){
    printf("1.录入信息 ");
    printf("2.查看信息 ");
    printf("0.退出 ");
    }




    int main(int argc,char** argv){
    system("color 1e");
    int select;
    STU* head = NULL;
    head = (STU*)malloc(sizeof(STU));
    head->pnext = NULL;
    while(1){
    system("cls");
    menu();
    printf("请输入您要选择的功能 ");
    printf("您选择的功能是: ");
    scanf("%d",&select);
    switch(select)
    {
    case 1: input(head);
    break;
    case 2: viewer(head);
    break;
    case 0: exit(1);
    break;
    default : printf("输入无效,请重新输入 ");
    break;
    }
    }


  • 相关阅读:
    批处理实现SQLServer数据库备份与还原
    Axapta物流模块深度历险(二)
    Axapta4.0Tech
    Script#
    Axapta物流模块深度历险(一)
    Agrs Class
    折半的意义
    个人性格
    诚实
    英语学习闪存
  • 原文地址:https://www.cnblogs.com/viplanyue/p/12700744.html
Copyright © 2011-2022 走看看