[问题描述]

建立一个会员管理程序,
每个会员的登记内容包括会员编号、
会员卡号、累计消费金额,可以分别按会员编号、
会员卡号进行查询,也可以增加或删除会员信息。
[实现提示]
可以采用顺序表或单链表的存储结构,
至少实现题目所要求的三个功能,
要求使用文件存储会员信息。

#include <string>
#include<iostream>
#include<stdlib.h>
#include<fstream>
using namespace std;
struct T   //建立了T,用来存储会员的各项信息
{long id;//会员idstring cardid;//会员卡idstring name;//会员的姓名double moneysum;//会员消费总量
};
struct node//建立了单链表节点的结构
{struct T data;struct node *next;
};
struct node *creatlist()//创建单链表的头节点并返回
{   struct node* headnode=new node;headnode->next=NULL;return headnode;
}
struct node *creatnode(struct T data)//建立新的节点并返回
{struct node *newnode=new node;newnode->next=NULL;newnode->data=data;return newnode;
}void insert(struct node* headnode,struct T data)//通过头插法,调用creatnode函数创建一个新的节点,将数据导入节点并插入指定表中
{struct node*newnode=creatnode(data);newnode->next=headnode->next;headnode->next=newnode;
}
void printlist(struct node* headnode)//通过遍历单链表,输出指定链表中的元素
{struct node* pmove=new node;pmove=headnode->next;if(pmove==NULL) {cout<<"no data"<<endl; return;}while(pmove){cout<<"会员id= "<<pmove->data.id<<" 会员卡号= "<<pmove->data.cardid<<" 总消费额= "<<pmove->data.moneysum<<" 会员姓名= "<<pmove->data.name<<endl;pmove=pmove->next;}
}
void deletes(struct node* headnode,int data)//通过传入的会员id来查找到指定节点并且删除
{struct node* postnode=new node;struct node* front=new node;postnode=headnode->next;front=headnode;if(postnode==NULL) { cout<<"会员信息为空";return ;}else{while(postnode->data.id!=data){front=postnode;postnode=postnode->next;if(postnode==NULL){cout<<"无法找到该会员信息";return ;}}front->next=postnode->next;free(postnode);cout<<"ok!";}
}void drawmap()//绘制程序主界面
{   system("cls");cout<<"*****会员信息管理系统******\n";cout<<"***************************\n";cout<<"1:录入会员信息\n";cout<<"2:显示所有会员信息\n";cout<<"3:删除会员信息\n";cout<<"4:修改会员信息\n";cout<<"5:查找会员信息\n";cout<<"6:保存会员信息\n";cout<<"7:读取会员信息\n";cout<<"8:会员消费录入\n";cout<<"9:会员消费排序\n";cout<<"0:退出系统\n";cout<<"请选择需要的功能?(0`9)\n";
}
struct T getdata()//从键盘获取会员的各项信息并存入结构体T并返回
{struct T enters;while(1){cout<<"请输入会员的id"<<endl;cin>>enters.id;if(enters.id<0) {cout<<"输入错误,请重新输入\n";}else break;}cout<<"请输入会员的会员卡号(cardid) "<<endl;cin>>enters.cardid;while(1){cout<<"请输入会员消费的总金额"<<endl;cin>>enters.moneysum;if(enters.moneysum<0) {cout<<"输入错误,请重新输入:\n";}else break;}cout<<"请输入会员姓名"<<endl;cin>>enters.name;return enters;
}
void adds(struct node* list)//通过调用自定义的insert函数添加会员信息
{insert(list,getdata());cout<<"添加成功";system("pause");
}
void deletess(struct node* list)//通过调用自定义的deletes的函数添加会员信息
{int a;cout<<"请输入要删除的会员的id"<<endl;cin>>a;deletes(list,a);system("pause");
}
void prints(struct node* list)//调用自定义的printlist函数输出所有会员信息
{printlist(list);system("pause");
}
void rewrite(struct node* list)//通过键盘获取会员id来查找并修改会员信息
{long a;cout<<"请输入想要修改的会员的id:"<<endl;cin>>a;struct node* postnode=new node;struct node* front=new node;postnode=list->next;front=list;if(postnode==NULL) { cout<<"没有会员信息";return ;}else{while(postnode->data.id!=a){front=postnode;postnode=postnode->next;if(postnode==NULL){return ;}}postnode->data=getdata();}system("pause");
}
void find(struct node* list)//通过会员id或者会员卡id来寻找该会员的所有信息并输出
{struct node* postnode=new node;struct node* front=new node;postnode=list->next;front=list;if(postnode==NULL) { cout<<"没有会员信息";return ;}else{string b;long a;int m;cout<<"请选择查找方式 1.会员id 2.会员卡id ";cin>>m;while(1){if(m==1){cout<<"输入想要寻找的会员id:"<<endl;cin>>a;while(postnode->data.id!=a){front=postnode;postnode=postnode->next;if(postnode==NULL){cout<<"没有找到该会员信息";system("pause");return ;}}cout<<"会员id= "<<postnode->data.id<<" 会员卡号= "<<postnode->data.cardid<<" 总消费金额= "<<postnode->data.moneysum<<" 会员姓名= "<<postnode->data.name<<endl;system("pause");return ;}if(m==2){cout<<"输入想要寻找的会员卡id:"<<endl;cin>>b;while(postnode->data.cardid!=b){front=postnode;postnode=postnode->next;if(postnode==NULL){cout<<"没有找到该会员信息";system("pause");return ;}}cout<<"会员id= "<<postnode->data.id<<" 会员卡号= "<<postnode->data.cardid<<" 总消费金额= "<<postnode->data.moneysum<<" 会员姓名= "<<postnode->data.name<<endl;system("pause");return ;}else {cout<<"请输入1或者2 \n";}}}
}
void save(struct node* list)//自动生成一个data文件,将系统中的会员信息保存
{struct node* pmove=new node;pmove=list->next;if(pmove==NULL) {cout<<"没有数据"<<endl; return;}ofstream out("data.txt");while(pmove){out<<" "<<pmove->data.id<<" "<<pmove->data.cardid<<" "<<pmove->data.moneysum<<" "<<pmove->data.name;pmove=pmove->next;} out.close();system("pause");
}
void load(struct node* list)//从文件根目录读取data文件中的数据,并且导入系统中
{struct T a;//int cout=1;ifstream in("data.txt");while(!in.eof())  { in.get();if(in.peek()=='\n')break;in>>a.id>>a.cardid>>a.moneysum>>a.name;insert(list,a);}   in.close();
}
void cost(struct node* list)//通过会员id查找会员并对其消费总额进行增加或减少计算
{long a;cout<<"输入会员id:"<<endl;cin>>a;struct node* postnode=new node;struct node* front=new node;postnode=list->next;front=list;if(postnode==NULL) { cout<<"没有会员信息";return ;}else{while(postnode->data.id!=a){front=postnode;postnode=postnode->next;if(postnode==NULL){cout<<"没有该会员信息";system("pause");return ;}}}double add;cout<<"输入本次消费的金额:";cin>>add;postnode->data.moneysum+=add;system("pause");
}
void lists(struct node* list)//对链表中的各个会员信息根据消费金额进行排序
{struct node* postnode=new node;struct node* q=new node;postnode=list->next;if(postnode==NULL) { cout<<"没有会员信息";return ;}else{for(postnode=list->next;postnode;postnode=postnode->next){for(q=postnode->next;q;q=q->next)if(q->data.moneysum>postnode->data.moneysum){T sss=q->data;q->data=postnode->data;postnode->data=sss;}}}cout<<"排序完成"<<endl;system("pause");
}
int main()
{struct node* list=creatlist();//创建链表int choice=0;while(1){drawmap();scanf("%d",&choice);switch (choice){case 1:{adds(list);break;}case 2:{prints(list);break;}case 3:{deletess(list);break;}case 4:{rewrite(list);break;}case 5:{find(list);break;}case 6:{save(list);break;}case 7:{load(list);break;}case 8:{cost(list);break;}case 9:{{lists(list);break;}}case 0:{return 0;break;}}}return 0;
}

