学生通讯管理系统

 

C课程设计题目第一套 难度:难
设计一个《学生通讯录管理系统》,在动态链表程序的基础上, 设计要求如下
(必须使用结构体和链表等数据结构)
1建立文件
 存储文件使用指定文件名或默认文件名;
 可以不保存输入记录,但需要确认是否保存输入记录
 如果已有文件,只能在其后追加;
 新增记录可以不存入原文件中,以可以用原来的文件覆盖内存的内容;
可以将连个文件合并到一个文件中;
2文件的存取和显示
 可以单独存取文件;
 可以随时显示内存中记录的全部内容;
 可以直接存取默认文件或指定文件;
3删除记录
 可以按“姓名”或“电话”方式删除记录并更新内存链表内容;
 能给出被删除的信息,输出没有找到的信息;
 如果已经是空表,上出时应给出信息并返回主菜单;
 如果没有要删除的信息,输出没有找到的信息;
删除操作仅限于内存,只有执行记录时,才能覆盖原记录;
4查询记录
 可以按“姓名”或“电话”或“宿舍”方式查询记录
 能给出查询记录的信息;
如果查询的信息不存在,输出没有找到的信息;
5 整体功能
 a可以随时检索、删除、或增加新记录,保存或取消新的记录
 b使姓名可由 16位字符和数字的混合编码组成
 c使电话号码可由 18位字符和数字组成
d将输出信息加上输出信息信息栏,例如
 姓名    电话 性别 年龄 生日       宿舍
 李四  1234   男    21    7月1日    东二333
      e使用菜单实现功能的正确的选择
      f 所有节点信息都是动态生成。
6测试程序
 应列出测试大纲对程序进行测试;

 应保证测试用例测试到程序的各种边缘情况

 

 

ex.h    //头文件

#define LEN sizeof(struct data)
#define NULL 0
#include<stdio.h>
#include<malloc.h>
#include<conio.h>
#include <graphics.h>

void face();
void drawmat(char *mat,int matsize,int x,int y,int color);

void mainmenu();
void menu3(char filename[10]);
void del(char filename[20]);
void add(char filename[10]);
void search(char filename[10]);
void setup();
void show(char filename[10]);
void hebin();

struct data
{
    char name[16];
    char tel[18];
    char sex;
    int age;
    char birth[10];
    char addres[10];
    struct data*next;
 };

#include"setup.c"
#include"show.c"
#include"search.c"
#include"add.c"
#include"mainmenu.c"
#include"menu3.c"
#include"del.c"
#include"hebin.c" 

//头文件

 

setup.c  //创立函数


  void setup()         /*创建链表,输入数据*/
{
    struct data *head;
    struct data *p1;
    struct data *p2;
    struct data *p;
    FILE *fp;
    char filename[10];
    int i,k,n=0;
    printf("how many records want to setup:");
    scanf("%d",&k);
    printf("input name tel sex age birth addres:/n");
    p1=p2=(struct data*) malloc(LEN);
    scanf("%s %s %c %d %s %s",p1->name,p1->tel,&p1->sex,&p1->age,p1->birth,
    p1->addres);
    head=NULL;
    head=p1;
    for(n=0;n<k-1;n++)
    {
        p1=(struct data*)malloc(LEN);
        scanf("%s %s %c %d %s %s",p1->name,p1->tel,&p1->sex,&p1->age,p1->birth,
        p1->addres);
        p2->next=p1;
        p2=p1;
    }

    p2->next=NULL;


 /*将数据写入文件*/
printf("save press 1,if not press 2:");
scanf("%d",&i);
if(i==1)
 {
    printf("input the filename to save:");
    scanf("%s",filename);

    fp=fopen(filename,"wb");
    for(p=head;p!=0;p=p->next)
  {if(fwrite(p,sizeof(struct data),1,fp)!=1)
    printf("file write error/n");
    };
fclose(fp);
printf("data has been setted up./n");
printf("press enter into mainmenu");
getch();
  }

}   //创立函数

 

search.c  //查找函数

