问题描述
采用顺序表,设计一个 QQ群名片信息管理系统,主要包含:QQ号码、昵称、性别、年龄、生日等属性。完成基本功能如下:
(1)初始化群名片;
(2)添加某一个QQ群中10名成员的名片信息;
(3)删除某位成员信息;
(4)根据QQ号码或昵称查找某位成员的信息;
(5)显示群成员信息。
扩展功能:
1.统计当前QQ群中共有多少联系人
2.销毁群名片
代码
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MaxSize 10 //最大人数
/* 成员信息 */
typedef struct Member
{
int Number;
char ID[20];
char Sex[4];
int Age;
char Birthday[20];
}Mem;
typedef struct SeqList *PtrToSeqList;
struct SeqList
{
Mem Data[MaxSize];
int count; //当前人数
};
typedef PtrToSeqList List;
void PrintMenu(); //打印菜单
List InitList(); //初始化表
int IsFuLL(List L); //是否为满
void AddMember(List L); //添加成员
int IsEmpty(List L); //是否为空
List DeleteMember(List L, int Q); //通过qq号删除成员
void FindMember(List L); //通过qq号或昵称查找成员
void PrintList(List L); //打印表
int main()
{
List L;
int choice, d, flag;
choice = 1;
flag = 0;
L = (List)malloc(sizeof(struct SeqList));
L->count = 0;
PrintMenu();
while(choice) //choice == 0 时退出系统
{
printf("请选择:");
scanf("%d", &choice);
if(flag == 1)
printf("名片已被销毁请先初始化名片!\n");
else
{
switch(choice)
{
case 1: //录入群成员信息
AddMember(L);
break;
case 2: //删除群成员信息
printf("请输入要删除成员的QQ:");
scanf("%d", &d);
L = DeleteMember(L, d);
break;
case 3: //查找成员信息
FindMember(L);
break;
case 4: //显示群成员信息
PrintList(L);
break;
case 5: //显示当前成员数
printf("当前有%d个成员\n", L->count);
break;
case 6: //清空名片
L = InitList();
break;
case 7: //销毁名片
free(L);
flag = 1;
printf("名片已被销毁!\n");
break;
}
}
if(choice == 8) //初始化名片
{
flag = 0;
L = InitList();
}
else if(choice == 9) //回到主菜单
PrintMenu();
else if(choice < 0 || choice > 9)
printf("非法输入!\n");
}
printf("谢谢使用!");
return 0;
}
void PrintMenu()
{
printf(" QQ群名片信息管理系统\n");
printf(" ________________________________\n\n");
printf(" 1 录入群成员信息\n");
printf(" ________________________________\n\n");
printf(" 2 删除群成员信息\n");
printf(" ________________________________\n\n");
printf(" 3 查找成员信息\n");
printf(" ________________________________\n\n");
printf(" 4 显示群成员信息\n");
printf(" ________________________________\n\n");
printf(" 5 显示当前成员数\n");
printf(" ________________________________\n\n");
printf(" 6 清空名片\n");
printf(" ________________________________\n\n");
printf(" 7 销毁名片\n");
printf(" ________________________________\n\n");
printf(" 8 初始化名片\n");
printf(" ________________________________\n\n");
printf(" 9 回到主菜单\n");
printf(" ________________________________\n\n");
printf(" 0 退出系统\n");
printf(" ________________________________\n\n");
}
List InitList()
{
List L;
L = (List)malloc(sizeof(struct SeqList));
L->count = 0;
printf("已初始化名片!\n");
return L;
}
int IsFull(List L)
{
return (L->count == MaxSize);
}
void AddMember(List L)
{
if(IsFull(L))
{
printf("成员已满!\n");
return;
}
printf("QQ号:");
scanf("%d", &L->Data[L->count].Number);
printf("昵称:");
scanf("%s", L->Data[L->count].ID);
printf("性别:");
scanf("%s", L->Data[L->count].Sex);
printf("年龄:");
scanf("%d", &L->Data[L->count].Age);
printf("生日:");
scanf("%s", L->Data[L->count].Birthday);
L->count++;
}
int IsEmpty(List L)
{
return (L->count == 0);
}
List DeleteMember(List L, int Q)
{
int i, j, tmp;
tmp = L->count;
if(IsEmpty(L))
printf("无成员!\n");
for(i = 0; i < L->count; i++)
{
if(L->Data[i].Number == Q)
{
for(j = i; j < L->count; j++)
L->Data[j] = L->Data[j + 1];
L->count--;
}
}
if(tmp == L->count)
printf("该成员未在群内!\n");
return L;
}
void FindMember(List L)
{
int i, fqq, choice, flag;
char fid[20];
if(IsEmpty(L))
{
printf("无成员!\n");
return ;
}
flag = 0; //查找标志
printf("查找\n1、qq:\t2、昵称:\n");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("请输入QQ号:");
scanf("%d", &fqq);
for(i = 0; i < L->count; i++)
{
if(fqq == L->Data[i].Number)
{
printf("以下为您要找的成员:");
printf("\nQQ号:%d", L->Data[i].Number);
printf("\n昵称:%s", L->Data[i].ID);
printf("\n性别:%s", L->Data[i].Sex);
printf("\n年龄:%d", L->Data[i].Age);
printf("\n生日:%s\n", L->Data[i].Birthday);
flag = 1;
}
}
break;
case 2:
printf("请输入昵称:");
scanf("%s", fid);
for(i = 0; i < L->count; i++)
{
if(!strcmp(fid, L->Data[i].ID)) //strcmp(str1, str2) 当 “str1 == str2” 时返回0
{
printf("以下为您要找的成员:");
printf("\nQQ号:%d", L->Data[i].Number);
printf("\n昵称:%s", L->Data[i].ID);
printf("\n性别:%s", L->Data[i].Sex);
printf("\n年龄:%d", L->Data[i].Age);
printf("\n生日:%s\n", L->Data[i].Birthday);
flag = 1;
}
}
break;
}
if(flag == 0)
printf("未找到改成员!\n");
}
void PrintList(List L)
{
int i;
if(IsEmpty(L))
{
printf("无成员!\n");
return ;
}
for(i = 0; i < L->count; i++)
{
printf("\n第%d个成员的信息:", i + 1);
printf("\nQQ号:%d", L->Data[i].Number);
printf("\n昵称:%s", L->Data[i].ID);
printf("\n性别:%s", L->Data[i].Sex);
printf("\n年龄:%d", L->Data[i].Age);
printf("\n生日:%s\n", L->Data[i].Birthday);
}
}
网友评论