C语言 项目 CRM系统(客户信息管理系统)
生活随笔
收集整理的這篇文章主要介紹了
C语言 项目 CRM系统(客户信息管理系统)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
項目目標(biāo)
項目需求說明
系統(tǒng)界面
1)添加客戶界面
通過編號來區(qū)分客戶
2)刪除客戶界面
對用戶輸入的編號進(jìn)行核查,存在與否,合法與否
3)顯示客戶列表界面
4)修改客戶信息的界面
項目設(shè)計
Customer結(jié)構(gòu)體的設(shè)計
CRM系統(tǒng)結(jié)構(gòu)框架圖
案例代碼
#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;//客戶結(jié)構(gòu)體數(shù)組 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++;}//根據(jù)輸入的id去找對應(yīng)的下標(biāo),如果找不到返回-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對應(yīng)的元素下標(biāo)int index = findIndex(id);int i;if (index == -1) {return 0;//說明這個客戶不存在..}else {//找到,就從index+1開始整體前移for (i = index + 1; i < customerNum; i++) {customers[i - 1] = customers[i];}--customerNum;return 1;} }//顯示部分//1. 顯示所有 void showList(){int i = 0;printf("\n---------------------------客戶列表---------------------------");printf("\n編號\t姓名\t性別\t年齡\t電話\t郵箱");for (i = 0; i < customerNum; i++) {getInfo(&customers[i]);} }//2. 完成刪除 界面 //---------------------刪除客戶--------------------- //請選擇待刪除客戶編號(-1退出):1 //確認(rèn)是否刪除(Y/N):y //---------------------刪除完成---------------------void delView(){int id;char choice = ' ';printf("\n---------------------刪除客戶---------------------");printf("\n請選擇待刪除客戶編號(-1退出):");scanf("%d", &id);getchar();if (id == -1) {printf("\n---------------------刪除沒有完成---------------------");return;}printf("確認(rèn)是否刪除(Y/N):");scanf("%c", &choice);getchar();if (choice == 'Y') {if(del(id)){printf("\n---------------------刪除完成---------------------");}else{printf("\n---------------------刪除沒有完成,無此id---------------------");}} }//3. 主菜單 void mainMenu() {do {printf("\n-----------------客戶信息管理軟件-----------------");printf("\n 1 添 加 客 戶");printf("\n 2 修 改 客 戶");printf("\n 3 刪 除 客 戶");printf("\n 4 客 戶 列 表");printf("\n 5 退 出");printf("\n請選擇(1-5):");scanf("%c", &key);getchar();switch (key) {case '1':add();break;case '2':break;case '3':delView();break;case '4':showList();break;case '5':loop = 0;break;default:printf("\n輸入錯誤,請重新輸入");break;}} while (loop);printf("\n你已經(jīng)成功的退出了系統(tǒng)....");getchar(); }void main() {為了測試方便customers[0].id = 1;customers[0].age = 10;strcpy(customers[0].email , "xx@sohu.com");customers[0].gender = 'f';strcpy(customers[0].name , "zs");strcpy(customers[0].phone , "110");mainMenu();return ; }自己完成的代碼
#include<stdio.h> #include<string.h> #include<stdlib.h> //項目-CRM系統(tǒng)(客戶信息管理系統(tǒng))-DQ版本1 const int size=100;//結(jié)構(gòu)體數(shù)組大小 //客戶結(jié)構(gòu)體 struct Customer{int id;//編號char name[10];//姓名char sex[2];//性別int age;//年齡char phone[20];//電話char email[30];//郵箱 }cs[size]; //全局變量 //記住:結(jié)構(gòu)體數(shù)組的下標(biāo)從0開始,而客戶編號從1開始 int loop=1;//判斷菜單是否循環(huán) char num='0';//用戶選擇的功能數(shù)字 int d=0;//用戶選擇要刪除的客戶編號 char c='c';//用戶選擇確認(rèn)是否要刪除的操作 int count=0;//現(xiàn)在存有的客戶數(shù)量 char m='c';//用戶選擇是否要退出系統(tǒng)的操作 //添加客戶 void add() {printf("-----------添加客戶-----------\n");//使用結(jié)構(gòu)體數(shù)組去存儲信息cs[count]printf("姓名:");scanf("%s",cs[count].name);getchar();printf("性別:");scanf("%s",cs[count].sex);getchar();printf("年齡:");scanf("%d",&cs[count].age);getchar();printf("電話:");scanf("%s",cs[count].phone);getchar();printf("郵箱:");scanf("%s",cs[count].email);getchar();cs[count].id=count+1;//客戶編號從1開始count++;printf("-----------添加完成-----------\n"); } //返回對應(yīng)編號所對應(yīng)的數(shù)組下標(biāo) int findindex(int id) {int i;for(i=0;i<count;i++){if(id==cs[i].id){return i;//已找到id,對應(yīng)的下標(biāo)為i}}return -1;//沒有找到id } //顯示要修改的客戶界面 void showUpdate(int index) { printf("姓名(%s):",cs[index].name);scanf("%s",cs[index].name);getchar();printf("性別(%s):",cs[index].sex);scanf("%s",cs[index].sex);getchar();printf("年齡(%d):",cs[index].age);scanf("%d",&cs[index].age);getchar();printf("電話(%s):",cs[index].phone);scanf("%s",cs[index].phone);getchar();printf("郵箱(%s):",cs[index].email);scanf("%s",cs[index].email);getchar();} //修改客戶 void update() {int id=0;printf("-----------修改客戶-----------\n");printf("請輸入要修改的客戶的編號:");scanf("%d",&id);getchar();int index=findindex(id);if(index!=-1)//找到下標(biāo){showUpdate(index);printf("-----------修改完成-----------\n");}else{printf("沒有此編號的客戶!\n");}} //在刪除之后重新排列結(jié)構(gòu)體數(shù)組 void rearr(int d) {int i;if(d<count){for(i=d;i<count;i++){cs[i]=cs[i+1];//如:把cs[1]的內(nèi)容復(fù)制給cs[0]//修改編號cs[i].id-=1;//移動過來的數(shù)組的編號-1}}count--;//客戶數(shù)量-1 } //刪除客戶 void del(struct Customer*cs) {printf("-----------刪除客戶-----------\n");printf("請選擇要刪除的客戶編號:");scanf("%d",&d);getchar();//enterif(d>count){printf("該編號的客戶不存在!\n");}else{printf("確認(rèn)是否刪除(y/n):");scanf("%c",&c);if(c=='y'){rearr(d-1);//重新排列結(jié)構(gòu)體}else if(c=='n'){printf("取消刪除!\n");}else{printf("輸入內(nèi)容錯誤!\n");}getchar();}printf("-----------刪除完成-----------\n"); } //客戶列表 void show(struct Customer*cs) {printf("-----------客戶列表-----------\n");printf("編號\t姓名\t性別\t年齡\t電話\t郵箱\n");int i;for(i=0;i<count;i++){printf("%d\t%s\t%s\t%d\t%s\t%s\n",(*cs).id,(*cs).name,(*cs).sex,(*cs).age,(*cs).phone,(*cs).email);cs++;}printf("----------客戶列表完成--------\n"); } //顯示查找的客戶信息 void showSeek(int index) {printf("編號\t姓名\t性別\t年齡\t電話\t郵箱\n"); printf("%d\t%s\t%s\t%d\t%s\t%s\n",cs[index].id,cs[index].name,cs[index].sex,cs[index].age,cs[index].phone,cs[index].email); } //查找客戶 void seek() {int id=0;printf("-----------查找客戶-----------\n");printf("請輸入要查找的客戶的編號:");scanf("%d",&id);getchar();int index=findindex(id);if(index!=-1)//找到下標(biāo){showSeek(index);printf("-----------查找完成-----------\n");}else{printf("沒有此編號的客戶!\n");} } //退出 void esc() {//do-while另外一種寫法/*do{printf("請確認(rèn)是否要退出(y/n):");scanf("%c",&m);getchar();}while(m!='y'&&m!='n');//輸入的內(nèi)容既不是y也不是n*/do{printf("請確認(rèn)是否要退出(y/n):");scanf("%c",&m);getchar();if(m=='y'||m=='n'){break;//退出此do-while循環(huán)}else{printf("輸入的內(nèi)容錯誤!\n");}}while(1);if(m=='y'){loop=0;//退出系統(tǒng)} } //顯示菜單 void menu(struct Customer*cs) {do{printf("-------客戶信息管理軟件-------\n");printf("---------1.添加客戶-----------\n---------2.修改客戶-----------\n---------3.刪除客戶-----------\n---------4.客戶列表-----------\n---------5.查找客戶-----------\n---------6.退出---------------\n");printf(" 請選擇(1-6):");scanf("%c",&num);getchar();//enterswitch(num){case '1'://添加客戶add();break;case '2'://修改客戶update();break;case '3'://刪除客戶del(cs);break;case '4'://客戶列表show(cs);break;case '5'://查找客戶seek();break;case '6'://退出esc();break;default://用戶輸入其他內(nèi)容時printf("輸入的內(nèi)容錯誤!");break;}}while(loop);printf("已退出CRM系統(tǒng)!\n"); }int main() {//初始化局部變量memset(cs,0,sizeof(cs));//cs是數(shù)組,直接傳遞首地址即可menu(cs);getchar();return 0; }完成代碼遇到的知識點(diǎn)
C語言在void函數(shù)中使用return
如:
return表示中止當(dāng)前函數(shù)的運(yùn)行,并將操作權(quán)返回給調(diào)用者。
如果是在main函數(shù)中,表示將操作權(quán)返回給操作系統(tǒng),return不是必須要返回一個值。
總結(jié)
以上是生活随笔為你收集整理的C语言 项目 CRM系统(客户信息管理系统)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: windows查看网络常用cmd命令
- 下一篇: vue实现中英文切换