void search(char filename[10])
{  int n,j=0;
   FILE*fp;
   struct data p,head;
   char name[16];
   char tel[18];
   char addres[10];
    printf("in which way to check:/n");
    printf("*************************/n");
    printf("    1------by name/n");
    printf("    2------by tel/n");
    printf("    3------by addres/n");
    printf("    4------back to menu3/n");
    printf("*************************/n");
    printf("choose please:");
    scanf("%d",&n);
    while(n!=1&&n!=2&&n!=3&&n!=4)
    { printf("error,choose again:");
      scanf("%d",&n);

     }

 

   if(n==1)
        { fp=fopen(filename,"rb");
          printf("the name want to search:");
          scanf("%s",name);
          printf("the result:/n");
          while(!feof(fp))
          { if(fread(&p,sizeof(struct data),1,fp)!=0)
            if(strcmp(name,p.name)==0)
             {printf("name  tel  sex  age  birthday  address/n ");
              printf("%s  %s  %c    %d    %s     %s/n",p.name,p.tel,p.sex,p.age,p.birth,
                p.addres);j=1;}
           };if(j==0) printf("can not find the information.");
          };
   if(n==2)
        { fp=fopen(filename,"rb");
          printf("the name want to search:");
          scanf("%s",tel);
          printf("the result:/n");
          while(!feof(fp))
          { if(fread(&p,sizeof(struct data),1,fp)!=0)
            if(strcmp(tel,p.tel)==0)
             {printf("name  tel  sex  age  birthday  address/n ");
              printf("%s  %s  %c    %d    %s     %s/n",p.name,p.tel,p.sex,p.age,p.birth,
                p.addres);j=1;}
           };if(j==0) printf("can not find the information.");
          };
   if(n==3)
        { fp=fopen(filename,"rb");
          printf("the name want to search:");
          scanf("%s",addres);
          printf("the result:/n");
          while(!feof(fp))
          { if(fread(&p,sizeof(struct data),1,fp)!=0)
            if(strcmp(addres,p.addres)==0)
             {printf("name  tel  sex  age  birthday  address/n ");
              printf("%s  %s  %c    %d    %s     %s/n",p.name,p.tel,p.sex,p.age,p.birth,
                p.addres);j=1;}
           };if(j==0) printf("can not find the information.");
          };
    if(n==4) {clrscr();menu3(filename);};
fclose(fp);
}    //查找函数

 

del.C //删除函数

void del(char filename[20])
{
 FILE *fp;
 struct data p,*head,*p1,*p2;
 char name[18];
 char tel[10];
 int i,n;
    printf("in which way to delete:/n");
    printf("*************************/n");
    printf("    1------by name/n");
    printf("    2------by tel/n");
    printf("    3------back to menu3/n");
    printf("*************************/n");
    printf("choose please:");
    scanf("%d",&i);
    while(i!=1&&i!=2&&i!=3)
    { printf("error,choose again:");
      scanf("%d",&i);
     };
         fp=fopen(filename,"rb");
     n=0;;
     p1=p2=(struct data*) malloc(LEN);
     fread(p1,sizeof(struct data),1,fp);

    while(!feof(fp))
      {   n=n+1;
          if(n==1) head=p1;
          else p2->next=p1;
          p2=p1;
          p1=(struct data*) malloc(LEN);
          fread(p1,sizeof(struct data),1,fp);

       };
      p2=p1;
      p2->next=NULL;

      if(i==1)
    {printf("input the name want to delete:");
     scanf("%s",name);
     if(head==NULL) {printf("/nlist null!/n");goto end;}
     p1=head;
    while(strcmp(name,p1->name)!=0&&p1->next!=NULL)
      {p2=p1;p1=p1->next;}
    if(strcmp(name,p1->name)==0)
      {if(p1==head) head=p1->next;
       else p2->next=p1->next;
      printf("delete:%s/n",name);
       }
    else {printf("%s not been found!/n",name);
          printf("press enter back to menu3.");getch();goto end;}
      }

     if(i==2)
     {printf("input the tel want to delete:");
     scanf("%s",tel);
     if(head==NULL) {printf("/nlist null!/n");goto end;}
     p1=head;
    while(strcmp(tel,p1->tel)!=0&&p1->next!=NULL)
      {p2=p1;p1=p1->next;}
    if(strcmp(tel,p1->tel)==0)
      {if(p1==head) head=p1->next;
       else p2->next=p1->next;
      printf("delete:%s/n",name);
       }
    else {printf("%s not been found!/n",tel);
        printf("press enter back to menu3.");getch();goto end;}
     }
  fclose(fp);
  fp=fopen(filename,"wb");
    for(p1=head;p1!=0;p1=p1->next)
  {if(fwrite(p1,sizeof(struct data),1,fp)!=1)
    printf("file write error/n");
    };
fclose(fp);

     if(i==3);

  end:{clrscr();menu3(filename);}


  }  //删除函数

 

add.c //添加函数

