| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 919 人关注过本帖
标题:学生信息管理系统,在添加教师时,如果添加第二个教师,系统就把第一个覆盖 ...
只看楼主 加入收藏
夏日_
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2015-3-31
结帖率:0
收藏
已结贴  问题点数:10 回复次数:1 
学生信息管理系统,在添加教师时,如果添加第二个教师,系统就把第一个覆盖了,怎么才能不覆盖?
执行时,先选择3,管理员登录(账号和密码都是admin),然后选2,添加教师,随便添加2个。
再选3,返回主菜单.在主菜单中选2,教师登录,这时候如果登录第一个添加的教师,就会显示
用户不存在,而第二个添加的教师则可以登录,就是说第一个教师的信息被第二个教师的信息
覆盖了,怎么才能不覆盖。求指导,感激不尽!!!!!




#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define STU_SIZE 120
#define TCH_SIZE 3
int student();
int teacher();
int admin();
int add_user();

//////////////////////////////////////////////////////////////////////////////////
struct User_info   /*结构体声明中不能直接赋值,要赋值只能在结构体变量中*/
{
    char number[20];
    char password[20];
    int math;
    int english;
    int chinese;
    int c_language;
    int clas;
}admin_info={"admin","admin"},student_info[STU_SIZE]/*={{"11","11"},{"22","22"}}*/,teacher_info[TCH_SIZE]/*={{"11","11"},{},{"22","22"}}*/,add_info;   /*结构体变量名不能与已存在的函数名相同,如此处定义结构体变量名为admin*/
                                   /*就会出错,因为已经定义了一个函数,函数名为admin,相互冲突*/
                                   
/////////////////////////////////添加用户////////////////////////////////////////////////
int add_user(char *aup)
{
    struct User_info *addip=&add_info;/*结构体sdd_info用来暂时存放从键盘读入的将要添加的用户信息*/
    struct User_info *adp,*add;
    int n,success=1,count=0,i;
    switch(*aup)
    {
        case 's':n=STU_SIZE;add=adp=student_info;break;
        case 't':n=TCH_SIZE;add=adp=teacher_info;break;
        default:printf("\n    input error number!\n");
    }
    while(1)
    {

//        for(adp=add;adp<add+n;adp++)
//        {
////            printf("%s",(*adp).number);
//            if(strcmp((*addip).number,(*adp).number)==0)  /*根据号码查找用户是否存在*/
//            {
//                printf("用户已经存在!\n");
//                success=0;
//            }
//        }
//        if(success==1)
//        {
            for(;adp<add+n;adp++)
            {
                printf("please input user's number:");
                scanf("%s",(*addip).number);
                strcpy((*adp).number,(*addip).number);
                printf("%s",(*adp).number);
                printf("please input user's password:");
                scanf("%s",(*adp).password);
                if(*aup=='s')
                {
                    printf("please input student's class:");
                    scanf("%s",&(*adp).clas);
                    printf("please input student's math score:");
                    scanf("%s",&(*adp).math);
                    printf("please input student's chinese score:");
                    scanf("%s",&(*adp).chinese);
                    printf("please input student's english score:");
                    scanf("%s",&(*adp).english);
                    printf("please input student's c language score:");
                    scanf("%s",&(*adp).c_language);   
                    printf("\n     add user information success!\n");
                    count=count+1;                    
//                    printf("\n\n%s\n\n",(*adp).number);
                    
                    break;
                }
//                printf("\n     add user information success!\n");
                count=count+1;
               
                break;
            }
            
            //printf("\n\n%d\n\n\n",count);
//            printf("\n\n%s\n\n",(*adp).number);
            admin_func();
        //adp++;
        //printf("%s",(*adp).number);
    }
   
    return 0;
}

 
int main()
{
    int choise;
    while(1)
    {
        printf("*********************************\n");    /*主界面菜单*/
        printf("*     student manage system     *\n");
        printf("*                               *\n");
        printf("*                               *\n");
        printf("*      1.Student  login         *\n");
        printf("*      2.Teacher  login         *\n");
        printf("*      3.Admin    login         *\n");
        printf("*      4.Exit                   *\n");
        printf("*********************************\n");
        printf("\nplease input your choise:");
        scanf("%d",&choise);
        switch(choise)
        {
            case 1:student();break;
            case 2:teacher();break;
            case 3:admin();break;
            case 4:exit(0);break;
            default:printf("\n    this user dose not exist!\n\n");
        }
    }
    return 0;
}

int student()
{
    char *sip,a='s';  //学生登陆标记
    if(user_login(&a)!=0)
        printf("login faile!\n");
    else
    {
        printf("i am student!\n");
        }
}


int teacher()
{
    char *tip,a='t';  //教师登陆标记
    if(user_login(&a)!=0)
        printf("login faile!\n");
    else
    {
        printf("i am teacher!\n");
    }
   
}


