| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 883 人关注过本帖
标题:学生档案管理问题之二
只看楼主 加入收藏
fjf1016
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-12-27
收藏
 问题点数:0 回复次数:3 
学生档案管理问题之二
这个程序可以运行,但是在运行中有些问题!请高手帮帮忙!!!!
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

struct student{
   int num ;
   char name [10];
   char sex[5];
   int age;
 }student[10];

  void student_information();
  int search_num();
  void student_del();
  void student_edit();
 void page_title();

 void main()
  {
    menu: page_title("Menu operation");
 printf("Please use number keys select Options\n\n");
 printf("1 student_information\n2 search_num\n");
 printf("3 student_del\n\n4 student_edit\n5 exit\n");
        switch (getchar())
            {
        case '1':
            student_information() ;
            break;
        case '2':
            search_num();
            break;
        case '3':
        student_del();
            break;
        case '4':
            student_edit();
            break;
        case '5':
            printf("goodbye !\n");
            exit(0);
           }
      }
 void page_title(char *menu_item)
 {
 clrscr();
 printf(">>> Student performance management system <<<\n\n- %s -\n\n",menu_item);
 }
void return_confirm(void)
 {
 printf("\nPress any button to return......\n");
 getch();
 }
void student_information(void)
 {
 int n;
 page_title("Input students basic information");
 for(n=0;n<10;n++)
  if(student[n].num==0) break;
 printf("num:");
 scanf("%d",&student[n].num);
 printf("name:");
 scanf("%s",&student[n].name);
 printf("age:");
 scanf("%d",&student[n].age);
 return_confirm();
 }
int search_num()
 {
 int n,i;
 printf("plese input num:");
 scanf("%d",&i);
 for(n=0;n<10;n++)
  {
  if(student[n].num==i&&student[n].num!=0)
   {
   printf("num:%d\n",student[n].num);
   printf("name:%s\n",student[n].name);
   printf("age:%d\n",student[n].age);
   return n;
   }
  }
 printf("\ninput error or wrong number.\n");
 return -1;
 }
void student_del()
 {
 int n;
 page_title("delete students basic information");
 if((n=search_num())!=-1)
 { student[n].num=0;
 printf("\n!The students have been deleted.\n");
 }
 return_confirm();
 }
void student_edit()
 {
 int n;
 page_title("editor students basic information");
 if((n=search_num())!=-1)
  {
  printf("\nRe-enter new information:\nnum:");
  scanf("%d",&student[n].num);
  printf("name:");
  scanf("%s",&student[n].name);
  printf("age:");
  scanf("%d",&student[n].age);
  }
 return_confirm();
 }
在图2的地方不能返回了,本来设计的思想是返回继续的!

1.jpg (12.81 KB)
图片附件: 游客没有浏览图片的权限,请 登录注册


2.jpg (9.28 KB)
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 档案管理 void student include 学生 
2008-01-02 13:22
cosdos
Rank: 9Rank: 9Rank: 9
来 自:ShangHai
等 级:蜘蛛侠
威 望:6
帖 子:2109
专家分:1385
注 册:2007-6-19
收藏
得分:0 


C 语言要简洁、易读、函数要使用参数。

[[italic] 本帖最后由 cosdos 于 2008-1-2 16:17 编辑 [/italic]]

—>〉Sun〈<—
2008-01-02 16:14
cosdos
Rank: 9Rank: 9Rank: 9
来 自:ShangHai
等 级:蜘蛛侠
威 望:6
帖 子:2109
专家分:1385
注 册:2007-6-19
收藏
得分:0 
怎么又犯了上次的错误。

student[0].name  是 .name 数组的首地址。
收到的鲜花
  • fjf10162008-01-02 22:26 送鲜花  2朵   附言:回答很好

—>〉Sun〈<—
2008-01-02 16:34
cosdos
Rank: 9Rank: 9Rank: 9
来 自:ShangHai
等 级:蜘蛛侠
威 望:6
帖 子:2109
专家分:1385
注 册:2007-6-19
收藏
得分:0 
/* 还不够完善 */

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <conio.h>   // getch()

struct stu_t {
    int  num ;
    char name [10];
    char sex[5];
    int  age;
} student[10];