void add(char filename[10])         /*创建链表,输入数据*/
{   FILE *fp;
    struct data *head;
    struct data *p1;
    struct data *p2;
    int n=0; int i,j;
   printf("how many records want to add:");
   scanf("%d",&j);
   printf("input name tel sex age birth addres/n");
  head=p1=p2=(struct data*)malloc(LEN);
  scanf("%s %s %c %d %s %s",p1->name,p1->tel,&p1->sex,&p1->age,p1->birth,
    p1->addres);
 for(n=0;n<j-1;n++)
 {
    p1=(struct data*)malloc(LEN);
    scanf("%s %s %c %d %s %s",p1->name,p1->tel,&p1->sex,&p1->age,p1->birth,
    p1->addres);
    p2->next=p1;
    p2=p1;
 }
 p2->next=NULL;


    printf("add to data press 1,cover old data press 2,neither press 3:");
    scanf("%d",&i);
while(i!=1&&i!=2&&i!=3)
  { printf("error,press again:");
    scanf("%d",&i);
   };
    if(i==1)
      { fp=fopen(filename,"ab");
      do
       { if((n=fwrite(head,sizeof(struct data),1,fp))!=1)
         printf("file write error/n");
         head=head->next;
        }while(head!=0);fclose(fp);
       }
    if(i==2)
      {fp=fopen(filename,"wb");
       do
       { if((n=fwrite(head,sizeof(struct data),1,fp))!=1)
         printf("file write error/n");
         head=head->next;
        }while(head!=0);fclose(fp);
       }

}  //添加函数

 

hebin.c   //合并函数

void hebin()
{   FILE *fp1,*fp2,*fp;
    struct data p1,p2,p;
    char file1[10],file2[10];
      printf("input the name of the input file:");
      scanf("%s",file1);
      printf("input the name of the output file:");
      scanf("%s",file2);
    if((fp1=fopen(file1,"ab"))==NULL)
     {printf("cannot open this file");getch();goto end;}
    if((fp2=fopen(file2,"rb"))==NULL)
     {printf("cannot open this file");getch();goto end;}
   while(!feof(fp2))
    {  if(fread(&p2,LEN,1,fp2)!=0&&fwrite(&p2,LEN,1,fp1)==1);
     }
    printf("hepin finished.");
  end:fclose(fp2);fclose(fp1);getch(); clrscr();mainmenu();

 }  //合并函数

 

show.c //显示函数

void show(char filename[10])
{ FILE *fp;
  struct data e;
  fp=fopen(filename,"rb");


  while(!feof(fp))
   {
    if(fread(&e,sizeof(struct data),1,fp)!=0)
     printf("%s %s %c %d %s %s",e.name,e.tel,e.sex,e.age,e.birth,
     e.addres);printf("/n");
    };
    fclose(fp);
 }  //显示函数

 

mainmenu.C //主目录

void mainmenu()
{
  char filename[10];
  FILE *fp;

  gotoxy(25,5);    printf("*************************/n");
  gotoxy(25,6);    printf("    1----new /n");
  gotoxy(25,7);    printf("    2----hebing/n");
  gotoxy(25,8);    printf("    3----open/n");
  gotoxy(25,9);    printf("    4----exit/n");
  gotoxy(25,10);   printf("*************************/n");
  gotoxy(25,11);   printf("choose please:");

    switch(getch()-'0')
     {
       case 1: clrscr();setup();clrscr();mainmenu();break;
       case 2: clrscr();hebin();break;
       case 3: clrscr();
                        printf("input name of the file want to edit:");
                        scanf("%s",filename);clrscr();
                        if((fp=fopen(filename,"r"))==NULL)
                         {  gotoxy(25,5);printf("cannot open this file/n");
                            gotoxy(25,6);printf("press enter back to mainmenu.");
                            getch();
                            clrscr();mainmenu();
                          }
                        else {fclose(fp);menu3(filename);}break;

       case 4: exit(0);
       default: clrscr();mainmenu();
      }
 }  // 主目录

 

menu3.c //子目录

void menu3(char filename[10])
{  int j;

 gotoxy(25,5);  printf("you open the file is '%s'./n",filename);
 gotoxy(25,6);  printf("*************************/n");
 gotoxy(25,7);  printf("    1----show/n");
 gotoxy(25,8);  printf("    2----search/n");
 gotoxy(25,9);  printf("    3----delete/n");
 gotoxy(25,10); printf("    4----add/n");
 gotoxy(25,11); printf("    5----back/n");
 gotoxy(25,12); printf("*************************/n");
 gotoxy(25,13); printf("choose please:");
      scanf("%d",&j);
      while(j!=1&&j!=2&&j!=3&&j!=4&&j!=5)
  { printf("error,press again:");
    scanf("%d",&j);}
    switch(j)
     {
       case 1: clrscr();

               show(filename);break;
       case 2: clrscr();

               search(filename);break;
       case 3: clrscr();del(filename);break;
       case 4: clrscr();

               add(filename);break;
       case 5: clrscr(); mainmenu();break;
      };
   if(j!=5)
   { printf("press enter back to menu3/n");
     getch();
     clrscr();
    menu3(filename);};
} //子目录

 

main.c  //主函数

#include"ex.h"
main()
{

    mainmenu();

}  // 主函数

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值