//////////////////////////////////////管理员//////////////////////////////////////
int admin()
{
    char *aip,a='a';  //管理员登陆标记
    if(user_login(&a)!=0)
    {
         printf("login faile!\n");
         return;
    }
    else
    {
        printf("\n    welcome administrator!\n");
        admin_func();
    }   
}
/////////////////////////////////////////////////////////////////////////////////
int admin_func()
{
    int choise;
    int b;//添加用户成功标记
    char s='s',t='t';
    while(1)
    {
        printf("***********************************\n");
        printf("  1.Add new student  \n");
        printf("  2.Add new teacher  \n");
        printf("  3.return previous menu \n");
        printf("***********************************\n");  
        printf("\nplease input your choise:");
        scanf("%d",&choise);
        switch(choise)
        {
            case 1:b=add_user(&s);break;
            case 2:b=add_user(&t);break;
            case 3:main();break;
            default:printf("\n    input error number!\n");
        }
        //if(!b)printf("进行下一步工作\n");     
    }   
}


////////////////////////////////用户登录//////////////////////////////////

/******************************************
*函数名:int user_login(char *pl)         
*功能:   实现用户登录,当输入密码连      
*           续错误三次时就自动退出。        
*                                          
*完成时间:2014.04.21  22:29               
*                                          
******************************************/
int user_login(char *pl)/*成功则返回0。*/
{
    struct User_info *login_p,*addr;
    char choise=*pl;
    int n,exist=0;
    switch(choise)
    {
        case 'a':addr=login_p=&admin_info;break;
        case 's':n=STU_SIZE;addr=login_p=student_info;break;
        case 't':n=TCH_SIZE;addr=login_p=teacher_info;break;
        default:printf("   this user dose not exist!\n\n");
    }
    int count=0;/*记录密码错误次数,用户号码错误不计。*/
    while(count<3)
    {
        char user_psw[20],user_num[20];/*定义数组未赋值,应该指明数组长度*/
        printf("please input user's number:");
        scanf("%s",user_num);
        for(login_p=addr;login_p<addr+n;login_p++)
        {
            if(strcmp(user_num,(*login_p).number)==0)  /*根据号码查找用户是否存在*/
            {     
                printf("please input user's password:");
                scanf("%s",user_psw);
                if(strcmp(user_psw,(*login_p).password)==0)/*判断密码是否正确*/
                    return 0;
                else
                {
                    count++;           /*错误次数加一*/
                    printf("password error!\n");
                    exist=1;
                } exist=1;   
            }   
        }
        if(exist==0)
        printf("\nthis user dose not exist!\n\n");
    }
    printf("    password error 3 times,system auto exit!\n");
    exit(0);      /*错误超过3次直接退出*/
                    /*调用此函数要加头文件stdlib.h*/   
}
//////////////////////////////////////////////////////////////////////////////
搜索更多相关主题的帖子: teacher 管理系统 include 管理员 admin 
2015-04-25 00:07
林月儿
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:138
帖 子:2277
专家分:10647
注 册:2015-3-19
收藏
得分:10 
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define STU_SIZE 120
#define TCH_SIZE 3
int student();
int teacher();
int admin();
int add_user();
int admin_func();
int user_login(char a);
//////////////////////////////////////////////////////////////////////////////////
struct User_info   /*结构体声明中不能直接赋值,要赋值只能在结构体变量中*/
{
    char number[20];
    char password[20];
    int math;
    int english;
    int chinese;
    int c_language;
    int clas;
}admin_info={"admin","admin"},student_info[STU_SIZE]/*={{"11","11"},{"22","22"}}*/,teacher_info[TCH_SIZE]/*={{"11","11"},{},{"22","22"}}*/,add_info;   /*结构体变量名不能与已存在的函数名相同,如此处定义结构体变量名为admin*/
                                   /*就会出错,因为已经定义了一个函数,函数名为admin,相互冲突*/
                                   
/////////////////////////////////添加用户////////////////////////////////////////////////
int add_user(char *aup)
{
    struct User_info *addip=&add_info;/*结构体sdd_info用来暂时存放从键盘读入的将要添加的用户信息*/
    struct User_info *adp,*add;
    int n,success=1,count=0,i;
    switch(*aup)
    {
        case 's':n=STU_SIZE;add=adp=student_info;break;
        case 't':n=TCH_SIZE;add=adp=teacher_info;break;
        default:printf("\n    input error number!\n");
    }
    while(1)
    {

//        for(adp=add;adp<add+n;adp++)
//        {
////            printf("%s",(*adp).number);
//            if(strcmp((*addip).number,(*adp).number)==0)  /*根据号码查找用户是否存在*/
//            {
//                printf("用户已经存在!\n");
//                success=0;
//            }
//        }
//        if(success==1)
//        {
            for(;adp<add+n;adp++)
            {
                printf("please input user's number:");
                scanf("%s",(*addip).number);
                strcpy((*adp).number,(*addip).number);
                printf("%s",(*adp).number);
                printf("please input user's password:");
                scanf("%s",(*adp).password);
                if(*aup=='s')
                {
                    printf("please input student's class:");
                    scanf("%s",&(*adp).clas);
                    printf("please input student's math score:");
                    scanf("%s",&(*adp).math);
                    printf("please input student's chinese score:");
                    scanf("%s",&(*adp).chinese);
                    printf("please input student's english score:");
                    scanf("%s",&(*adp).english);
                    printf("please input student's c language score:");
                    scanf("%s",&(*adp).c_language);   
                    printf("\n     add user information success!\n");
                    count=count+1;                    
//                    printf("\n\n%s\n\n",(*adp).number);
                    
                    break;
                }
//                printf("\n     add user information success!\n");
                count=count+1;
               
                break;
            }
            
            //printf("\n\n%d\n\n\n",count);
//            printf("\n\n%s\n\n",(*adp).number);
            admin_func();
        //adp++;
        //printf("%s",(*adp).number);
    }
   
    return 0;
}