【水汐のc++】建立一个会员管理程序, 每个会员的登记内容包括会员编号、 会员卡号、累计消费金额,可以分别按会员编号、 会员卡号进行查询,也可以增加或删除会员信息。相关推荐

  1. java程序设计与j2ee中间件技术/软件开发技术(III)-大作业-采用MVC模式实现商品信息的查询显示(可以模糊查询)、增加和删除功能,商品表自拟,实现简单菜单操作和分页显示

    目录 1.题目说明 2.实验设计 2.1 表设计 2.2 工程结构 3.运行界面截图与说明 4.小结 附录:源代码 src/main/java src/main/java/bean Goods.jav ...

  2. 如何用python创建文件_怎么用python建立一个txt文档,并输入内容-百度经验

    这里,我要用python,在电脑桌面上,新建一个文件夹a,并在文件夹a里面,建立一个txt文档--b.txt,写上如下文字: 你好, 世界. 工具/原料 电脑 python 方法/步骤 1 在电脑桌面 ...

  3. C语言创建学生姓名分数链表,C语言编程 编写程序,建立一个学生数据链表,学生的数据包括学号、姓名、成绩。...

    满意答案 w6611826 2013.04.19 采纳率:50%    等级:11 已帮助:10597人 #include #include #define NULL 0 struct stud { ...

  4. 使用html 语言建立一个简单的网页,如何用记事本建立简单的网页(1).doc

    第九章 网页制作 实验一 用记事本建立简单的HTML文件 [实验目的] 学会用HTML语言建立一个简单的网页. [实验内容] 建立一个网页,布局自定,包括自我介绍.图片.自己的电子信箱地址等,要求在标 ...

  5. 如何快速建立一个网络爬虫(初学者指南)

    作为一个采集新手,我搭建了一个网络爬虫,成功的从Amazon Career 网站中提取了20000条数据.如何建立一个网络爬虫并导出到数据库,最终可以将数据无成本地转变成你的财富? 跟着我我往下看吧. ...

  6. Java实现一个会员制度的CD出租销售店,基本的功能有:一是对会员的管理,包括增加会员、删除会员;二是对货品的管理,包括出租、销售CD、进货、统计账目等。

    Java实现一个会员制度的CD出租销售店,基本的功能有:一是对会员的管理,包括增加会员.删除会员:二是对货品的管理,包括出租.销售CD.进货.统计账目等. 一 MyCD package p1; imp ...

  7. 【水汐のC#】计一个Windows应用程序,在该程序中定义一个学生类和班级类,以处理学生的学号,姓名,语文,数学和英语3门课程的期末考试成绩。实现如下要求的功能:

    设计一个Windows应用程序,在该程序中定义一个学生类和班级类,以处理学生的学号,姓名,语文,数学和英语3门课程的期末考试成绩.实现如下要求的功能: 根据姓名查询该学生的总成绩: 统计全班学生总分的 ...

  8. bat 删除文件_利用电脑文本文档建立一个简单方便的删除文件的小程序

    删除文不需要的文件或者资料,是日常工作中必定会遇到了. 各种的杀毒软件或者防护软件都具备删除文件的功能,例如360.腾讯电脑管家.这些操作起来其实也不是太麻烦! 不过呢!今天来和大家分享一个更简单的方 ...

  9. Python:用字典建立一个通讯录,向字典中添加和删除通讯人信息,查询某个人的信息,然后输出通讯录中所有人的信息。

    用字典建立一个通讯录,向字典中添加和删除通讯人(名字.电话.邮箱.工作单位等),查询某个人的信息,然后输出通讯录中所有人的信息. 采用列表里套字典的方法,比较简单 contacts = []def a ...

