鱼C论坛

 找回密码
 立即注册
查看: 1417|回复: 2

[已解决]c系统程序添加密码登录

[复制链接]
发表于 2022-6-21 11:48:53 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 19112915084 于 2022-6-21 16:22 编辑

/*学生管理系统*/
#include<stdio.h>
#include<string.h>//包含头文件string.h
#define MAX 40//定义MAX最大值为40
struct student{
        char name[20];
        int age;
        int num;
        char sex[10];
};

struct class_room{
        struct student st[MAX];        //定义多个学生
        int n;        //当前班级的人数
};

void printf_menu()//打印主菜单函数
{
        printf("        学生管理系统        \n");
        printf("*****************************\n");
        printf("|1、添加学生信息            |\n");
        printf("|2、显示所有学生信息        |\n");
        printf("|3、查询学生信息            |\n");
        printf("|4、删除学生信息            |\n");
        printf("|5、修改学生信息            |\n");
        printf("|6、退出                    |\n");
        printf("*****************************\n");
        printf("请输入相应的序号选择!       \n");
}

void add_student(struct class_room *WLW)//添加学生信息,其中struct class_room *WLW为结构体指针
{
        printf("请输入学生的姓名:\n");
        scanf("%s",WLW->st[WLW->n].name);        //数组名代表首地址
        printf("请输入学生的年龄:\n");
        scanf("%d",&WLW->st[WLW->n].age);        //取变量的地址
        printf("请输入学生的学号:\n");
        scanf("%d",&WLW->st[WLW->n].num);
        printf("请输入学生的性别:\n");
        scanf("%s",WLW->st[WLW->n].sex);
       
        WLW->n++;//班级人数加一
}

void show_student(struct class_room *WLW)//显示所有学生信息
{
        int i;
        for(i=0;i<WLW->n;i++)//WLW->n为当前班级的人数
        {
                printf("the %d student name is %s\n",i+1,WLW->st[i].name);//第一个学生
                printf("the %d student age is %d\n",i+1,WLW->st[i].age);
                printf("the %d student id is %d\n",i+1,WLW->st[i].num);
                printf("the %d student sex is %s\n",i+1,WLW->st[i].sex);
        }
}

int find_student(struct class_room *WLW)//查找指定学生
{
        int num,i;
        printf("请输入要查找的学生num:\n");
        scanf("%d",&num);
       
        for(i=0;i<WLW->n;i++)
        {
                if(num==WLW->st[i].num)
                {
                        printf("the student is exist!\n");
                        printf("the %d student name is %s\n",i+1,WLW->st[i].name);
                        printf("the %d student age is %d\n",i+1,WLW->st[i].age);
                        printf("the %d student num is %d\n",i+1,WLW->st[i].num);
                        printf("the %d student sex is %s\n",i+1,WLW->st[i].sex);
                        return i;
                }
        }
        printf("the student is not exist!\n");
        return -1;
}

void remove_student(struct class_room *WLW)//删除指定学生
{
        int ret,i;
        ret=find_student(WLW);
       
        if(ret!=-1)
        {
                for(i=ret;i<WLW->n-1;i++)
                {
                        strcpy(WLW->st[i].name,WLW->st[i+1].name);//由于是字符串类型复制使用头文件string.h中的strcpy复制函数
                        WLW->st[i].age=WLW->st[i+1].age;
                        WLW->st[i].num=WLW->st[i+1].num;
                        strcpy(WLW->st[i].sex,WLW->st[i+1].sex);
                }
               
                WLW->n--;
        }
        printf("该学生已经删除成功!\n");
}

