| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3207 人关注过本帖
标题:功能5要如何实现,已有部分代码在附件中
只看楼主 加入收藏
SSY006
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2015-12-13
结帖率:75%
收藏
 问题点数:0 回复次数:11 
功能5要如何实现,已有部分代码在附件中
12345.zip (3.65 KB)

学生考勤信息管理 系统


1 建立文件
(1)考勤记录文件使用指定文件名 ARecord.txt;
(2)可以不保存输入记录,但需要确认是否保存输入记录
2.文件的存取和显示
(1)可以单独存取文件;
(2)可以随时显示内存中记录的全部内容;
3 删除记录
(1)可以按“学号”或“姓名”方式删除记录;
(2)能给出被删除的信息,进行删除,如果没有要删除的信息,输出没有找到的信息;
4 查询记录
(1)可以按“姓名”或“学号”方式查询个人信息和考勤登记信息记录
(2)可以按“任课教师”或“课程名称”方式查询课程信息
(3)能给出查询记录的信息;
(4)如果查询的信息不存在,输出没有找到的信息;
5 统计记录
(1)可以显示某生某门课考勤信息,并统计各类违纪情况次数
(2)可以显示某人所有门课考勤信息,并统计各类违纪情况次数
(3)可以显示某班所有课程考勤信息,并统计各类违纪情况次数
6 备份功能
(1)  编写函数 Backupdata 实现将 ARecord.txt 内容复制到备份文件 backup.txt 中,要求
不能使用该两个文件以外的任何文件。
7 整体功能
(1)可以随时检索、删除、或增加新记录,保存或取消新的记录
(2)姓名可由 16 位字符和数字的混合编码组成

(3)使电话号码可由 11 位字符和数字组成
(4)将输出信息加上输出信息栏,例如
7 测试数据要求
(1)不少于 3 门课信息(高数、英语、程序设计)。
(2)不少于 1 个班,每班不少于 10 个同学。每人每门课的考勤信息不少于 5 次。


附表 1:数据格式要求
个人信息


姓名    学号    班级    专业    电话    年龄    生日    宿舍    QQ
                                



课程信息


课程编号    课程名称    课程学分    任课教师    上课时间    上课次数    上课地点
                        



考勤登记信息


姓名    学号    班级    课程编号    课程名称    考勤违纪    第几次课    时间    地点
                    迟到/早退/
旷课/正常            
搜索更多相关主题的帖子: 个人信息 如何 记录 教师 课程 
2016-05-11 11:21
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:0 
只完成功能,未经调试,你可以自行调试

