| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 818 人关注过本帖
标题:谁能帮我改正一下这个程序啊 万分感谢啊 !!!!!!!1
只看楼主 加入收藏
我爱下载102
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2013-1-5
收藏
得分:0 
回复 9楼 不玩虚的
哈哈  是的是的  还要谢谢你呢
2013-01-07 18:55
我爱下载102
Rank: 2
等 级:论坛游民
帖 子:15
专家分:10
注 册:2013-1-5
收藏
得分:0 
回复 7楼 allmy34
高手!谢谢啦
2013-01-07 19:13
ggx7061131
Rank: 2
等 级:论坛游民
威 望:1
帖 子:21
专家分:12
注 册:2012-7-5
收藏
得分:2 
#include <iostream>
#include <stdio.h>
#include<stdlib.h>
#include<conio.h>
#include <string.h>
using namespace std;
#include <io.h>
#define NULL 0
#define LEN sizeof(struct student)

struct student   
{
long int num;
char name[20];
int age;
char sex[4];
char address[30];
long int  tele_num;
struct student *next;
};
int TOTAL_NUM = 0;
struct student *head = NULL;
void record();
void insert(struct student *stu);
void display(struct student *stu);
void displayAll();
void query();
void query_by_num();
void del_by_num();
void freeAll();
void devise(struct student *p);
//系统主菜单
void main()
{
    int choice;
    choice = -1;
do
    {
        printf("\n\n\n");
        printf("\t\t\t--------------------------------\n");
        printf("\t\t\t|        学生信息管理系统      |\n");  
        printf("\t\t\t--------------------------------\n");               
        printf("\t\t\t+    [1]----录入学生信息       +\n");
        printf("\t\t\t+    [2]----浏览学生信息       +\n");
        printf("\t\t\t+    [3]----查询学生信息       +\n");
        printf("\t\t\t+    [4]----删除学生信息       +\n");
        printf("\t\t\t+    [0]----退出系统           +\n");
        printf("\t\t\t+*·*·*·*·*·*·*·*·*·*·+\n");
        printf("\t\t\t--------------------------------\n");
        printf("请输入您的选择:");
        scanf("%d", &choice);
        switch(choice)
        {
        case 0:
                freeAll();
                break;
        case 1:
                record();
                break;
        case 2:
                displayAll();
                break;
        case 3:
                query_by_num();
                break;
        case 4:
                del_by_num();
                break;

  default:
                printf("\n无效选项!");
                break;
        }
    }
    while(choice != 0);
}

//录入学生信息
void record()
{
int i=0;
struct student *p0,*head;   
char a;
do
{
p0 = (struct student *)malloc(LEN);
printf("请输入学生的学号:");
scanf("%ld",&p0->num);   
fflush(stdin);
printf("请输入学生的姓名:");
scanf("%s",p0->name);
fflush(stdin);
printf("请输入学生的年龄:");
scanf("%d",&p0->age);
fflush(stdin);
printf("请输入学生的性别:");
scanf("%s",p0->sex);
fflush(stdin);
printf("请输入学生的籍贯:");
scanf("%s",p0->address);
fflush(stdin);
printf("请输入学生的电话:");
scanf("%ld",&p0->tele_num);
fflush(stdin);

insert(p0);
printf("\n是否继续输入另外一个学生信息?(y/n)");
a=getchar();
i++;
}
while(a=='y' && i<=50);
TOTAL_NUM=i;
head=p0;
}

void insert(struct student *stu)
{
struct student *p0, *p1, *p2;

p1 = head;
p0 = stu;

if(head == NULL)
{
  head = p0;
  p0->next = NULL;
}
else
{
  while((p0->num > p1->num)&&(p1->next != NULL))
  {
      p2 = p1;
   p1 = p1->next;
  }
  if(p0->num <= p1->num)
  {
   if(head == p1)
   head = p0;
   else
   p2->next = p0;
   p0->next = p1;
  }
  else
  {
   p1->next = p0;
   p0->next = NULL;
  }  
}
TOTAL_NUM++;
}
void display(struct student *p)
{
printf("%ld\t%s\t%d\t%s\t%s\t%ld\t%s\n", p->num, p->name, p->age, p->sex,p->address, p->tele_num);
}
//浏览学生信息
void displayAll()
{
struct student *p;
printf("学生总数:%d\n", TOTAL_NUM);

if(head != NULL)
{ p=head;//少了这个
  do
{
printf("%10d%10s%10d%10s%10s\n",p->num,p->name,p->age,p->sex);
p=p->next;
} while(p!=NULL);
}
printf("\n");
}
//查询学生信息
void query()
{
int choice;
    choice = -1;
do
    {
        printf("\n");
        printf("+--------------------+\n");
        printf("| 按学号查询  请按 1 |\n");
            
  printf("| 取消        请按 0 |\n");
        printf("+--------------------+\n");
        printf("请输入您的选择:");
        scanf("%d", &choice);
      
        switch(choice)
        {
            case 0:
                return;
            case 1:
                query_by_num();
                break;
                        
            default:
                printf("\n无效选项!");
                break;
        }
    }
    while(choice != 0);
}
//按学号查询学生信息
void query_by_num()
{
int num;
struct student *p1;
printf("请输入学生的学号:");
scanf("%ld", &num);
if(head==NULL)
{
  printf("无学生记录!\n");
  return;
}
p1=head;
while(num!=p1->num && p1->next!=NULL)
  p1=p1->next;
if(num == p1->num)
{
  printf("\n 学 号\t姓 名\t年龄\t性别\t 地址\t        电话\t      \n");
  printf("-------------------------------------------------------------------------------  ");
  display(p1);
}
else
  printf("没有该学生记录,请检查!");
}

void  del_by_num()// 定义数据删除函数 //
{   
  int num;
  struct student *p1;
  printf("请输入要删除的学生学号:");
  scanf("%ld", &num);
  if(num==p1->num)
    {      
       p1=head;
       while(num!=p1->num && p1->next!=NULL)
       p1=p1->next;
       p1=head;
       printf("删除成功!%ld\n",num);
       display(p1=NULL);
       num=num-1;
    }
    else
        cout<<"输出无效"<<endl;   
}

void freeAll()
{
struct student *p1, *p2;
p1=p2=head;
while(p1)
{
  p2=p1->next;
  free(p1);
  p1=p2;
}
}
2013-01-08 11:43
快速回复:谁能帮我改正一下这个程序啊 万分感谢啊 !!!!!!!1
数据加载中...
 
   



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

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