void return_confirm(void);
void student_initia(struct stu_t * p, int n);    // 初始化
void page_title(char * menu_item);
void student_information(void);
int  search_num(void);
void student_del(void);
void student_edit(void);

int main(void)
{
    int ch;
   
    student_initia(student, 10);     // 初始化
   
    page_title("Menu operation");
   

    ch = 0;
    while(ch != '5')
    {
        printf("Please use number keys select Options\n"
               "1) student_information    2) search_num\n"
               "3) student_del            4) student_edit\n"
               "5 exit\n\n"
              );

        ch = getchar();
        
        if(ch != '\n')
            while(getchar() != '\n')
                continue;

        switch(ch)
        {
            case '1':
                student_information();
                break;
            case '2':
                search_num();
                break;
            case '3':
                student_del();
                break;
            case '4':
                student_edit();
                break;
        }
    }
   
    printf("goodbye !\n");
   
    return 0;
}

void student_initia(struct stu_t * p, int n)
{
    int i;
    for(i = 0; i < n; i++)
        p[i].num = -1;
}

void page_title(char * menu_item)
{
    system("cls");    // 清屏  (system() stdlib.h)
    printf(">>> Student performance management system <<<\n\n- %s -\n\n",menu_item);
}

void return_confirm(void)
{
    printf("\nPress any button to return...\n");
    getch();
    putchar('\n');
}

void student_information(void)
{
    int i, k;
   
    page_title("Input students basic information");
    for(i = k = 0; i < 10; i++)
        if(student[i].num == -1)
        {
            do{
                printf("num: ");
                k = scanf("%d", &student[i].num);
                while(getchar() != '\n')
                    continue;
            }while(k != 1 || student[i].num <= 0);
            
            do{
                printf("name:");
                scanf("%9s", student[i].name);
                while(getchar() != '\n')
                    continue;
            }while(student[i].name[0] == '\0');
            
            do{
                printf("sex:");
                scanf("%4s", student[i].sex);
                while(getchar() != '\n')
                    continue;
            }while(student[i].name[0] == '\0');
            
            do{
                printf("age:");
                k = scanf("%d", &student[i].age);
                while(getchar() != '\n')
                    continue;
            }while(k != 1);
            
            return_confirm();
            break;
        }

}

int search_num(void)
{
    int n, i;
   
    do{
        printf("plese input num:");
        n = scanf("%d", &i);
        while(getchar() != '\n')
            continue;
    }while(n != 1);
   
    for(n = 0; n < 10; n++)
    {
        if(student[n].num == i && student[n].num != -1)
        {
            printf("num: %d\nname: %s\nage: %d\n", student[n].num
                                                 , student[n].name
                                                 , student[n].age);
            return n;
        }
    }
    printf("\nInput error or wrong number.\n");
    return -1;
}

void student_del(void)
{
    int n;
    page_title("Delete students basic information");
    if((n = search_num()) != -1)
    {
        student[n].num = -1;
        printf("\n!The students have been deleted.\n");
    }
    return_confirm();
}

void student_edit(void)
{
    int i, k;
    page_title("editor students basic information");

    i = search_num();
    if(i != -1)
    {
        printf("\nRe-enter new information:\n");

            do{
                printf("num: ");
                k = scanf("%d", &student[i].num);
                while(getchar() != '\n')
                    continue;
            }while(k != 1 || student[i].num <= 0);

            do{
                printf("name:");
                scanf("%9s", student[i].name);
                while(getchar() != '\n')
                    continue;
            }while(student[i].name[0] == '\0');

            do{
                printf("sex:");
                scanf("%4s", student[i].sex);
                while(getchar() != '\n')
                    continue;
            }while(student[i].name[0] == '\0');

            do{
                printf("age:");
                k = scanf("%d", &student[i].age);
                while(getchar() != '\n')
                    continue;
            }while(k != 1);
    }
    return_confirm();
}


[[italic] 本帖最后由 cosdos 于 2008-1-2 18:27 编辑 [/italic]]

—>〉Sun〈<—
2008-01-02 17:26
快速回复:学生档案管理问题之二
数据加载中...
 
   



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

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