C++之客户消费积分管理系统

之前数据结构课程设计要求做这么一个小程序,现在贴上源码,来和大家进行交流学习,希望大家给出意见和建议

程序以链表为主要数据结构对客户信息进行存储,对身份证号码判断了位数及构成(前十七位为数字,最后一位是数字或X)

需求:

针对客户的消费情况,进行客户管理,根据客户的消费积分对客户实行不同程度的打折优惠。

  1. 采用一定的存储结构进行客户信息的存储
  2. 对客户的信息可以进行修改、删除、添加
  3. 能够根据消费情况进行客户积分的累加
  4. 根据积分情况,对客户实行不同程度的打折优惠
 #include<iostream>
#include<iomanip>
#include "stdlib.h"
#include<string>
using namespace std; bool isID(string &);
typedef struct cnode
{
char name[];
string ID;
double consume;
double integer;
struct cnode *next;
}cnode; void Initstack(cnode * &head)/*初始化链表*/
{
head= new cnode(); //开辟节点空间
head->next=NULL;
} void Getelem (cnode *head);
void Search(cnode *head,string &ID);
void Amend(cnode *head,string &ID);
void Delete(cnode *head,string &ID);
void Showall(cnode *head);
void count(cnode *head);
double display_discount(double integer); int main()
{
cnode *head;
int choice;
string y;
Initstack(head);
do
{
cout<<endl;
cout<<" 客户消费 积分管理系统 "<<endl;
cout<<" ******************************"<<endl;
cout<<" * *"<<endl;
cout<<" * 主菜单 *"<<endl;
cout<<" * 1 添加客户 *"<<endl;
cout<<" * 2 查找客户 *"<<endl;
cout<<" * 3 修改客户 *"<<endl;
cout<<" * 4 删除客户 *"<<endl;
cout<<" * 5 显示客户 *"<<endl;
cout<<" * 6 统计客户 *"<<endl;
cout<<" * 7 退出 *"<<endl;
cout<<" * *"<<endl;
cout<<" ******************************"<<endl;
cout<<"请输入您的选择(1,2,3,4,5,6):";
cin>>choice;
if(choice==)
Getelem(head); //添加
else if(choice==)
{
cout<<"请输入您查找客户的身份证号:";
cin>>y;
isID(y);
Search(head,y); //查找
}
else if(choice==)
{
cout<<"请输入您想修改客户的身份证号:";
cin>>y;
isID(y);
Amend(head,y);
} //修改
else if(choice==)
{
cout<<"请输入你想要删除的客户的身份证号:";
cin>>y;
isID(y);
Delete(head,y);
} //删除
else if(choice==)
Showall(head); //显示
else if(choice==)
count(head); //统计
else if(choice==)
exit();
}
while(choice<=);
system("pause");
return ;
}
void Getelem (cnode *head)
{
//添加客户函数以头节点为参数
cnode *p;
double y;
p=new cnode;
p->next=new cnode;/*申请空的节点空间*/
p->ID=" ";
cout<<"请输入姓名:";
cin>>p->name;
cout<<"请输入身份证号(18位):";
cin>>p->ID;
isID(p->ID);
cout<<"请输入消费金额:";
cin>>p->consume;
p->integer=p->consume/;
cout<<"积分:"<<p->integer<<endl;
y=display_discount(p->integer); //调用函数计算折扣
cout<<"折扣:"/*<<setprecision(1)*/<<y<<"折"<<endl;
p->next=head->next;
head->next=p;
}
void Search(cnode *head,string &ID)
{
cnode *p=new cnode;
double y;
p=head;
if(p->next==NULL)
cout<<"没有客户!"<<endl;
else
{
while(p->next!=NULL)
{
p=p->next;
if(ID==p->ID) //判断身份证号是否相同
{
cout<<"姓名:"<<p->name<<endl;
cout<<"身份证号:"<<p->ID<<endl;
cout<<"消费:"<</*setprecision(2)<<*/p->consume<<endl;
cout<<"积分:"<<p->integer<<endl;
y=display_discount(p->integer);
cout<<"折扣"<</*setprecision(1)<<*/y<<"折"<<endl;
return;
}
}
cout<<"不存在该客户!"<<endl;
}
} /*
修改客户函数
通过ID获取信息
可以修改身份证号、姓名、消费金额
修改消费金额有覆盖原有金额及续加两种方式
*/
void Amend(cnode *head,string &ID){
cnode *p;
double y,z;
int choose,x;
p=head;
if(p->next==NULL)
cout<<"没有客户!"<<endl;
else
{
while(p->next!=NULL)
{
p=p->next;
if(ID==p->ID) //判断身份证号是否相同
{
cout<<"姓名:"<<p->name<<endl;
cout<<"身份证号:"<<p->ID<<endl;
cout<<"消费:"/*<<setprecision(2)*/<<p->consume<<endl;
cout<<"积分:"<</*setprecision(1)<<*/p->integer<<endl;
y=display_discount(p->integer);
cout<<"折扣:"<</*setprecision(1)<<*/y<<"折"<<endl;
cout<<"请选择你要修改的1、姓名。2、身份证号。3、消费金额。";
cin>>choose;
if(choose==)
{
cout<<"请输入修改后姓名;";
cin>>p->name;
}
if(choose==)
{
cout<<"请输入修改后的身份证号:";
cin>>p->ID;
isID(p->ID);
}
if(choose==)
{
cout<<"1.覆盖以前消费、2.续加上现在费用!请选择:";
cin>>x;
if(x==)
{
cout<<"请输入修改后的消费:";
cin>>p->consume;
}
else{
printf("请输入续加金额:");
cin>>z;
p->consume+=z;
}
}
cout<<"姓名:"<<p->name<<endl;
cout<<"身份证号:"<<p->ID<<endl;
cout<<"消费:"<</*setprecision(2)<<*/p->consume<<endl;
p->integer=p->consume/100.0;
cout<<"积分:"<<p->integer<<endl;
y=display_discount(p->integer);
cout<<"折扣:"/*<<setprecision(1)*/<<y<<"折"<<endl;
return;
}
}
cout<<"不存在该客户!"<<endl;
}
}
void Delete(cnode *head,string &ID)
{
//删除客户函数
cnode *p;
int x;
double y;
p=head;
if(p->next==NULL)
cout<<"没有客户!"<<endl;
else
{
while(p->next!=NULL)
{
head=p;
p=p->next;
if(ID==p->ID)
{ //判断身份证号是否相同
cout<<"姓名:"<<p->name<<endl;
cout<<"身份证号:"<<p->ID<<endl;
cout<<"消费:"/*<<setprecision(2)*/<<p->consume<<endl;
cout<<"积分:"<<p->integer<<endl;
y=display_discount(p->integer);
cout<<"折扣:"<</*setprecision(1)<<*/y<<"折"<<endl;
cout<<"你确认删除?1、确定。2、取消。请选择:";
cin>>x;
if(x==)
{
head->next=p->next;
cout<<("删除成功!");
}
else
cout<<"删除失败!";
return ;
}
}
cout<<"不存在该客户!"<<endl;
}
}
void Showall(cnode *head) //显示所有客户函数
{
cnode *p;
double y;
p=head;
if(p->next==NULL)
cout<<"没有客户!"<<endl;
else
while(p->next!=NULL)
{
p=p->next;
cout<<"姓名:"<<p->name<<endl;
cout<<"身份证号:"<<p->ID<<endl;
cout<<"消费:"<</*setprecision(2)<<*/p->consume<<endl;
cout<<"积分:"<<p->integer<<endl;
y=display_discount(p->integer);
cout<<"折扣:"<</*setprecision(1)<<*/y<<"折"<<endl;
}
} void count(cnode *head)
{
cnode *p;
int i=;
p=head;
if(p->next==NULL)
cout<<"没有客户!"<<endl;
else
while(p->next!=NULL)
{
p=p->next;
i++;
}
cout<<"现有客户数量为"<<i<<"位!"<<endl;
}
double display_discount(double points)
{
//计算客户折扣函数,接受一个double型的数作为参数,输出对应的折扣
double discount;
if(points == )
discount = ;
if(points > &&points <= )
discount = 9.8;
if(points > &&points <= )
discount = 9.5;
if(points > &&points <= )
discount = 9.2;
if(points > &&points <= )
discount = ;
if(points > &&points <= )
discount = ;
else if(points > )
discount = ;
return discount;
} int cal(string a)
{
return (a[] - '') * + (a[] - '') * + (a[] - '') * + (a[] - '') * + (a[] - '') * +
(a[] - '') * + (a[] - '') * + (a[] - '') * + (a[] - '') * +(a[] - '') * +
(a[] - '') * + (a[] - '') * + (a[] - '') * + (a[] - '') * + (a[] - '') * +
(a[] - '') * +(a[] - '') * ;
} char s(string a)
{
int k = cal(a) % ;
if (k == )
return '';
else if (k == )
return '';
else if (k == )
return 'X';
else
return ''+-k;
} bool isNumber(string str);
bool isID(string &number)
{
do
{
if(==number.length()&&isNumber(number))
if (number[] == s(number))
return true;
else
return false;
else
cout<<"输入格式不正确,请重新输入:"<<endl;
}while (cin >> number); } bool isNumber(string str)
{
for(int i=;i<str.length()-;i++)
if(!isdigit(str[i]))
return false;
if((isdigit(str[str.length()-]))||str[str.length()-]=='X')
return true;
else
return false;
}

作者:耑新新,发布于  博客园

转载请注明出处,欢迎邮件交流:zhuanxinxin@aliyun.com

上一篇:阿里巴巴2014研发project师实习生面试经历


下一篇:ORACLE EBS R12 FOR LINUX 开机后如何启动数据库、应用脚本[Z]