void change_student(struct class_room *WLW)//修改学生信息
{
        int ret,choose;
        ret=find_student(WLW);
        if(ret!=-1)
        {
                loop1:
                        printf("修改学生信息的哪一项?\n");
                        printf("1、姓名\n");
                        printf("2、年龄\n");
                        printf("3、学号\n");
                        printf("4、性别\n");
                        scanf("%d",&choose);
                       
                        switch(choose)
                        {
                                case 1:
                                        printf("请输入新的学生姓名:\n");
                                        scanf("%s",WLW->st[ret].name);//输出的代表首地址,所以不需要&取地址
                                        break;
                                case 2:
                                        printf("请输入新的学生年龄:\n");
                                        scanf("%d",&WLW->st[ret].age);
                                        break;
                                case 3:
                                        printf("请输入新的学生学号:\n");
                                        scanf("%d",&WLW->st[ret].num);
                                        break;
                                case 4:
                                        printf("请输入新的学生性别:\n");
                                        scanf("%s",WLW->st[ret].sex);
                                        break;
                                default:
                                        printf("输出错误,请重新输入!\n");
                                        goto loop1;
                        }
                       
        }
}

int main()
{
        struct class_room WLW;//定义一个班级为WLW存储学生
        WLW.n=0;//初始化,学生人数为0
       
        while(1)//无限循环
        {
                loop:
                        printf_menu();//调用主菜单函数输出主菜单
                        int choose;//定义一个序号
                        scanf("%d",&choose);
       
                switch(choose)
                {
                        case 1:
                                add_student(&WLW);//添加学生
                                break;
                        case 2:
                                show_student(&WLW);//显示学生
                                break;
                        case 3:
                                find_student(&WLW);//查询学生
                                break;
                        case 4:
                                remove_student(&WLW);//删除学生
                                break;
                        case 5:
                                change_student(&WLW);//修改学生
                                break;
                        case 6:
                                return 0;//退出程序
                        default://若输出错误的序号,则跳转至重新输出
                                printf("输出错误,请重新输入!\n");
                                goto loop;       
                }
       
        }
}
最佳答案
2022-6-21 14:47:52
  1. /*学生管理系统*/
  2. #include<stdio.h>
  3. #include<string.h>//包含头文件string.h
  4. #define MAX 40//定义MAX最大值为40
  5. #include <windows.h>
  6. struct student{
  7.         char name[20];
  8.         int age;
  9.         int num;
  10.         char sex[10];
  11. };

  12. struct class_room{
  13.         struct student st[MAX];        //定义多个学生
  14.         int n;        //当前班级的人数
  15. };

  16. void printf_menu()//打印主菜单函数
  17. {
  18.         printf("*****************************\n");
  19.         printf("|1、添加学生信息            |\n");
  20.         printf("|2、显示所有学生信息        |\n");
  21.         printf("|3、查询学生信息            |\n");
  22.         printf("|4、删除学生信息            |\n");
  23.         printf("|5、修改学生信息            |\n");
  24.         printf("|6、退出                    |\n");
  25.         printf("*****************************\n");
  26.         printf("请输入相应的序号选择!       \n");
  27. }

  28. void add_student(struct class_room *WLW)//添加学生信息,其中struct class_room *WLW为结构体指针
  29. {
  30.         printf("请输入学生的姓名:\n");
  31.         scanf("%s",WLW->st[WLW->n].name);        //数组名代表首地址
  32.         printf("请输入学生的年龄:\n");
  33.         scanf("%d",&WLW->st[WLW->n].age);        //取变量的地址
  34.         printf("请输入学生的学号:\n");
  35.         scanf("%d",&WLW->st[WLW->n].num);
  36.         printf("请输入学生的性别:\n");
  37.         scanf("%s",WLW->st[WLW->n].sex);
  38.       
  39.         WLW->n++;//班级人数加一
  40. }

  41. void show_student(struct class_room *WLW)//显示所有学生信息
  42. {
  43.         int i;
  44.         for(i=0;i<WLW->n;i++)//WLW->n为当前班级的人数
  45.         {
  46.                 printf("the %d student name is %s\n",i+1,WLW->st[i].name);//第一个学生
  47.                 printf("the %d student age is %d\n",i+1,WLW->st[i].age);
  48.                 printf("the %d student id is %d\n",i+1,WLW->st[i].num);
  49.                 printf("the %d student sex is %s\n",i+1,WLW->st[i].sex);
  50.         }
  51. }

  52. int find_student(struct class_room *WLW)//查找指定学生
  53. {
  54.         int num,i;
  55.         printf("请输入要查找的学生num:\n");
  56.         scanf("%d",&num);
  57.       
  58.         for(i=0;i<WLW->n;i++)
  59.         {
  60.                 if(num==WLW->st[i].num)
  61.                 {
  62.                         printf("the student is exist!\n");
  63.                         printf("the %d student name is %s\n",i+1,WLW->st[i].name);
  64.                         printf("the %d student age is %d\n",i+1,WLW->st[i].age);
  65.                         printf("the %d student num is %d\n",i+1,WLW->st[i].num);
  66.                         printf("the %d student sex is %s\n",i+1,WLW->st[i].sex);
  67.                         return i;
  68.                 }
  69.         }
  70.         printf("the student is not exist!\n");
  71.         return -1;
  72. }

  73. void remove_student(struct class_room *WLW)//删除指定学生
  74. {
  75.         int ret,i;
  76.         ret=find_student(WLW);
  77.       
  78.         if(ret!=-1)
  79.         {
  80.                 for(i=ret;i<WLW->n-1;i++)
  81.                 {
  82.                         strcpy(WLW->st[i].name,WLW->st[i+1].name);//由于是字符串类型复制使用头文件string.h中的strcpy复制函数
  83.                         WLW->st[i].age=WLW->st[i+1].age;
  84.                         WLW->st[i].num=WLW->st[i+1].num;
  85.                         strcpy(WLW->st[i].sex,WLW->st[i+1].sex);
  86.                 }
  87.                
  88.                 WLW->n--;
  89.         }
  90.         printf("该学生已经删除成功!\n");
  91. }

  92. void change_student(struct class_room *WLW)//修改学生信息
  93. {
  94.         int ret,choose;
  95.         ret=find_student(WLW);
  96.         if(ret!=-1)
  97.         {
  98.                 loop1:
  99.                         printf("修改学生信息的哪一项?\n");
  100.                         printf("1、姓名\n");
  101.                         printf("2、年龄\n");
  102.                         printf("3、学号\n");
  103.                         printf("4、性别\n");
  104.                         scanf("%d",&choose);
  105.                        
  106.                         switch(choose)
  107.                         {
  108.                                 case 1:
  109.                                         printf("请输入新的学生姓名:\n");
  110.                                         scanf("%s",WLW->st[ret].name);//输出的代表首地址,所以不需要&取地址
  111.                                         break;
  112.                                 case 2:
  113.                                         printf("请输入新的学生年龄:\n");
  114.                                         scanf("%d",&WLW->st[ret].age);
  115.                                         break;
  116.                                 case 3:
  117.                                         printf("请输入新的学生学号:\n");
  118.                                         scanf("%d",&WLW->st[ret].num);
  119.                                         break;
  120.                                 case 4:
  121.                                         printf("请输入新的学生性别:\n");
  122.                                         scanf("%s",WLW->st[ret].sex);
  123.                                         break;
  124.                                 default:
  125.                                         printf("输出错误,请重新输入!\n");
  126.                                         goto loop1;
  127.                         }
  128.                        
  129.         }
  130. }

  131. int main()
  132. {
  133.         struct class_room WLW;//定义一个班级为WLW存储学生
  134.         WLW.n=0;//初始化,学生人数为0
  135.         char username[20];
  136.         char password[20];
  137.         
  138.         printf("        学生管理系统        \n");
  139.         printf("帐号:");
  140.         scanf("%s",&username);
  141.         printf("密码:");
  142.         scanf("%s",&password);
  143.         
  144.         if (strcmp(username,"admin") && strcmp(password,"123456"))
  145.         {
  146.                 printf("帐号或密码错误\n");
  147.                 return 0;
  148.                 }
  149.                
  150.                 printf("登录成功\n");
  151.       
  152.         while(1)//无限循环
  153.         {
  154.                 loop:
  155.                         printf_menu();//调用主菜单函数输出主菜单
  156.                         int choose;//定义一个序号
  157.                         scanf("%d",&choose);
  158.       
  159.                 switch(choose)
  160.                 {
  161.                         case 1:
  162.                                 add_student(&WLW);//添加学生
  163.                                 break;
  164.                         case 2:
  165.                                 show_student(&WLW);//显示学生
  166.                                 break;
  167.                         case 3:
  168.                                 find_student(&WLW);//查询学生
  169.                                 break;
  170.                         case 4:
  171.                                 remove_student(&WLW);//删除学生
  172.                                 break;
  173.                         case 5:
  174.                                 change_student(&WLW);//修改学生
  175.                                 break;
  176.                         case 6:
  177.                                 return 0;//退出程序
  178.                         default://若输出错误的序号,则跳转至重新输出
  179.                                 printf("输出错误,请重新输入!\n");
  180.                                 goto loop;      
  181.                 }
  182.       
  183.         }
  184. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2022-6-21 14:47:52 | 显示全部楼层    本楼为最佳答案   
  1. /*学生管理系统*/
  2. #include<stdio.h>
  3. #include<string.h>//包含头文件string.h
  4. #define MAX 40//定义MAX最大值为40
  5. #include <windows.h>
  6. struct student{
  7.         char name[20];
  8.         int age;
  9.         int num;
  10.         char sex[10];
  11. };

  12. struct class_room{
  13.         struct student st[MAX];        //定义多个学生
  14.         int n;        //当前班级的人数
  15. };

  16. void printf_menu()//打印主菜单函数
  17. {
  18.         printf("*****************************\n");
  19.         printf("|1、添加学生信息            |\n");
  20.         printf("|2、显示所有学生信息        |\n");
  21.         printf("|3、查询学生信息            |\n");
  22.         printf("|4、删除学生信息            |\n");
  23.         printf("|5、修改学生信息            |\n");
  24.         printf("|6、退出                    |\n");
  25.         printf("*****************************\n");
  26.         printf("请输入相应的序号选择!       \n");
  27. }

  28. void add_student(struct class_room *WLW)//添加学生信息,其中struct class_room *WLW为结构体指针
  29. {
  30.         printf("请输入学生的姓名:\n");
  31.         scanf("%s",WLW->st[WLW->n].name);        //数组名代表首地址
  32.         printf("请输入学生的年龄:\n");
  33.         scanf("%d",&WLW->st[WLW->n].age);        //取变量的地址
  34.         printf("请输入学生的学号:\n");
  35.         scanf("%d",&WLW->st[WLW->n].num);
  36.         printf("请输入学生的性别:\n");
  37.         scanf("%s",WLW->st[WLW->n].sex);
  38.       
  39.         WLW->n++;//班级人数加一
  40. }

  41. void show_student(struct class_room *WLW)//显示所有学生信息
  42. {
  43.         int i;
  44.         for(i=0;i<WLW->n;i++)//WLW->n为当前班级的人数
  45.         {
  46.                 printf("the %d student name is %s\n",i+1,WLW->st[i].name);//第一个学生
  47.                 printf("the %d student age is %d\n",i+1,WLW->st[i].age);
  48.                 printf("the %d student id is %d\n",i+1,WLW->st[i].num);
  49.                 printf("the %d student sex is %s\n",i+1,WLW->st[i].sex);
  50.         }
  51. }

  52. int find_student(struct class_room *WLW)//查找指定学生
  53. {
  54.         int num,i;
  55.         printf("请输入要查找的学生num:\n");
  56.         scanf("%d",&num);
  57.       
  58.         for(i=0;i<WLW->n;i++)
  59.         {
  60.                 if(num==WLW->st[i].num)
  61.                 {
  62.                         printf("the student is exist!\n");
  63.                         printf("the %d student name is %s\n",i+1,WLW->st[i].name);
  64.                         printf("the %d student age is %d\n",i+1,WLW->st[i].age);
  65.                         printf("the %d student num is %d\n",i+1,WLW->st[i].num);
  66.                         printf("the %d student sex is %s\n",i+1,WLW->st[i].sex);
  67.                         return i;
  68.                 }
  69.         }
  70.         printf("the student is not exist!\n");
  71.         return -1;
  72. }

  73. void remove_student(struct class_room *WLW)//删除指定学生
  74. {
  75.         int ret,i;
  76.         ret=find_student(WLW);
  77.       
  78.         if(ret!=-1)
  79.         {
  80.                 for(i=ret;i<WLW->n-1;i++)
  81.                 {
  82.                         strcpy(WLW->st[i].name,WLW->st[i+1].name);//由于是字符串类型复制使用头文件string.h中的strcpy复制函数
  83.                         WLW->st[i].age=WLW->st[i+1].age;
  84.                         WLW->st[i].num=WLW->st[i+1].num;
  85.                         strcpy(WLW->st[i].sex,WLW->st[i+1].sex);
  86.                 }
  87.                
  88.                 WLW->n--;
  89.         }
  90.         printf("该学生已经删除成功!\n");
  91. }

  92. void change_student(struct class_room *WLW)//修改学生信息
  93. {
  94.         int ret,choose;
  95.         ret=find_student(WLW);
  96.         if(ret!=-1)
  97.         {
  98.                 loop1:
  99.                         printf("修改学生信息的哪一项?\n");
  100.                         printf("1、姓名\n");
  101.                         printf("2、年龄\n");
  102.                         printf("3、学号\n");
  103.                         printf("4、性别\n");
  104.                         scanf("%d",&choose);
  105.                        
  106.                         switch(choose)
  107.                         {
  108.                                 case 1:
  109.                                         printf("请输入新的学生姓名:\n");
  110.                                         scanf("%s",WLW->st[ret].name);//输出的代表首地址,所以不需要&取地址
  111.                                         break;
  112.                                 case 2:
  113.                                         printf("请输入新的学生年龄:\n");
  114.                                         scanf("%d",&WLW->st[ret].age);
  115.                                         break;
  116.                                 case 3:
  117.                                         printf("请输入新的学生学号:\n");
  118.                                         scanf("%d",&WLW->st[ret].num);
  119.                                         break;
  120.                                 case 4:
  121.                                         printf("请输入新的学生性别:\n");
  122.                                         scanf("%s",WLW->st[ret].sex);
  123.                                         break;
  124.                                 default:
  125.                                         printf("输出错误,请重新输入!\n");
  126.                                         goto loop1;
  127.                         }
  128.                        
  129.         }
  130. }

  131. int main()
  132. {
  133.         struct class_room WLW;//定义一个班级为WLW存储学生
  134.         WLW.n=0;//初始化,学生人数为0
  135.         char username[20];
  136.         char password[20];
  137.         
  138.         printf("        学生管理系统        \n");
  139.         printf("帐号:");
  140.         scanf("%s",&username);
  141.         printf("密码:");
  142.         scanf("%s",&password);
  143.         
  144.         if (strcmp(username,"admin") && strcmp(password,"123456"))
  145.         {
  146.                 printf("帐号或密码错误\n");
  147.                 return 0;
  148.                 }
  149.                
  150.                 printf("登录成功\n");
  151.       
  152.         while(1)//无限循环
  153.         {
  154.                 loop:
  155.                         printf_menu();//调用主菜单函数输出主菜单
  156.                         int choose;//定义一个序号
  157.                         scanf("%d",&choose);
  158.       
  159.                 switch(choose)
  160.                 {
  161.                         case 1:
  162.                                 add_student(&WLW);//添加学生
  163.                                 break;
  164.                         case 2:
  165.                                 show_student(&WLW);//显示学生
  166.                                 break;
  167.                         case 3:
  168.                                 find_student(&WLW);//查询学生
  169.                                 break;
  170.                         case 4:
  171.                                 remove_student(&WLW);//删除学生
  172.                                 break;
  173.                         case 5:
  174.                                 change_student(&WLW);//修改学生
  175.                                 break;
  176.                         case 6:
  177.                                 return 0;//退出程序
  178.                         default://若输出错误的序号,则跳转至重新输出
  179.                                 printf("输出错误,请重新输入!\n");
  180.                                 goto loop;      
  181.                 }
  182.       
  183.         }
  184. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2022-6-21 16:20:11 | 显示全部楼层
看到了看到了,谢谢谢谢
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-4-24 01:55

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表