| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 542 人关注过本帖
标题:怎样在这个程序里面添加口令验证!!!!求解
取消只看楼主 加入收藏
遗忘的野狼
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-12-26
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
怎样在这个程序里面添加口令验证!!!!求解
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>

typedef struct student
{
    int no;
    char name[10];
    float score;
    struct student *next;
}stuinfo;

stuinfo *InputInfo()
{
    stuinfo *head,*p1,*p2;
    char select;
    head=p1=p2=NULL;
    head=p1=p2=(stuinfo*)malloc(sizeof(stuinfo));
    head->next=NULL;
    while(1)
    {
        printf("请输入学号:");fflush(stdin);scanf("%d",&p1->no);
        printf("请输入姓名:");scanf("%s",p1->name);
        printf("请输入成绩:");scanf("%f",&p1->score);
line1:    printf("是否继续录入学生信息?(y/n)");
        fflush(stdin);
        scanf("%c",&select);
        if(select=='y'||select=='Y')
        {
            p2=(stuinfo*)malloc(sizeof(stuinfo));
            p1->next=p2;
            p1=p2;
            p2->next=NULL;
        }
        else if(select=='n'||select=='N')
        {
            printf("学生信息录入完成!\n");
            system("PAUSE");
            p1->next=NULL;
            return head;
        }
        else
        {
            printf("对不起,您输入的有误,请重新输入...\n");
            goto line1;
        }
    }
}

void SaveToFile(stuinfo *head)
{
    stuinfo *p;
    p=head;
    FILE *fp;
    fp=fopen("C:\\file.txt","w");
    if(fp==NULL)
    {
        printf("文件打开或创建失败!\n");
        exit(0);
    }
    while(p!=NULL)
    {
        fprintf(fp,"%d %s %f\n",p->no,p->name,p->score);
        p=p->next;
    }
    printf("学生信息已经成功保存到文件中!\n");
    system("PAUSE");
    fclose(fp);
}

void ScoreSearch(stuinfo *head)
{
    stuinfo *p;
    p=head;
    int no_find,notfind=1;
    printf("请输入要查询学生成绩的相应学号:");
    scanf("%d",&no_find);
    while(p!=NULL)
    {
        if(no_find==p->no)
        {
            notfind=0;
            break;
        }
        p=p->next;
    }
    if(notfind)
    {
        printf("对不起,找不到相应学号的学生信息!\n");
        system("PAUSE");
        return;
    }
    printf("学号:%d 姓名:%s 成绩:%f\n",p->no,p->name,p->score);
    system("PAUSE");
}

void ScoreChange(stuinfo *head)
{
    stuinfo *p;
    p=head;
    int no_change,notfind=1;
    float newscore;
    printf("请输入要修改学生成绩的相应学号:");
    scanf("%d",&no_change);
    while(p!=NULL)
    {
        if(no_change==p->no)
        {
            notfind=0;
            break;
        }
        p=p->next;
    }
    if(notfind)
    {
        printf("对不起,找不到相应学号的学生信息!\n");
        system("PAUSE");
        return;
    }
    printf("请输入该学号对应的新成绩:");
    scanf("%f",&newscore);
    p->score=newscore;
    SaveToFile(head);
}

stuinfo *ScoreDelete(stuinfo *head)
{
    stuinfo *p,*p1;
    p=p1=head;
    int no_delete;
    printf("请输入要删除学生成绩的相应学号:");
    scanf("%d",&no_delete);
    if(head->no==no_delete)//第一个结点为删除结点
    {
        head=head->next;
        free(p);
        return head;
    }
    if(p->next==NULL)//最后一个结点为删除结点
    {
        while(p1->next!=p)
            p1=p1->next;
        p1->next=NULL;
        free(p);
        return head;
    }
    while(p!=NULL)//中间结点
    {
        if(p->no==no_delete)
        {
            while(p1->next!=p)
                p1=p1->next;
            p1->next=p->next;
            free(p);
            break;
        }
        p=p->next;
    }
    return head;
}

void Sort(stuinfo *head)
{
    int sort=1;
    stuinfo *q,*p,*r;
    stuinfo temp,max;
    p=head;
    q=p->next;
    while(p!=NULL)
    {
        max.no=p->no;
        strcpy(max.name,p->name);
        max.score=p->score;
        r=p;
        while(q!=NULL)
        {
            if(max.score<q->score)
            {
                max.no=q->no;
                strcpy(max.name,q->name);
                max.score=q->score;
                r=q;
            }
            q=q->next;
        }
        temp.no=p->no;
        strcpy(temp.name,p->name);
        temp.score=p->score;

        p->no=r->no;
        strcpy(p->name,r->name);
        p->score=r->score;

        r->no=temp.no;
        strcpy(r->name,temp.name);
        r->score=temp.score;

        q=p->next;
        p=p->next;
    }
    p=head;
    printf("学生总分信息显示如下:\n");
    printf("排名\t学号\t姓名\t成绩\n");
    while(p!=NULL)
    {
        printf("%d\t%d\t%s\t%f\n",sort,p->no,p->name,p->score);
        sort++;
        p=p->next;
    }
    system("PAUSE");
}

void main()
{
    int select;
    stuinfo *p;
    while(1)
    {
        system("cls");
        printf("学生成绩管理系统\n");
        printf("1.录入\n");
        printf("2.查询\n");
        printf("3.修改\n");
        printf("4.删除\n");
        printf("5.排名\n");
        printf("0.退出\n");
        printf("请选择...");
        scanf("%d",&select);
        switch(select)
        {
            case 1:
            {
                p=InputInfo();
                SaveToFile(p);
            }break;
            case 2:ScoreSearch(p);break;
            case 3:ScoreChange(p);break;
            case 4:p=ScoreDelete(p);break;
            case 5:Sort(p);break;
            case 0:exit(0);break;
            default:
            {
                printf("对不起,您输入有误,请重新输入...\n");
                system("PAUSE");
            }break;
        }
    }
}
搜索更多相关主题的帖子: include 姓名 
2013-12-26 17:26
遗忘的野狼
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-12-26
收藏
得分:0 
回复 楼主 遗忘的野狼
想加个口令密码,不知道在哪添加
2013-12-27 07:59
快速回复:怎样在这个程序里面添加口令验证!!!!求解
数据加载中...
 
   



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

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