项目目标
项目需求说明
系统界面
1)添加客户界面
通过编号来区分客户
2)删除客户界面
对用户输入的编号进行核查,存在与否,合法与否
3)显示客户列表界面
4)修改客户信息的界面
项目设计
Customer结构体的设计
CRM系统结构框架图
案例代码
#include <stdio.h>
#include <string.h>
struct Customer {
int id;
int age;
char name[10];
char gender;
char phone[10];
char email[10];
};
char key ;
char loop;
int customerNum;
//客户结构体数组
struct Customer customers[20];
//得到一个客户的信息
void getInfo(struct Customer *customer) {
/*sprintf(info, "\n%d\t%s\t%c\t%d\t%s\t%s", (*customer).id, (*customer).name,
(*customer).gender, (*customer).age, (*customer).phone,(*customer).email);*/
printf("\n%d\t%s\t%c\t%d\t%s\t%s", (*customer).id, (*customer).name,
(*customer).gender, (*customer).age, (*customer).phone,(*customer).email);
}
//提供各种操作
//1. 添加
void add(){
//编号自动增长
customers[customerNum].id = customerNum + 1;
printf("\n---------------------添加客户---------------------");
printf("\n姓名:");
scanf("%s", customers[customerNum].name);
getchar();
printf("\n性别:");
scanf("%c", &(customers[customerNum].gender));
getchar();
printf("\n年龄:");
scanf("%d", &(customers[customerNum].age));
getchar();
printf("\n电话:");
scanf("%s", customers[customerNum].phone);
getchar();
printf("\n邮箱:");
scanf("%s",customers[customerNum].email);
getchar();
printf("\n---------------------添加完成---------------------");
customerNum++;
}
//根据输入的id去找对应的下标,如果找不到返回-1
int findIndex(int id){
int index = -1;
int i;
for (i = 0; i < customerNum ; i++) {
if (customers[i].id == id) {
index = i;
break;
}
}
return index;
}
//2. 删除客户
int del(int id){
//找到id对应的元素下标
int index = findIndex(id);
int i;
if (index == -1) {
return 0;//说明这个客户不存在..
}else {
//找到,就从index+1开始整体前移
for (i = index + 1; i &l