| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 3908 人关注过本帖
标题:请高手帮忙介绍一下这个程序?其中各个功能模块的流程图怎么画?非常感谢!
只看楼主 加入收藏
彤辉
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2012-1-3
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
请高手帮忙介绍一下这个程序?其中各个功能模块的流程图怎么画?非常感谢!
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int put(int op);
void search();
void add();
void delet();
void chang();
void sort();
void print1();

struct student{
    int stuid;
    char name[6];
    int score;
}stu[30];

main(){
    FILE *fp;
    int op,n,i;
    do{
        op=put(op);
        switch(op){
        case 0:
            printf("it is ok!");
            exit(0);
            break;
        case 1:
            printf("创建文件读取信息\n");
            if((fp=fopen("d:\\test.txt", "w"))==NULL){
                printf("can no open fill ");
                exit(1);
            }
            printf("创建成功!\n");
            printf("please input number of student:");
            scanf("%d",&n);
            fwrite(&n,sizeof(int),1,fp);
            printf("学号  姓名  成绩\n");
            for(i=0;i<n; i++){
                scanf("%d %s %d",&stu[i].stuid,stu[i].name,&stu[i].score);
            }
            fwrite(stu,sizeof(struct student), n, fp); /*一次写入n个数据项*/
            fclose(fp);
            printf("存储成功!\n");
            printf("-----------------------\n");
            printf("---------信息的输出------\n");
            if((fp=fopen("d:\\test.txt", "r"))==NULL){
                printf("can no open fill ");
                exit(1);
            }
            rewind(fp);
            fread(&n,sizeof(int),1,fp);
            printf("n=%d\n",n);
            printf("学号  姓名  成绩\n");
            for(i=0; i<n; i++){
                if(fread(&stu[i], sizeof(struct student), 1, fp) != 1 ){
                    printf("file read error!");
                    exit(1);
                }
                printf("%d %s %d",stu[i].stuid,stu[i].name,stu[i].score);
                printf("\n");
            }
            fclose(fp);
            break;
        case 2: search();break;
        case 3: add();break;
        case 4: delet();break;
        case 5: chang();break;
        case 6:sort();break;
        case 7:print1();break;
        }
    }while(op!=0);
}

void search(){
    int n,i,loc=0;
    FILE *fp;
   
    if((fp=fopen("d:\\test.txt", "r"))==NULL){
        printf("can no open fill ");
        exit(1);
    }
    rewind(fp);
    fread(&n,sizeof(int),1,fp);
    printf("n=%d\n",n);
    for(i=0; i<n; i++)
    {
        if(fread(&stu[i], sizeof(struct student), 1, fp) != 1 ){
            printf("file read error!");
            exit(1);
        }
    }
    printf("输入查询的学号:");
    scanf("%d",&n);
    for(i=0;i<n&&loc==0;i++){
        if(n==stu[i].stuid){
            loc=1;
            break;
        }
    }
    if(loc!=0){
        printf("已经查到信息!\n");
        printf("学号  姓名  成绩\n");
        printf("%d %s %d",stu[i].stuid,stu[i].name,stu[i].score);
        printf("\n");
    }
    else
        printf("没有要找的信息!\n");
}
void add(){
    int n,i;
    FILE *fp;
    if((fp=fopen("d:\\test.txt", "a+"))==NULL){
        printf("can no open fill ");
        exit(1);
    }
    rewind(fp);
    fread(&n,sizeof(int),1,fp);
    printf("n=%d\n",n);
    printf("添加信息\n");
    printf("please input number of student:");
    scanf("%d",&n);
    //fwrite(&n,sizeof(int),1,fp);
    printf("学号  姓名  成绩\n");
    for(i=0; i<n; i++){
        scanf("%d %s %d",&stu[i].stuid,stu[i].name,&stu[i].score);
    }
    fwrite( stu, sizeof(struct student), n, fp);/*一次写入n个数据项*/
    fflush(fp);
    printf("存储成功!\n");
    for(i=0;i<n;i++){
        printf("学号  姓名  成绩\n");
        printf("%d %s %d\n",stu[i].stuid,stu[i].name,stu[i].score);
    }
    fclose(fp);
   

}