int main()
{
    int choise;
    while(1)
    {
        printf("*********************************\n");    /*主界面菜单*/
        printf("*     student manage system     *\n");
        printf("*                               *\n");
        printf("*                               *\n");
        printf("*      1.Student  login         *\n");
        printf("*      2.Teacher  login         *\n");
        printf("*      3.Admin    login         *\n");
        printf("*      4.Exit                   *\n");
        printf("*********************************\n");
        printf("\nplease input your choise:");
        scanf("%d",&choise);
        switch(choise)
        {
            case 1:student();break;
            case 2:teacher();break;
            case 3:admin();break;
            case 4:exit(0);break;
            default:printf("\n    this user dose not exist!\n\n");
        }
    }
    return 0;
}

int student()
{
    char *sip,a='s';  //学生登陆标记
    if(user_login(a)!=0)
        printf("login faile!\n");
    else
    {
        printf("i am student!\n");
        }
}


int teacher()
{
    char *tip,a='t';  //教师登陆标记
    if(user_login(a)!=0)
        printf("login faile!\n");
    else
    {
        printf("i am teacher!\n");
    }
   
}


//////////////////////////////////////管理员//////////////////////////////////////
int admin()
{
    char *aip,a='a';  //管理员登陆标记
    if(user_login(a)!=0)
    {
         printf("login faile!\n");
         return 0;
    }
    else
    {
        printf("\n    welcome administrator!\n");
        admin_func();
    }   
}
/////////////////////////////////////////////////////////////////////////////////
int admin_func()
{
    int choise;
    int b;//添加用户成功标记
    char s='s',t='t';
    while(1)
    {
        printf("***********************************\n");
        printf("  1.Add new student  \n");
        printf("  2.Add new teacher  \n");
        printf("  3.return previous menu \n");
        printf("***********************************\n");  
        printf("\nplease input your choise:");
        scanf("%d",&choise);
        switch(choise)
        {
            case 1:b=add_user(&s);break;
            case 2:b=add_user(&t);break;
            case 3:main();break;
            default:printf("\n    input error number!\n");
        }
        //if(!b)printf("进行下一步工作\n");     
    }   
}


////////////////////////////////用户登录//////////////////////////////////

/******************************************
*函数名:int user_login(char *pl)         
*功能:   实现用户登录,当输入密码连      
*           续错误三次时就自动退出。        
*                                          
*完成时间:2014.04.21  22:29               
*                                          
******************************************/
int user_login(char pl)/*成功则返回0。*/
{
    struct User_info *login_p,*addr;
    char choise=pl;
    int n,exist=0;
    switch(choise)
    {
        case 'a':addr=login_p=&admin_info;break;
        case 's':n=STU_SIZE;addr=login_p=student_info;break;
        case 't':n=TCH_SIZE;addr=login_p=teacher_info;break;
        default:printf("   this user dose not exist!\n\n");
    }
    int count=0;/*记录密码错误次数,用户号码错误不计。*/
    while(count<3)
    {
        char user_psw[20],user_num[20];/*定义数组未赋值,应该指明数组长度*/
        printf("please input user's number:");
        scanf("%s",user_num);
        for(login_p=addr;login_p<addr+n;login_p++)
        {
            if(strcmp(user_num,(*login_p).number)==0)  /*根据号码查找用户是否存在*/
            {     
                printf("please input user's password:");
                scanf("%s",user_psw);
                if(strcmp(user_psw,(*login_p).password)==0)/*判断密码是否正确*/
                    return 0;
                else
                {
                    count++;           /*错误次数加一*/
                    printf("password error!\n");
                    exist=1;
                } exist=1;   
            }   
        }
        if(exist==0)
        printf("\nthis user dose not exist!\n\n");
    }
    printf("    password error 3 times,system auto exit!\n");
    exit(0);      /*错误超过3次直接退出*/
                    /*调用此函数要加头文件stdlib.h*/   
}
////////////////////////////////////////////////////////////////

剑栈风樯各苦辛,别时冰雪到时春
2015-04-25 11:17
快速回复:学生信息管理系统,在添加教师时,如果添加第二个教师,系统就把第一个 ...
数据加载中...
 
   



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

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