程序代码:
/*
1.阅读完此注释后请删除.
2.自定义path,path2,path3,不支持中文,新建一个空白文档ARecord.txt
3.把本txt重命名为xxx.c
4.在TC上运行程序
5.本程序没有实现功能5-统计信息,正因不完美才完美
6.TC不支持中文,所以本程序运行时显示的都是英文,具体含义查看英文单词对应意思或者看注释
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char path[200] = "ARecord.txt";     //均改为自己电脑TC\BIN目录下,文件名字不修改 
char path2[200] = "temp.txt";
char path3[200] = "backup.txt";
struct Student {        //个人信息 
    char name[30];    //学生姓名
    char id[30];    //学号
    char clazz[30];    //班级
    char major[30];    //专业
    char phone[11];        //电话
    int age;         //年龄
    char birth[30];    //生日
    char dormitory[30];    //宿舍 
    char QQ[30];
}stu[10] = {        //初始化学生信息 
    { "Xiao Ming","3113000000","Class 1","software","18819000000",20,"1996-01-01","712","12345678" },
    { "Na Ying","3113000001","Class 1","software","18819000001",21,"1996-10-01","512","123456781" },
    { "Rose","3113000002","Class 1","software","18819000002",20,"1996-02-01","712","123456782" },
    { "Jack","3113000003","Class 1","software","18819000003",20,"1996-12-01","712","123456783" },
    { "Hu LuWa","3113000004","Class 1","software","18819000004",20,"1996-02-01","502","123456784" },
    { "Wang Feng","3113000005","Class 1","software","18819000005",20,"1996-12-01","611","123456785" },
    { "Zhou Jielun","3113000006","Class 1","software","18819000006",20,"1996-05-01","533","123456786" },
    { "Hei Jialun","3113000007","Class 1","software","18819000007",20,"1996-03-19","713","123456787" },
    { "Na Polun","3113000008","Class 1","software","18819000008",20,"1996-03-29","712","123456788" },
    { "MO Tianlun","3113000009","Class 1","software","18819000009",20,"1996-04-01","712","123456789" }
};
struct lesson {        //课程信息 
    char id[30];    //课程编号
    char name[30];    //课程名称
    float score;    //学分
    char teacher[30];    //任课老师
    char time[30];    //上课时间
    int num;        //上课次数
    char address[30];    //上课地点 
}les[3] = {        //初始花课程信息 
    { "1000","Higher Mathematics",4.0,"Teacher 1","14:40-16:15",6,"teaching building 1-201" },
    { "1001","English",3.0,"Teacher 2","10:25-12:00",7,"teaching building 4-202" },
    { "1002","Application Design",4.0,"Teacher 3","16:15-18:00",8,"teaching building 5-501" }
};
struct KaoQin {        //考勤登记信息 
    struct Student st;        //学生信息 
    struct lesson ln;        //课程信息 
    int classnum;            //第几节课 
    enum Statuss { late, normal, absent, early }status;    //违纪状态 
}KQ;


void showStudent(struct Student stu[], int length)            //查看学生表的信息 
{
    char name_id[30];
    int i = 0, isFlag = 0;
    printf("Please enter Student Id or Student Name(enter 'all' to show all):");
    fflush(stdin);
    gets(name_id);
    for (i = 0; i<length; i++)
    {
        if (strcmp(name_id, "all") == 0)
        {
            if (!isFlag)
            {
                printf("\nSTUDENT NAME || ID || CLASS || MAJOR || PHONE || AGE || BIRTH || DORMITORY || QQ\n");
                isFlag = 1;
            }
            printf("%s || %s || %s || %s || %s || %d || %s || %s || %s\n", stu[i].name, stu[i].id, stu[i].clazz, stu[i].major, stu[i].phone, stu[i].age, stu[i].birth, stu[i].dormitory, stu[i].QQ);
        }
        else if (strcmp(stu[i].name, name_id) == 0 || strcmp(stu[i].id, name_id) == 0)
        {
            if (!isFlag)
            {
                printf("\nSTUDENT NAME || ID || CLASS || MAJOR || PHONE || AGE || BIRTH || DORMITORY || QQ\n");
            }
            printf("%s || %s || %s || %s || %s || %d || %s || %s || %s\n", stu[i].name, stu[i].id, stu[i].clazz, stu[i].major, stu[i].phone, stu[i].age, stu[i].birth, stu[i].dormitory, stu[i].QQ);
            isFlag = 1;
        }
    }
    if (!isFlag)
    {
        printf("Message no found.\n");
    }
}
int deleteMessage()            //根据学生姓名或学号删除考勤信息 
{
    char ack2, name_id[30];
    int i = 0, isFlag = 0;
    struct KaoQin KQ3, KQ4;
    FILE *fp2, *fp3;
    fp2 = fopen(path, "r");
    fp3 = fopen(path2, "w");
    fclose(fp3);
    fp3 = fopen(path2, "a");
    printf("Please enter Student Id or Student Name to delete:");
    fflush(stdin);
    gets(name_id);
    while (1)
    {
        //fseek(fp2,i*sizeof(struct KaoQin),0);                    
        fread(&KQ3, sizeof(struct KaoQin), 1, fp2);
        if (feof(fp2)) break;
        if (strcmp(KQ3.st.name, name_id) == 0 || strcmp(KQ3.st.id, name_id) == 0)
        {
            printf("StudentName:%s StudentId:%s Class:%s lessonId:%s lessonName:%s Breach:%d BreachTime:%d Time:%s Address:%s\n", KQ3.st.name, KQ3.st.id, KQ3.st.clazz, KQ3.ln.id, KQ3.ln.name, KQ3.status, KQ3.classnum, KQ3.ln.time, KQ3.ln.address);
            printf("Are u sure delete this one?(Y/N)    ");
            fflush(stdin);
            ack2 = getchar();
            if (ack2 == 'Y' || ack2 == 'y')
            {

            }
            else
            {
                fwrite(&KQ3, sizeof(struct KaoQin), 1, fp3);
                printf("Cancel Delete.\n");

            }
            isFlag = 1;
        }
        else
        {
            fwrite(&KQ3, sizeof(struct KaoQin), 1, fp3);
        }

    }
    if (!isFlag)
    {
        printf("Message no found.\n");
    }
    fclose(fp3);
    fclose(fp2);
    remove(path);
    rename(path2, path);
    printf("Delete success.\n");
    printf("Enter number 0 to go back:");
    scanf("%d", &i);
    if (i == 0)    return 0;
    else    return 1;
}
void showKaoQin()                //查看考勤表的信息 
{
    char name_id[30];
    int i, isFlag = 0;
    FILE *fp;
    struct KaoQin KQ2;
    fp = fopen(path, "r");
    printf("Please enter Student Id or Student Name(enter 'all' to show all):");
    fflush(stdin);
    gets(name_id);
    while (1)
    {
        //fseek(fp,i*sizeof(struct KaoQin),0);    
        fread(&KQ2, sizeof(struct KaoQin), 1, fp);
        if (feof(fp)) break;
        if (strcmp(name_id, "all") == 0)
        {
            printf("StudentName:%s StudentId:%s Class:%s lessonId:%s lessonName:%s Breach:%d BreachTime:%d Time:%s Address:%s\n", KQ2.st.name, KQ2.st.id, KQ2.st.clazz, KQ2.ln.id, KQ2.ln.name, KQ2.status, KQ2.classnum, KQ2.ln.time, KQ2.ln.address);
            isFlag = 1;
        }
        else if (strcmp(KQ2.st.name, name_id) == 0 || strcmp(KQ2.st.id, name_id) == 0)
        {
            printf("StudentName:%s StudentId:%s Class:%s lessonId:%s lessonName:%s Breach:%d BreachTime:%d Time:%s Address:%s\n", KQ2.st.name, KQ2.st.id, KQ2.st.clazz, KQ2.ln.id, KQ2.ln.name, KQ2.status, KQ2.classnum, KQ2.ln.time, KQ2.ln.address);
            isFlag = 1;
        }
        //i++;

    }
    fclose(fp);
    if (!isFlag)
    {
        printf("Message no found.\n");
    }

}

void showLesson(struct lesson les[], int len)        //查看lesson的信息 
{
    char name_id[30];
    int i, isFlag = 0;
    printf("Please enter Lesson Name or Teacher Name(enter 'all' to show all):");
    fflush(stdin);
    gets(name_id);
    for (i = 0; i<len; i++)
    {
        if (strcmp(name_id, "all") == 0)
        {
            if (!isFlag)
            {
                printf("\nLESSON ID || NAME || SCORE || TEACHER || TIME || NUM || ADDRESS\n");
                isFlag = 1;
            }
            printf("%s || %s || %2.1f || %s || %s || %d || %s\n", les[i].id, les[i].name, les[i].score, les[i].teacher, les[i].time, les[i].num, les[i].address);
        }
        else if (strcmp(les[i].name, name_id) == 0 || strcmp(les[i].teacher, name_id) == 0)
        {
            if (!isFlag)
            {
                printf("\nLESSON ID || NAME || SCORE || TEACHER || TIME || NUM || ADDRESS\n");
            }
            printf("%s || %s || %2.1f || %s || %s || %d || %s\n", les[i].id, les[i].name, les[i].score, les[i].teacher, les[i].time, les[i].num, les[i].address);
            isFlag = 1;
        }
    }
    if (!isFlag)
    {
        printf("Message no found.\n");
    }
}
int show(struct Student stu[], int length, struct lesson les[], int len)        //实现查看的功能 
{
    int a, i = 0;
    printf("Please choose:\n1.Query Student Message  2.Query KaoQin  3.Query Lesson  0.Go Back\n");
    scanf("%d", &a);
    switch (a)
    {
    case 1:
        showStudent(stu, length);
        break;
    case 2:
        showKaoQin();
        break;
    case 3:
        showLesson(les, len);
        break;
    case 0:
    default:;
    }

    printf("Enter number 0 to go back:");
    scanf("%d", &i);
    if (i == 0)    return 0;
    else    return 1;
}
void save(struct KaoQin KQ)                //保存一条考勤记录信息到ARecord.txt 
{
    FILE *fp;
    if ((fp = fopen(path, "a")) == NULL)
    {
        printf("Can not open file.\n");
        return;
    }
    if (fwrite(&KQ, sizeof(struct KaoQin), 1, fp) != 1)
    {
        printf("File write error.\n");
    }
    printf("File write ok.\n");
    fclose(fp);
}
int add(struct KaoQin KQ, struct Student stu[], int length, struct lesson les[], int len)        //输入考勤记录信息 
{
    char student_name_id[30], lesson_name_id[30], ack;
    int classnum, i, isFlag1 = 0, isFlag2 = 0, isFlag3 = 0, status_num;
    do {
        printf("Please enter Student Name or Student Num:");
        fflush(stdin);
        gets(student_name_id);
        for (i = 0; i<length; i++)
        {
            if (strcmp(stu[i].name, student_name_id) == 0 || strcmp(stu[i].id, student_name_id) == 0)
            {
                KQ.st = stu[i];
                isFlag1 = 1;
            }
        }
        if (!isFlag1)
        {
            printf("Message no found.\n");
        }
    } while (!isFlag1);
    do {
        printf("Please enter lesson Name or lesson Id:");
        fflush(stdin);
        gets(lesson_name_id);
        for (i = 0; i<len; i++)
        {
            if (strcmp(les[i].name, lesson_name_id) == 0 || strcmp(les[i].id, lesson_name_id) == 0)
            {
                KQ.ln = les[i];
                isFlag2 = 1;
            }
        }
        if (!isFlag2)
        {
            printf("Message no found.\n");
        }
    } while (!isFlag2);
    do {
        printf("Please enter a num as Student Status(1.late,2.normal,3.absent,4.early):");
        scanf("%d", &status_num);
        if (status_num == 1 || status_num == 2 || status_num == 3 || status_num == 4)
        {
            KQ.status = (enum Statuss)status_num;
            isFlag3 = 1;
        }
        if (!isFlag3) {
            printf("Error Enter.\n");
        }
    } while (!isFlag3);
    printf("Please enter classnum:");
    scanf("%d", &classnum);
    KQ.classnum = classnum;
    printf("save the record?(Y/N)  ");
    fflush(stdin);
    ack = getchar();
    if (ack == 'Y' || ack == 'y') {
        save(KQ);
    }

    printf("Enter number 0 to go back:");
    scanf("%d", &i);
    if (i == 0)    return 0;
    else    return 1;
}
int count()        //显示某生考勤信息 
{
    char name_id[30];
    int i, isFlag = 0;
    int latecount = 0, normalcount = 0, absentcount = 0, earlycount = 0;
    FILE *fp;
    struct KaoQin KQ2;
    fp = fopen(path, "r");
    printf("Please enter Student Id or Student Name:or class Name:");
    fflush(stdin);
    gets(name_id);
    while (1)
    {
        //fseek(fp,i*sizeof(struct KaoQin),0);    
        fread(&KQ2, sizeof(struct KaoQin), 1, fp);
        if (feof(fp)) break;
        if (strcmp(KQ2.st.name, name_id) == 0 || strcmp(KQ2.st.id, name_id) == 0)
        {
            printf("Please enter Lesson Name(enter 'all' to show all):");
            fflush(stdin);
            gets(name_id);

            //for(i=0;i<len;i++)
            {
                if (strcmp(name_id, "all") == 0)
                {
                    if (!isFlag)
                    {
                        printf("\nLESSON ID || NAME || SCORE || TEACHER || TIME || NUM || ADDRESS\n");
                        isFlag = 1;
                    }
                    printf("%s || %s || %2.1f || %s || %s || %d || %s\n", KQ2.ln.id, KQ2.ln.name, KQ2.ln.score, KQ2.ln.teacher, KQ2.ln.time, KQ2.ln.num, KQ2.ln.address);
                    switch (KQ2.classnum)
                    {
                    case 0:
                        latecount++;
                        break;
                    case 1:
                        normalcount++;
                        break;
                    case 2:
                        absentcount++;
                        break;
                    case 3:
                        earlycount++;
                        break;
                    }
                }
                else if (strcmp(KQ2.ln.name, name_id) == 0)
                {
                    if (!isFlag)
                    {
                        printf("\nLESSON ID || NAME || SCORE || TEACHER || TIME || NUM || ADDRESS\n");
                    }
                    printf("%s || %s || %2.1f || %s || %s || %d || %s\n", KQ2.ln.id, KQ2.ln.name, KQ2.ln.score, KQ2.ln.teacher, KQ2.ln.time, KQ2.ln.num, KQ2.ln.address);
                    switch (KQ2.classnum)
                    {
                    case 0:
                        latecount++;
                        break;
                    case 1:
                        normalcount++;
                        break;
                    case 2:
                        absentcount++;
                        break;
                    case 3:
                        earlycount++;
                        break;
                    }
                    isFlag = 1;
                }
            }
        }
        else if (strcmp(KQ2.st.clazz, name_id) == 0)
        {
            if (!isFlag)
            {
                printf("\nLESSON ID || NAME || SCORE || TEACHER || TIME || NUM || ADDRESS\n");
                isFlag = 1;
            }
            printf("%s || %s || %2.1f || %s || %s || %d || %s\n", KQ2.ln.id, KQ2.ln.name, KQ2.ln.score, KQ2.ln.teacher, KQ2.ln.time, KQ2.ln.num, KQ2.ln.address);
            switch (KQ2.classnum)
            {
            case 0:
                latecount++;
                break;
            case 1:
                normalcount++;
                break;
            case 2:
                absentcount++;
                break;
            case 3:
                earlycount++;
                break;
            }
        }
        //i++;

    }
    fclose(fp);
    if (!isFlag)
    {
        printf("Message no found.\n");
    }
    else
    {
        printf("\nlate || normal || absent || early\n");
        printf("\n%d   || %d     || %d       || %d   \n", latecount, normalcount, absentcount, earlycount);
    }

}


int copy()                //备份功能 
{
    char ack2, name_id[30];
    int i = 0;
    struct KaoQin KQ3;
    FILE *fp2, *fp3;
    fp2 = fopen(path, "r");
    fp3 = fopen(path3, "w");
    fclose(fp3);
    fp3 = fopen(path3, "a");
    while (1)
    {
        fseek(fp2, i*sizeof(struct KaoQin), 0);
        fread(&KQ3, sizeof(struct KaoQin), 1, fp2);
        fwrite(&KQ3, sizeof(struct KaoQin), 1, fp3);
        i++;
        if (!feof(fp2)) break;
    }
    printf("Back up success.\n");
    fclose(fp3);
    fclose(fp2);

    printf("Enter number 0 to go back:");
    scanf("%d", &i);
    if (i == 0)    return 0;
    else    return 1;
}
int main()            //主函数 
{
    int a, length = sizeof(stu) / sizeof(stu[0]), i = 0;
    int len = sizeof(les) / sizeof(les[0]);
    printf("--------------------------------------------------------------------------------\n");
    printf("-------------------------Welcome to StudentManager System-----------------------\n");
    printf("--------------------------------------------------------------------------------\n");
    while (!i)
    {
        printf("Please choose:\n");
        printf("1.add  2.show  3.delete  4.count  5.copy\n");
        scanf("%d", &a);
        switch (a)
        {
        case 1:                        //添加一条考勤记录 
            i = add(KQ, stu, length, les, len);
            break;
        case 2:                        //查看信息(学生信息/课程信息/考勤信息) 
            i = show(stu, length, les, len);
            break;
        case 3:                        //删除一条考勤记录 
            i = deleteMessage();
            break;
        case 4:                        //未实现的功能5 
            i = count();
            break;
        case 5:                        //备份 
            i = copy();
            break;
        default:
            i = 1;
            printf("select error");
        }
    }
    return 0;
}


2016-05-11 14:21
SSY006
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2015-12-13
收藏
得分:0 
为什么输入班级时候会自动跳出来了??我用的是TC3.0
2016-05-11 15:49
SSY006
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2015-12-13
收藏
得分:0 
自动跳出来是退出了运行的界面
2016-05-11 15:50
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:0 
班级没输对吧
2016-05-11 15:52
SSY006
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2015-12-13
收藏
得分:0 
是输入了学生学号,再输入要查看的考勤信息就会退出来
2016-05-11 15:55
SSY006
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2015-12-13
收藏
得分:0 
没输入对不是应该弹出message no found吗?
2016-05-11 15:56
SSY006
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2015-12-13
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册

输入了这个后就出来了
2016-05-11 16:00
SSY006
Rank: 1
等 级:新手上路
帖 子:24
专家分:0
注 册:2015-12-13
收藏
得分:0 
运行是可以运行的
2016-05-11 16:00
grmmylbs
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:54
帖 子:1409
专家分:5845
注 册:2016-2-14
收藏
得分:0 
你看下ARecord.txt里面有没有数据?需要先把数据存进去才能读到
2016-05-11 16:05
快速回复:功能5要如何实现,已有部分代码在附件中
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.163524 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved