客户信息管理系统(还有些问题,有需要的可以参考下,问题解决后继续完善)

这是用纯C语言编写的

#include<stdio.h>

#include<string.h>
#include<stdlib.h>
#define N 100


void menu();   //主菜单
void input();  //录入客户信息
void del();    //删除客户信息
void change(); //修改客户信息
void find();   //查找客户信息
void display();//输出客户信息
void paixu();  //客户信息排序
int load();    //导入函数
void baocun(int n); //保存函数
void find_name();//按姓名查询客户信息
void find_work();//按工作查询客户信息
void paixu_name();//按姓名排序客户信息
void add();//增加客户信息


struct kehu
{
char num[10];  //用户编号
char name[10]; //用户姓名
char sex[10];  //用户性别
char work[10]; //用户的工作
char phone[10];//用户的号码
};
struct kehu kehu[N];
char kehu1[10];


//主函数
void main()
{
system("color 3e");
int c;
do
{
menu();
printf("请输入你需要操作的序号:\n");
scanf("%d", &c);
switch (c)
{
case 1:input();
break;
case 2:del();
break;
case 3:change();
break;
case 4:find();
break;
case 5:display();
break;
case 6:paixu();
break;
case 7:add();
break;
case 8:exit(0);
break;
}
} while (1);
}


//主菜单
void menu()
{
printf("          客户管理系统     \n");
printf("--------------------------------------------\n");
printf("          管理者:zhangshuishou\n");
printf("                               \n");
printf("    1.录入客户信息    \n");
printf("    2.删除客户信息    \n");
printf("    3.修改客户信息    \n");
printf("    4.查找客户信息    \n");
printf("    5.浏览客户信息    \n");
printf("    6.客户信息排序    \n");
printf("    7.客户信息添加    \n");
printf("    8.退出系统        \n");
printf("----------------------------------------------\n");
}


//录入客户信息
void input()
{
int m, i;
printf("请输入你要增添的客户数目:\n");
scanf("%d", &m);
for (i = 0; i < m; i++)
{
printf("请输入客户的编号:\n");
scanf("%s", &kehu[i].num);
printf("请输入客户姓名:\n");
scanf("%s", &kehu[i].name);
printf("请输入客户性别:\n");
scanf("%s", &kehu[i].sex);
printf("请输入客户的工作:\n");
scanf("%s", &kehu[i].work);
printf("请输入客户的电话号码:\n");
scanf("%s", &kehu[i].phone);
getchar();
system("cls");
printf("\n客户信息档案创建完毕!");
}
baocun(m);
}


//保存文件函数
void baocun(int m)
{
int i;
   FILE *fp;
   if ((fp = fopen("D:\\客户信息.txt", "wb")) == NULL)
{
   printf("该文件打不开!");
  exit(0);
}
 for (i = 0; i < m; i++)
fwrite(&kehu[i], sizeof(struct kehu), 1, fp);
 //将客户信息输入文件中
fclose(fp);
}


//导入函数(进行文件内的数据读取,并且返回文件内客户的数量)
int load()
{


FILE *fp;
int i = 0;
if ((fp = fopen("D:\\客户信息.txt", "rb")) == NULL)
{
printf("该文件打不开!");
exit(0);
}
else
{
do
{
fread(&kehu[i], sizeof(struct kehu), 1, fp);
//将用户从文件中读取出来
i++;
} while (feof(fp) == 0);
}
fclose(fp);
return (i - 1);
}


//输出函数
void display()
{
int i;
int m = load();//从导入函数内获取到客户的数量
printf("\n客户编号\t姓名\t性别\t工作\t号码\n");
for (i = 0; i < m; i++)
printf("\n%s\t%s\t%s\t%s\t%s\n", kehu[i].num, kehu[i].name, kehu[i].sex, kehu[i].work, kehu[i].phone);
printf("按任意键继续\n");
getchar();
getchar();
system("cls");
}


//删除函数
void del()
{
int m = load();
int i, j, n, t, f;
char del_name[10];
printf("原来的客户信息:\n");
display();
printf("\n");
printf("请输入你要删除的客户姓名:\n");
scanf("%s", del_name);
for (f = 1, i = 0; f&&i < m; i++)
{
if (strcmp(kehu[i].name, del_name) == NULL)
{
printf("\n已找到此人,原始记录为:\n");
printf("\n客户编号\t姓名\t性别\t工作\t电话号码\n");
printf("\n%s\t%s\t%s\t%s\t%s\n", kehu[i].num, kehu[i].name, kehu[i].sex, kehu[i].work, kehu[i].phone);
printf("\n确实要删除此人信息请按1,不删除请按0\n");
scanf("%d", &n);
if (n == 1)//表示要删除该信息
{
for (j = i; j < m - 1; j++)
{
kehu[j] = kehu[j + 1];
}
f = 0;//表示已经查到该客户,退出循环
}
}
}
if (!f)
m = m - 1;
else
printf("对不起,查无此人!\n");
printf("\n浏览删除后的客户信息:\n");
baocun(m);
display();
printf("\n继续删除请按1,不再删除请按0\n");
scanf("%d", &t);
switch (t)
{
case 1:del();
break;
case 0:break;
default:break;
}
system("cls");
}


//查找函数
void find()
{
int t, f;
do
{
printf("\n按姓名查询请按1\n 按工作查询请按2\n进入函数按3\n ");
scanf("%d", &t);
if (t >= 1 && t <= 3)
{
f = 1;
break;
}
else
{
f = 0;
printf("您输入有误,请重新选择!\n");
}
} while (f == 0);
system("cls");
while (f == 1)
{
switch (t)
{
case 1:printf("按姓名查询\n");
find_name();
break;
case 2:printf("按工作查询\n");
find_work();
break;
case 3:main();
break;
default:break;
}
system("cls");
}
}


//按姓名查找函数
void find_name()
{
char name[10];
int i, t;
int m = load();//随时更新m的值,方便读取函数
printf("%s", name);
for (i = 0; i < m; i++)
if (strcmp(name, kehu[i].name) == 0)
{
printf("\n已找到此人,其记录为:\n");
printf("\n客户编号\t姓名\t性别\t工作\t生日\n");
printf("\n%s\t%s\t%s\t%s\t%s\n", kehu[i].num, kehu[i].name, kehu[i].sex, kehu[i].work, kehu[i].phone);
break;
}
if (i == m)
printf("\n对不起,查无此人\n");
printf("\n");
printf("返回查询函数请按1\n");
scanf("%d", &t);
switch (t)
{
case 1:find();
break;
default:break;
}
}


//按工作查询函数
void find_work()
{
char work[10];
int i, t;
int m = load();
printf("请输入要查找到的工作:\n");
scanf("%s", work);
for (i = 0; i < m;i++)
if (strcmp(work, kehu[i].work) == 0)
{
printf("\n已查到此人,其记录为:\n");
printf("\n客户编号\t姓名\t性别\t工作\t电话号码\n");
printf("\n%s\t%s\t%s\t%s\t%s\n", kehu[i].num, kehu[i].name, kehu[i].sex, kehu[i].work, kehu[i].phone);
break;
}
if (i == m)
printf("\n对不起,查无此人\n");
printf("返回查询函数请按1\n");
scanf("%d", &t);
switch (t)
{
case 1:find();
break;
default:break;
}
}


//修改函数
void change()
{
char num[10];
char name[20];
char sex[10];
char work[10];
char phone[10];
//用来存储修改后的信息
int b, c, i, n, t, f;
int m = load();
printf("\n原来客户信息:\n");
display();
printf("请输入你要修改的职称姓名:\n");
scanf("%s", name);
for (f = 1, i = 0; f&&i < m; i++)//f用来定义的作用是用来检查是否查询到要找的信息
{
if (strcmp(kehu[i].name, name) == 0)
{
printf("\n此人已找到,原始记录为:\n");
printf("\n客户编号\t姓名\t性别\t工作\t电话号码\n");
printf("\n%s\t%s\%s\t%s\t%s\n", kehu[i].num, kehu[i].name, kehu[i].sex, kehu[i].work, kehu[i].phone);
printf("\n确实要修改此人信息请按1  不修改请按0\n");
scanf("%d", &n);
if (n == 1)
{
printf("\n需要进行修改的选项\n1.客户编号 2.姓名 3.性别 4.工作 5.电话号码\n");
printf("请输入你想修改的那一项序号:\n");
scanf("%d", &c);
if (c > 4 || c < 1)
printf("\n选项错误,请重新选择!\n");
}
f = 0; //找到客户后,f变为0
}
}
if (f == 1) // 表示没有查到该客户 
printf("\n对不起,查无此人!\n");
do
{
switch (c)
{
case 1:printf("客户编号改为:\n");
scanf("%s",num);
strcpy(kehu[i - 1].num, num);
break;
case 2:printf("姓名改为:\n");
scanf("%s", name);
strcpy(kehu[i - 1].name, name);
break;
case 3:printf("性别改为:\n");
scanf("%s", sex);
strcpy(kehu[i - 1].sex, sex);
break;
case 4:printf("工作改为:\n");
scanf("%s", work);
strcpy(kehu[i - 1].work, work);
break;
case 5:printf("电话号码改为:\n");
scanf("%s", phone);
strcpy(kehu[i - 1].phone, phone);
break;
}
printf("\n");
printf("\n是否确定所修改的信息?  是  请按1\n 不,重新修改 请按2 \n");
scanf("%d", &b);
} while (b == 2);
printf("\n浏览修改后的所有客户的信息:\n");
printf("\n");
baocun(m);
display();
printf("\n继续修改请按1,不再修改请按0\n");
scanf("%d", &t);
switch (t)
{
case 1:change();
break;
case 0:break;
}
system("cls");
}


//排序函数
void paixu()
{
int k, f;
do
{
printf("\n按姓名排序请按1,进入主函数请按2\n");
scanf("%d", &k);
if (k >= 1 && k <= 2)
{
f = 1;
break;
}
else
{
f = 0;
printf("您输入有误,请重新选择!\n");
}
} while (f == 0);
system("cls");
while (f == 1)
{
switch (k)
{
case 1:printf("\n按姓名排序为(字母由小到大排列):\n");
paixu_name();
break;
case 2:system("cls");
main();
break;
}
system("cls");
}
}


//按姓名排序函数
void paixu_name()
{
int i, j, k;
int m = load();
for (i = 0; i < m - 1;i++)
for (j = 0; j < m - 1 - i;j++)
if (strcmp(kehu[j].name, kehu[j + 1].name)>0)
{
strcpy(kehu1, kehu[j].name);
strcpy(kehu[j].name, kehu[j + 1].name);
strcpy(kehu[j + 1].name, kehu1);
}
baocun(m);
printf("\n客户编号\t姓名\t性别\t工作\t电话号码\n");
for (j = 0; j < m; j++)
printf("\n%s\t%s\t%s\t%s\t%s\n", kehu[j].num, kehu[j].name, kehu[j].sex, kehu[j].work, kehu[j].phone);
printf("返回排序函数请按1,返回主菜单请按2\n");
scanf("%d", &k);
switch (k)
{
case 1:paixu();
break;
case 2:system("cls");
main();
break;
}
system("cls");
}


 //增加客户信息函数
void add()
{
int n = load();
int i, m;
printf("请输入要增加客户的信息:\n");
scanf("%d", &m);
for (i = n; i < m + n; i++)
{
printf("请输入客户编号:\n");
scanf("%s", kehu[i].num);
printf("\n");
printf("请输入姓名:\n");
scanf("%s", kehu[i].name);
printf("\n");
printf("请输入客户性别:\n");
scanf("%s", kehu[i].sex);
printf("\n");
printf("请增加客户的工作:\n");
scanf("%s", kehu[i].work);
printf("\n");
printf("请输入客户的电话号码:\n");
scanf("%s", kehu[i].phone);
getchar();
printf("\n客户信息添加完毕!");
printf("\n");
}
baocun(m + n);
system("cls");
printf("添加客户档案完成。\n这时的库存信息为:\n");
display();
}
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值