C++实现会员管理程序

本文实例为大家分享了C++实现会员管理程序的具体代码,供大家参考,具体内容如下

设计快捷店会员的简单管理程序。基本要求如下:

(1)定义人民币RMB类,实现人民币的基本运算和显示。
(2)定义会员member类,表示会员的基本信息,包括:编号(按建立会员的顺序自动生成),姓名,密码,电话。提供输入、输出信息等功能。
(3)由RMB类和member类共同派生一个会员卡memberCar类,提供新建会员、充值、消费和查询余额等功能。
(4)main函数定义一个memberCar类数组或链表,保存会员卡,模拟一个快捷店的会员卡管理功能,主要包括:

① 新建会员;
② 已有会员充值;
③ 已有会员消费(凭密码,不能透支);
④ 输出快捷店当前会员数,营业额(收、支情况)。

代码:

#include<iostream>
#include<String.h>
using namespace std;
class RMB{
  int yuan,jiao,fen;
public:
  RMB(int y=0,int j=0,int f=0){
    yuan=y;
    jiao=j;
    fen=f;
  }
  RMB(double x)
  {
     int n = int((x + 0.005) * 100);
     yuan = n / 100;
     jiao = (n - yuan * 100) / 10;
     fen = n % 10;
  }
  operator double()
  {
     return (yuan + jiao * 0.1 + fen * 0.01);
  }
  ~RMB() {}
   friend ostream & operator<<(ostream&output, const RMB&m){
    output << m.yuan << "元" << m.jiao << "角" << m.fen << "分" << endl;
    return output;
   }
  friend istream & operator>>(istream&input, RMB&m){
     cout << "元:";
     input >> m.yuan;
     cout << "角:";
     input >> m.jiao;
     cout << "分:";
     input >> m.fen;
     return input;
  }
};
class member{
public:
  static int number;
  char name[20],code[10], phoneNumber[12];
  static int bianhao() { number++; return number; }
  member(char*a,char*c,char*p){
  strcpy(name,a);
  strcpy(code,c);
  strcpy(phoneNumber,p);
  }
  ~member() {}
   friend istream&operator>>(istream&input, member&A)
  {
     cout << "please input name: " << endl;
     input >> A.name;
     cout << "please input code: " << endl;
     input >> A.code;
     cout << "please input phone number : " << endl;
     input >> A.phoneNumber;
     return input;
  }
  friend ostream&operator<<(ostream&output, member&A)
  {
    output << "the information of member:" << endl;
    output << "number" << '\t' << "name" << '\t' << "phone" << endl;
    output << A.bianhao() << '\t' << A.name << '\t' << A.phoneNumber << endl;
    return output;
  }
};
int member::number=0;
class memberCar:public RMB,public member{
public:
   RMB income, outcome, balance;
   memberCar*next;
   memberCar(char*a, char*c, char*p):member(a,c,p){
    balance = 0;
    income = 0;
    outcome = 0;
   }
  ~memberCar() {}
  friend ostream&operator<<(ostream&output, const memberCar&A)
{
  output << "the information of member:" << endl;
  output << "number" << '\t' << "name" << '\t' << "phone" << '\t' << '\t' << "balance" << endl;
  output << A.bianhao() << '\t' << A.name << '\t' << A.phoneNumber << '\t' << A.balance << endl;
  return output;
}
void recharge()
  {
     cout << "How much do you want to recharge?" << '\n' << "please input the money : " << endl;
     cin >> income;
     balance =balance + income;
     cout << "your balance : " << balance << endl;
  }
void cost()
  {
     char y[10];
     cout << "please input your code : " << endl;
     cin >> y;
     if (strncmp(code, y, 10)==0)
     {
       cout << "please input the money you cost : " << endl;
       cin >> outcome;
       if (outcome > balance)
       {
         cout << "your balance is not enough ! " << endl;
       }
       else
       {
         balance = balance - outcome;
         cout << "your balance : "<< balance;
       }
     }
     else
     {
       cout << "your code is wrong ! " << endl;
     }
  }
  void query(){ cout << "your balance : " << balance; }
};
void AddFront(memberCar*&h, memberCar*&t)
{
  t->next = h;
  h = t;
}
void FindList(memberCar*head, int n = 2)
{
  char s[20];
  cout << "please input your name : " << endl;
  cin >> s;
  while (head)
  {
     if (strncmp(head->name, s, 20) == 0)      {
     switch (n)
       {
       case 2:
         (*head).recharge();
         break;
       case 3:
         (*head).cost();
         break;
       }
     }
     head = head->next;
  }
}
void ShowList(memberCar*head)
{
  int count = 0;
  RMB I=0, O=0;
  while (head)
  {
     count++;
     I=I+head->income;
     O = O + head->outcome;
     head = head->next;
  }
  cout << "the number of member :  " << count << endl;
  cout << "the income of the store : " << I << endl;
  cout << "the outcome of the store : " << O << endl;
  cout << "turn-over of the store :  " << (I - O) << endl;
}