void delet(){
    int n,i;
    char c;
    int flag=0;
    struct student *pt;
    FILE *fp;
    if((fp=fopen("d:\\test.txt", "r+"))==NULL){
        printf("can no open fill ");
        exit(1);
    }
    rewind(fp);
    fread(&n,sizeof(int),1,fp);
    printf("n=%d\n",n);
    for(i=0; i<n; i++){
        if(fread(&stu[i], sizeof(struct student), 1, fp) != 1 ){
            printf("file read error!");
            exit(1);
        }
    }
    pt=stu;
    printf("输入删除信息的学号:");
    scanf("%d",&n);
    for(i=0;i<n;i++){
        if(n==stu[i].stuid){
            flag=1;
            break;
        }
    }
    if(flag!=0){
        printf("学号  姓名  成绩\n");
        printf("%d %s %d",stu[i].stuid,stu[i].name,stu[i].score);
        printf("\n");
        printf("查到信息了!你真的想删除?y/n\n");
        scanf(" %c",&c);
        if(c=='Y'||c=='y'){
            printf("学号 姓名 成绩\n");
            printf("      ",pt->stuid,pt->name,pt->score);
            fwrite( stu, sizeof(struct student), n, fp);
            fclose(fp);
            fflush(fp);
        }
        else
            printf("没查到信息!\n");
        
        printf("存储成功!\n");
            printf("-----------------------\n");
            printf("---------信息的输出------\n");
            if((fp=fopen("d:\\test.txt", "r"))==NULL){
                printf("can no open fill ");
                exit(1);
            }
            rewind(fp);
            fread(&n,sizeof(int),1,fp);
            printf("n=%d\n",n-1);
            for(i=0; i<n-1; i++){
                if(fread(&stu[i], sizeof(struct student), 1, fp) != 1 ){
                    printf("file read error!");
                    exit(1);
                }
                printf("学号  姓名  成绩\n");
                printf("%d %s %d",stu[i].stuid,stu[i].name,stu[i].score);
                printf("\n");
            }
        fclose(fp);;
}
}
void chang(){
    int i,n,flag=0;
    FILE *fp;
    if((fp=fopen("d:\\test.txt", "r+"))==NULL){
        printf("can no open fill ");
        exit(1);
    }
    rewind(fp);
    fread(&n,sizeof(int),1,fp);
    printf("n=%d\n",n);
    for(i=0; i<n; i++){
        if(fread(&stu[i], sizeof(struct student), 1, fp) != 1 ){
            printf("file read error!");
            exit(1);
        }
    }
    printf("修改信息!\n");
    printf("输入修改信息的学号:");
    scanf("%d",&n);
    for(i=0;i<n;i++){
        if(n==stu[i].stuid){
            flag=1;
            break;
        }
    }
    if(flag!=0){
        printf("查找到了信息!\n");
        printf("%d %s %d\n",stu[i].stuid,stu[i].name,stu[i].score);
        printf("输入新数据:\n");
        printf("学号  姓名  成绩\n");
        scanf("%d %s %d",&stu[i].stuid,stu[i].name,&stu[i].score);
        printf("修改成功!\n");
        printf("%d %s %d\n",stu[i].stuid,stu[i].name,stu[i].score);
        fwrite(&stu[i],sizeof(struct student), 1, fp);
    }
    else
        printf("没有查到信息!\n");
   
    fclose(fp);
}
void sort(){
    int i,j,n,s,t;
    char temp[7];
    FILE *fp;
    if((fp=fopen("d:\\test.txt", "r"))==NULL){
        printf("can no open fill ");
        exit(1);
    }
    rewind(fp);
    fread(&n,sizeof(int),1,fp);
    printf("n=%d\n",n);

    for(i=0; i<n; i++){
        if(fread(&stu[i], sizeof(struct student), 1, fp) != 1 ){
            printf("file read error!");
            exit(1);
        }
    }
    for(i=0;i<n-1;i++){
        for(j=n-1;j>i;j--){
            
               s=stu[j-1].score;
            stu[j-1].score=stu[j].score;
            stu[j].score=s;

            strcpy(temp,stu[j-1].name);
            strcpy(stu[j-1].name,stu[j].name);
            strcpy(stu[j].name,temp);

            
            t=stu[j-1].stuid;
            stu[j-1].stuid=stu[j].stuid;
            stu[j].stuid=t;
        }
    }
    printf("排序成功!\n");
    printf("----输出排序结果-----\n");
    for(i=0; i<n; i++){
        printf("学号  姓名  成绩\n");
        printf("%d %s %d",stu[i].stuid,stu[i].name,stu[i].score);
        printf("\n");
    }
    fclose(fp);
}
void print1(){
    int i,n;
    float sum=0;
    float averg=0;
    FILE *fp;
    if((fp=fopen("d:\\test.txt", "r+"))==NULL){
        printf("can no open fill ");
        exit(1);
    }
    rewind(fp);
    fread(&n,sizeof(int),1,fp);
    printf("n=%d\n",n);
    for(i=0; i<n; i++){
        if(fread(&stu[i], sizeof(struct student), 1, fp) != 1 ){
            printf("file read error!\n");
            exit(1);
        }
    }
    for(i=0;i<n;i++){
        sum=sum+stu[i].score;
        averg=sum/n;
        
    }
    printf("sum=%4.2f\naverg=%4.2f\n",sum,averg);
    fclose(fp);
}
int put(int op){
    printf("-------学生成绩管理系统----------\n");
    printf("------0.退出系统---------------\n");
    printf("------1.从文件中读取学生信息-------\n");
    printf("------2.信息的寻找---------\n");
    printf("------3.信息的添加-------\n");
    printf("------4.信息的删除-------\n");
    printf("------5.信息的修改--------\n");
    printf("------6.信息的排序-------\n");
    printf("------7.成绩综合和平均分----\n");
    printf("请输入进行操作的选项0--7:\n");
    scanf("%d",&op);
    return op;
}
搜索更多相关主题的帖子: 信息 include search 流程图 
2012-01-03 13:28
hahayezhe
Rank: 15Rank: 15Rank: 15Rank: 15Rank: 15
来 自:湖南张家界
等 级:贵宾
威 望:24
帖 子:1386
专家分:6999
注 册:2010-3-8
收藏
得分:10 
这东西也需要流程图??

word、ppt里随便怎么画 都有这些相关图形的控件的
2012-01-03 13:47
绿茶盖儿
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:1
帖 子:363
专家分:1852
注 册:2011-9-3
收藏
得分:10 
你是什么思路就怎么画流程图啊
2012-01-03 16:06
快速回复:请高手帮忙介绍一下这个程序?其中各个功能模块的流程图怎么画?非常感 ...
数据加载中...
 
   



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

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