C語言實現(xiàn)學生考勤系統(tǒng)
本文實例為大家分享了C語言實現(xiàn)學生考勤系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
項目要求:
學生考勤系統(tǒng)
功能:學生考勤系統(tǒng)應包含各班學生的全部信息。每個學生是一條記錄,包括姓名、性別、學號、出勤情況等。本系統(tǒng)可模擬考勤過程,記錄考勤結(jié)果,并能夠在課程結(jié)束后按照設定的考勤評分標準自動給出每個學生的考勤分數(shù)。
分步實施:
(1)初步完成總體設計,搭好框架,確定人機對話界面,確定函數(shù)個數(shù);
(2)最低要求:建立一個文件,包括同一個班的10個學生的必要信息,能對文件進 行補充、修訂、刪除。
采用結(jié)構(gòu)體數(shù)組讀入讀出文件(二進制形式寫進data.txt文件)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
const int N = 1010;
const int LEN = 20;
const int CLAstunumber = 10;//每個班CLAstunumber人?
typedef struct
{
?? ?char attdate[LEN];//日期
?? ?int atts;//出勤情況 0缺勤 1出勤 ?
}attdent;
typedef struct
{
?? ?char stname[LEN];
?? ?char sex[LEN];
?? ?int stnumber;
?? ?int core;
?? ?attdent stattdent[N];//最多紀錄N個日期的考勤情況?? ?
}studentinf;
int cnt;//記錄日期數(shù)組用到哪里?
studentinf students[CLAstunumber];
void menu()
{
?? ?printf("========================================================\n");
?? ?printf("0.學生信息錄入\n");
?? ?printf("1.開始考勤\n");
?? ?printf("2.修改學生考勤紀錄\n");
?? ?printf("3.生成并查看學生考勤分數(shù)\n");
?? ?printf("4.讀取數(shù)據(jù)\n");
?? ?printf("5.保存數(shù)據(jù)\n");
?? ?printf("6.退出\n");
?? ?printf("========================================================\n");
}
void studentinput()
{
?? ?//錄入操作?
?? ?for(int i = 0 ; i < CLAstunumber; i ++)
?? ?{
?? ??? ?printf("----------------------------------------\n");
?? ??? ?printf("請輸入學生姓名: ? ? ? ? ? ? ? ? ? ? ? |\n");
?? ??? ?studentinf student1;
?? ??? ?scanf("%s",student1.stname);
?? ??? ?printf("請輸入學生性別: ? ? ? ? ? ? ? ? ? ? ? |\n");
?? ??? ?scanf("%s",student1.sex);
?? ??? ?printf("請輸入學生學號: ? ? ? ? ? ? ? ? ? ? ? |\n");
?? ??? ?scanf("%d",&student1.stnumber);
?? ??? ?student1.core = 0;
?? ??? ?//(student1.stattdent[N]).attdate[LEN] = '0';
?? ??? ?students[i] = student1;
?? ??? ?printf("----------------------------------------\n");
?? ?}
}
void attcheck()
{
?? ?//考勤操作?
?? ?for(int i = 0;i < CLAstunumber ; i ++)
?? ?{
?? ??? ?students[i];
?? ??? ?printf("------------------------------\n");
?? ??? ?printf("姓名:%s\n",students[i].stname);
?? ??? ?printf("性別:%s\n",students[i].sex);
?? ??? ?printf("學號:%d\n",students[i].stnumber);
?? ??? ?printf("請輸入時間:XXXX/XX/XX\n");
?? ??? ?scanf("%s",(students[i].stattdent[cnt]).attdate);
?? ??? ?printf("請輸入該學生出勤情況:(0表示缺勤,1表示出勤)\n");
?? ??? ?scanf("%d",&(students[i].stattdent[cnt]).atts);
?? ??? ?cnt ++;
?? ??? ?printf("------------------------------\n");
?? ??? ?
?? ?}
}
void changeinf()
{
?? ?//遍歷修改
?? ?char fname[LEN];
?? ?char fdate[LEN];
?? ?printf("----------------------------------\n");
?? ?printf("請輸入學生姓名:\n");
?? ?scanf("%s",fname);
?? ?int stand1;//退出第一層for標準?
?? ?for(int i = 0;i < CLAstunumber; i ++)?
?? ?{
?? ??? ?if(!strcmp(fname,students[i].stname))
?? ??? ?{
?? ??? ??? ?printf("學生姓名:%s\n",students[i].stname);
?? ??? ??? ?printf("請輸入時間:(XXXX/XX/XX)\n");
?? ??? ??? ?scanf("%s",fdate);
?? ??? ??? ?for(int j = 0;j < cnt ; j ++)
?? ??? ??? ?{
?? ??? ??? ??? ?if(!strcmp(fdate,(students[i].stattdent[j]).attdate))
?? ??? ??? ??? ?printf("學生:%s",fname);
?? ??? ??? ??? ?printf("考勤時間:%s\n",fdate);
?? ??? ??? ??? ?printf("出勤情況:%d\n",(students[i].stattdent[j]).atts);
?? ??? ??? ??? ?printf("請輸入修改后的出勤情況:\n");
?? ??? ??? ??? ?scanf("%d",&(students[i].stattdent[j]).atts);
?? ??? ??? ??? ?printf("修改成功!\n");
?? ??? ??? ??? ?stand1 = 1;
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ??? ?if(stand1 == 1) break;
?? ??? ?}
?? ?}
?? ?printf("----------------------------------\n");
}
void checkcore()
{
?? ?//生成考勤分數(shù) = 出勤次數(shù)即分數(shù)?
?? ?for(int i = 0;i < CLAstunumber; i++)
?? ?{
?? ??? ?printf("----------------------------\n");
?? ??? ?printf("學生姓名:%s\n",students[i].stname);
?? ??? ?printf("學生性別:%s\n",students[i].sex);
?? ??? ?printf("學生學號:%d\n",students[i].stnumber);
?? ??? ?//計算分數(shù)
?? ??? ?students[i].core = 0;
?? ??? ?for(int j = 0;j < cnt ; j ++)
?? ??? ?{
?? ??? ??? ?students[i].core += (students[i].stattdent[j]).atts;?? ?
?? ??? ?}?
?? ??? ?printf("考勤分數(shù):%d\n",students[i].core);?? ?
?? ??? ?printf("----------------------------\n");
?? ?}
?? ?
}
void readdata()
{
?? ?FILE *fp = NULL;
?? ?fp = fopen("data.txt","rb");
?? ?
?? ?//讀出?
?? ?int i = 0;
?? ?while(!feof(fp))
?? ?{
?? ??? ?fread(&students[i],sizeof(studentinf),1,fp);
?? ??? ?i ++;
?? ?}
?? ?i --;
?? ?
?? ?cnt = i;
?? ?
?? ?fclose(fp); ??? ?
?? ?printf("讀取成功!\n");
}
void savedata()
{
?? ?FILE *fp = NULL;
?? ?fp = fopen("data.txt","wb");
?? ?//寫入
?? ?for(int i = 0;i < CLAstunumber ?; i ++)
?? ?{
?? ??? ?fwrite(&students[i],sizeof(studentinf),1,fp);
?? ?}
?? ?
?? ?fclose(fp); ?
?? ?printf("保存成功!\n");?? ?
}
int main()
{
?? ?menu();
?? ?int op;
?? ?while(1)
?? ?{
?? ??? ?scanf("%d",&op);
?? ??? ?if(op == 0)
?? ??? ?{
?? ??? ??? ?system("cls");
?? ??? ??? ?studentinput();
?? ??? ??? ?menu();
?? ??? ?}
?? ??? ?else if(op == 1)
?? ??? ?{
?? ??? ??? ?system("cls");
?? ??? ??? ?attcheck();
?? ??? ??? ?menu();
?? ??? ?}?
?? ??? ?else if(op == 2)
?? ??? ?{
?? ??? ??? ?changeinf();
?? ??? ??? ?menu();
?? ??? ?}
?? ??? ?else if(op == 3)
?? ??? ?{
?? ??? ??? ?system("cls");
?? ??? ??? ?checkcore();
?? ??? ??? ?menu();
?? ??? ?}
?? ??? ?else if(op == 4)
?? ??? ?{
?? ??? ??? ?system("cls");
?? ??? ??? ?readdata();
?? ??? ??? ?menu();
?? ??? ?}
?? ??? ?else if(op == 5)
?? ??? ?{
?? ??? ??? ?system("cls");
?? ??? ??? ?savedata();
?? ??? ??? ?menu();
?? ??? ?}
?? ??? ?else if(op == 6)
?? ??? ?{
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?else printf("input error!\n");
?? ?}
?? ??
}
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
C語言實現(xiàn)訪問及查詢MySQL數(shù)據(jù)庫的方法
這篇文章主要介紹了C語言實現(xiàn)訪問及查詢MySQL數(shù)據(jù)庫的方法,涉及C語言基于libmysql.lib實現(xiàn)訪問MySQL數(shù)據(jù)庫的相關操作技巧,需要的朋友可以參考下2018-01-01
C語言植物大戰(zhàn)數(shù)據(jù)結(jié)構(gòu)堆排序圖文示例
這篇文章主要為大家介紹了C語言植物大戰(zhàn)數(shù)據(jù)結(jié)構(gòu)堆排序的圖文示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05
Qt6遠程連接MySQL數(shù)據(jù)庫的簡單易上手版
在Qt應用程序里,可實現(xiàn)遠程MySQL服務器的連接操作,本文就來介紹一下Qt6遠程連接MySQL數(shù)據(jù)庫,具有一定的參考價值,感興趣的可以了解一下2023-11-11

