C语言实现建立一个简单的会员卡储值积分管理系统该系统的主要功能是:会员卡管理功能和会员卡储值积分管理,会员卡管理功能: (1) 根据身份证办理会员卡,一张身份证只能办理一张会员卡。 (2)根据需要可以注销、挂失、冻结会员卡或修改会员卡密码以及积分和消费金额查询。会员卡基本信息包括:会员名、身份证号、卡号、密码、积分、消费金额、级别。会员卡储值积分管理: (1)根据会员卡级别设置折扣率,根据折扣率自动打折计算消费金额 (2)根据消费金额计算积分,积分累计达到一定标准后换购商品设计要求: 按照题目1的设计要求必须含有主菜单、主控程序模块设计、并体现程序的交互性(必须输入/输出提示)、模块化程序思想。
时间: 2023-06-24 21:06:43 浏览: 60
以下是一个简单的C语言程序,实现了会员卡储值积分管理系统的基本功能:
```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_MEMBERS 100
// 会员卡信息结构体
typedef struct {
char name[20]; // 会员名
char id[20]; // 身份证号
char card_no[20]; // 卡号
char password[20]; // 密码
int level; // 级别
int points; // 积分
double balance; // 储值余额
} MemberCard;
MemberCard members[MAX_MEMBERS]; // 会员卡数组
int num_members = 0; // 已有会员卡数量
// 根据身份证号查找会员卡,返回会员卡在数组中的下标,未找到返回-1
int find_member_by_id(const char* id) {
for (int i = 0; i < num_members; i++) {
if (strcmp(members[i].id, id) == 0) {
return i;
}
}
return -1;
}
// 办理会员卡
void register_member_card() {
if (num_members >= MAX_MEMBERS) {
printf("系统已满,无法办理新会员卡!\n");
return;
}
// 输入会员卡信息
MemberCard new_member;
printf("请输入会员名:");
scanf("%s", new_member.name);
printf("请输入身份证号:");
scanf("%s", new_member.id);
if (find_member_by_id(new_member.id) >= 0) {
printf("该身份证号已经办理了会员卡!\n");
return;
}
printf("请输入密码:");
scanf("%s", new_member.password);
printf("请输入级别(1-5):");
scanf("%d", &new_member.level);
// 自动生成卡号
sprintf(new_member.card_no, "C%04d", num_members + 1);
// 新会员卡初始积分和余额为0
new_member.points = 0;
new_member.balance = 0;
// 添加到会员卡数组
members[num_members++] = new_member;
printf("办理成功!卡号为:%s\n", new_member.card_no);
}
// 修改密码
void change_password() {
char id[20], password[20];
printf("请输入身份证号:");
scanf("%s", id);
int index = find_member_by_id(id);
if (index < 0) {
printf("未找到该会员卡!\n");
return;
}
printf("请输入原密码:");
scanf("%s", password);
if (strcmp(members[index].password, password) != 0) {
printf("密码错误!\n");
return;
}
printf("请输入新密码:");
scanf("%s", password);
strcpy(members[index].password, password);
printf("修改成功!\n");
}
// 储值
void add_balance() {
char id[20];
double amount;
printf("请输入身份证号:");
scanf("%s", id);
int index = find_member_by_id(id);
if (index < 0) {
printf("未找到该会员卡!\n");
return;
}
printf("请输入储值金额:");
scanf("%lf", &amount);
members[index].balance += amount;
printf("储值成功!余额为:%.2f\n", members[index].balance);
}
// 消费
void consume() {
char id[20], password[20];
double amount, discount;
printf("请输入身份证号:");
scanf("%s", id);
int index = find_member_by_id(id);
if (index < 0) {
printf("未找到该会员卡!\n");
return;
}
printf("请输入密码:");
scanf("%s", password);
if (strcmp(members[index].password, password) != 0) {
printf("密码错误!\n");
return;
}
printf("请输入消费金额:");
scanf("%lf", &amount);
printf("请输入折扣率:");
scanf("%lf", &discount);
members[index].balance -= amount * discount;
members[index].points += (int)(amount / 10);
printf("消费成功!余额为:%.2f,积分为:%d\n", members[index].balance, members[index].points);
}
// 查询会员卡信息
void query_member_card() {
char id[20];
printf("请输入身份证号:");
scanf("%s", id);
int index = find_member_by_id(id);
if (index < 0) {
printf("未找到该会员卡!\n");
return;
}
printf("会员名:%s\n", members[index].name);
printf("身份证号:%s\n", members[index].id);
printf("卡号:%s\n", members[index].card_no);
printf("级别:%d\n", members[index].level);
printf("积分:%d\n", members[index].points);
printf("余额:%.2f\n", members[index].balance);
}
// 主菜单
void main_menu() {
printf("欢迎使用会员卡储值积分管理系统!\n");
printf("1. 办理会员卡\n");
printf("2. 修改密码\n");
printf("3. 储值\n");
printf("4. 消费\n");
printf("5. 查询会员卡信息\n");
printf("6. 退出系统\n");
}
int main() {
int choice;
while (1) {
main_menu();
printf("请选择:");
scanf("%d", &choice);
switch (choice) {
case 1:
register_member_card();
break;
case 2:
change_password();
break;
case 3:
add_balance();
break;
case 4:
consume();
break;
case 5:
query_member_card();
break;
case 6:
printf("谢谢使用!\n");
exit(0);
default:
printf("无效选项!\n");
break;
}
printf("\n");
}
return 0;
}
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)