int main()
{
  int choice;
  memberCar*head = NULL, *p;
  do
  {
     cout << "please choice:\n";
     cout << "1 : new member, 2 : recharge, 3 : purchase , 4 :output the number of member and turn-over,other number is over! " << endl;
     cin >> choice;
     switch (choice)
     {
     case 1:
    {
        cout << "input information of new member : " << endl;
        char a[20],c[10],h[12];
        cout << "please input name: " << endl;
        cin>>a;
        cout << "please input code: " << endl;
        cin>>c;
        cout << "please input phone number : " << endl;
        cin>>h;
       p = new memberCar(a, c, h);
       AddFront(head, p);
       cout << *p << endl;
       break;
     }
     case 2:
     {
       FindList(head, 2);
       break;
     }
     case 3:
     {
       FindList(head, 3);
       break;
     }
     case 4:
     {
       ShowList(head);
       break;
     }
     }
  } while (choice);
  return 0;
}

运行结果:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • C++实现景区信息管理系统

    本文实例为大家分享了C++实现景区信息管理系统的具体代码,供大家参考,具体内容如下  1.1 建立主程序应用菜单选项 主程序应用菜单选项包含所实现的所有功能,并且对选项采用数字标识进行选择,对其他错误输入可以进行判别,提示输入错误. 1.2 导游线路图的创建级景区分布图的输出 用邻接链表存储景点分布图的信息,(带权无向)图的邻接链表.输出景区景点分布图(邻接矩阵).图中边的权值∞用32767表示. 1.3  输出导游线路图 景区旅游信息管理系统中制订旅游景点导游线路策略,首先通过遍历景点,给出一

  • C++实现简单的图书管理系统

    今天再为大家介绍另一个常用的管理系统--图书管理系统,希望大家可以亲自动手实践一下,下面就与大家一起分享我的劳动成果. 图书信息包括:登录号.书名.作者名.分类号.出版单位.出版时间.价格等.试设计一图书信息管理系统,使之能提供以下功能: (1)图书信息录入功能(图书信息用文件保存) (2)图书信息浏览功能 (3)查询和排序功能:(至少一种查询方式)         .按书名查询         .按作者名查询 (4)图书信息的删除与修改 分享代码如下 #include<iostream.h>

  • C++基础学生管理系统

    本文实例为大家分享了C++基础学生管理系统的实现代码,供大家参考,具体内容如下 适用于c++6.0,codeblocks等常用工具 1. 链表处理部分 #include<stdio.h> #include<string.h> #include<stdlib.h> #include"linklist.h" #include"elem.h" void dispnode(linklist h) { node *p; p=h->ne

  • C++实现企业职工工资管理系统

    课程设计目的和要求 工资管理要和人事管理相联系,生成企业每个职工的实际发放工资. 企业职工人事基本信息包括:职工编号.姓名.性别.出生日期.职称(助工.工程师.高级工程师)和任职年限. 企业职工工资信息包括:职工编号.姓名.职务工资.职务补贴.住房补贴.应发工资.个人所得税.养老保险.住房公积金和实发工资. 系统主要功能包括: (1)创建职工人事基本信息文件,根据提示输入职工的各项信息,按职工编号对职工信息进行排序,并将排序后的职工信息存储到一个文件中. (2)创建职工的工资信息文件(每个月创建

  • C++实现停车场管理系统

    本文实例为大家分享了停车场管理系统的具体代码,供大家参考,具体内容如下 #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cstdlib> #include<algorithm> #include<queue> #include<vector> #include<stack> #includ

  • C++实现简单的学生管理系统

    C++实现简单的学生管理系统 //Student.cpp #include<iostream> using namespace std; struct Stu { char no[10]; char name[16]; int math; int chi; double ave; }; class Student { public: Stu st; Student * next; public: Student(){} Student(Stu s) { st=s; next=NULL; st.

  • C++学生信息管理系统

    本文实例为大家分享了C++学生信息管理系统源码,供大家参考,具体内容如下 1. tea_list.c #include<stdio.h> #include<stdlib.h> #include<string.h> #include"teacher.h" int sq_tea ; PTEA head = NULL ; FILE *fp ; int tea_llopen(const char* path)//打开文件 { fp=fopen(path,&q

  • C++实现简单的职工管理系统实训代码

    本文实例为大家分享了C++职工管理系统实例代码 1.单个职工的头文件 staff.h #ifndef STAFF_H_INCLUDED #define STAFF_H_INCLUDED //结构体创建 struct staff { char ID[10]; char name[10]; char sex[10]; int pay; int reward; int factpay; }; //自定义结构体 typedef struct staff staff; //单个职工信息创建 staff C

  • C++实现简单的信息管理系统

    本文为大家分享C++实现简单的信息管理系统,小编之前在学习的时候也要做一些管理系统,在网上查了许多资料,现在我把资料分享给大家,希望能够帮助到大家. #include <stdio.h> #include <stdlib.h> #include "file.h" void savaList(Node *head)/**把用户录入的数据存储到文件里面去方便下次读取*/ { FILE *fp=fopen("data\\data.txt" ,&qu

  • C++实现简单的职工信息管理系统

    功能主模块描述 模块一:增加人员函数Add():增加职工基本信息. 模块二:删除人员函数Delete():删除指定的职工的基本信息以及薪酬. 模块三:修改人员函数Modify():修改指定的职工基本信息. 模块四:查询职工信息函数Search():查询指定的职工信息以及薪酬. 模块五:排序职工信息函数Sort():职工信息排序功能实现 模块六:基础数据设置函数Set():设置五类职位的基本薪酬. 模块七:数据存盘,载入函数Save()以及Load():储存职工基本信息,薪酬以及五类职位的基本薪酬

随机推荐