最新文章

  1. python不想学了-十分钟也学不会python?就不要学python了
  2. Android中setLayoutParams要用父控件的LayoutParams
  3. [LeetCode] Linked List Cycle II
  4. bread是可数还是不可数_​面包bread是可数名词还是不可数
  5. Firefox 不响应 event.keyCode 问题的解决方案
  6. 使用Python写的第一个网络爬虫程序
  7. 探讨破解3G今日困局之策
  8. 爱立信实习生面试小结
  9. 109 个实用 shell 脚本
  10. 系统提速,Windows Ready Boost,使用闪存设备提高性能
  11. 1.UFS3.1 — Power Mode
  12. 我的世界服务器等级系统,[娱乐][角色][聊天][上古之石]LevelSignPlus——服务器等级声望系统[1.7.2-1.10.2]...
  13. 适合设计电话号码的一款字体
  14. 盛迈坤电商:退款率高会影响店铺吗
  15. threejsV0.143.0版本如何设置uv坐标贴图
  16. 本博客早已废除。请移步新地址
  17. [ Linux ] 格式化硬盘出现/dev/sdb is apparently in use by the system
  18. C 语言隐式类型转换
  19. JAVA_小小圣诞树
  20. 【ceph】ceph osd blacklist cep黑名单|MDS问题分析

热门文章

  1. 元素王座服务器维护,元素王座最新版
  2. Use HAProxy to load balance 300k concurrent tcp socket connections: Port Exhaustion, Keep-alive and
  3. 银行贷款与网上借贷比较
  4. 利用SQL语句创建、修改、删除、查看与使用数据库
  5. 排除万难,从入门到精通区块链
  6. core dump 是什么意思?
  7. 关于logcat的使用
  8. ios怎么打开c语言文件操作函数,C++ ofstream和ifstream详细用法以及C语言的file用法...
  9. 用python进行数据分析举例说明_《利用python进行数据分析》读书笔记 --第一、二章 准备与例子...
  10. python ljust 中文_python ljust 中文_Python为文档批量注音(生僻字歌词为例)