编程dev c++饭卡管理系统

(1). 建立饭卡信息:添加若干人的饭卡号、姓名、金额,要求饭卡号是唯一的;
(2). 买饭:要求用户输入饭卡号、饭费,系统自动从该人的饭卡中减去饭钱,并分别显示买饭前后的金额,如果原来饭卡中的余额不足5元,则不能买饭,显示“余额不足,请充值”;
(3). 充值:输入饭卡号、充值金额,充值完成后显示充值前后的金额。

可参考

/***********Person.h****************/
#include<iostream>
#include"Main.h"
 
#ifndef PERSON_H
    #define PERSON_H
        
    class Person 
    {
        protected:
            SEX sex;
            IDNUM id;
       public:
        Person(SEX _sex,IDNUM _id);
        Person(){}
    };
#endif
 
 
 
/***********Person.cpp****************/
#include"Person.h"
 
Person::Person(SEX _sex,IDNUM _id)
{
    sex = _sex;
    id = _id;
}
 
 
 
/***********Cstudent.h****************/
#include"CCard.h"
#include"Person.h"
#include"Main.h"
 
#ifndef CSTUDENT_H
    #define CSTUDENT_H        
    
class Cstudent :public CCard, public Person
{
    private:
        STUDENT stu;
        CLASSNUM classNum;
    public:
        Cstudent(STUDENT _stu,CLASSNUM _classNUM,NAME _name,MOMEY _balance,SEX _sex,IDNUM _id);
        Cstudent();
        ~Cstudent(){}
        void showCstudent();
};
 
#endif
 
 
 
/***********Cstudent.cpp****************/
#include"Cstudent.h"
#include"Main.h"
#include"CCard.h"
#include"Person.h"
using namespace std;
 
Cstudent::Cstudent(STUDENT _stu,CLASSNUM _classNum,char* _name,MOMEY _balance,SEX _sex,IDNUM _id):Person( _sex, _id),CCard (_name, _balance)
{
    stu = _stu;
    classNum = _classNum;
}    
 
Cstudent::Cstudent():CCard(),Person()
{}
 
void Cstudent::showCstudent()
{
  cout<<"姓名:"<<name<<endl;
  cout<<"班级号码 :"<<classNum<<endl;
  cout<<"ID号码:"<<id<<endl;
  cout<<"性别: ";if(sex == 0) cout<<"男"<<endl;else if(sex == 1) cout<<"女"<<endl; else cout<<"其他性别"<<endl;
  cout<<"学生类别: ";if(stu == 0) cout<<"本科生"<<endl;else cout<<"研究生"<<endl;
  cout<<"余额"<<balance<<endl<<endl;
}
 
 
 
/***********CCard.h****************/
#include <iostream>
#include "Main.h"
#include<ctime>
 
#ifndef CCARD_H
    #define CCARD_H
    
class CCard 
 {    
    protected:
        CARDNUM cardNum;
        NAME name;
        tm *_time;
        MOMEY balance;        
    public:
        CCard(char * _name,MOMEY _balance);
        CCard(){}
        ~CCard(){}
        void ChargeCard(MOMEY m);
        void ConsumeCard(MOMEY m);
        void InquireCard();
        char* showName();
        tm*get_firstsettime();
};
#endif
 
 
 
/***********CCard.cpp****************/
#include "CCard.h"
#include<iostream>
using namespace std;
CCard::CCard(char * _name,MOMEY _balance)
{
    strcpy(name,_name);
    balance = _balance;
    time_t now;
    time(&now);
    _time = localtime(&now);
}
 
void CCard::ChargeCard(MOMEY m)
{
    balance += m;
    cout<<"充值成功!"<<endl;
    cout<<"当前余额为:"<<balance<<endl;
}
 
void CCard::ConsumeCard(MOMEY m)
{
    if(balance>=m)
    {
        balance -= m;
        cout<<"付款完成!"<<endl;
        cout<<"当前余额为:"<<balance<<endl;
    }
    else
    {
        cout<<"余额不足请充值"<<endl;
    }
}
tm* CCard::get_firstsettime()
{
    return _time;
}
char* CCard::showName()
{
    return name;
}
/*CCard::InquireCard()
{
    //cout<<setw(15)<<"饭卡卡号:"<<card_ID<<endl;
    cout<<setw(15)<<"用户姓名:"<<name<<endl;
    cout<<setw(15)<<"建卡时间:";    
    cout<<get_firstsettime()->tm_year+1900<<"-";
    cout<<get_firstsettime()->tm_mon+1<<"-";
    cout<<get_firstsettime()->tm_mday<<endl;
    cout<<setw(15)<<"用户余额:"<<momery<<endl;
}*/
 
 
 
/***********Main.h****************/
#ifndef MAIN_H
    #define MAIN_H
 
#include<cstring>    
    #define Max 4294967295  //定义最大数
    
    typedef char NAME[20] ; //定义各种变量类型
    typedef int CARDNUM [6];
    typedef int TIME ;
    typedef int MOMEY ;
    typedef int IDNUM;
    typedef int CLASSNUM;
    
    typedef int SEX ;
    typedef int STUDENT ;
    
#endif 
 
 
 
/***********Main.cpp****************/
 
/***************************************
     链表管理例程
     主要实现功能为:
     0、新建链表
     1、插入成员
     2、查找成员
     3、删除成员
     4、数据浏览
***************************************/
//#include "StdAfx.h"
#include <iostream>
#include <cstring>
#include<cstdlib>
#include"Cstudent.h"
using namespace std;
 
/*类声明*/
typedef struct student                //定义student结构体
{
 int num;
 Cstudent stu;
 struct student * next;
}stud;                                                //用stud 代替 student类 类型 同typedef int NUM一样原理
 
/* 函数声明 */
stud * create_list();                                                        //创建链表
int insert_list(stud * head,int n);                                    //插入成员
int del_list(stud * head, char *name);                            //删除成员
stud * find_list(stud * head, char * name);                        //查找成员
void brow_list(stud * head);                                            //显示全部
void showTable();
void chargeCard(stud * head, char * name);                     //饭卡充值
void consumeCard(stud * head, char * name);                 //饭卡消费
/*主函数*/
void main()
{
 stud * head;     //定义stud类型的指针
 int choice;
 char name[8];
 
 head = NULL;        //指针赋空值
 head = create_list();
 showTable();
 do
 {
  system("cls");
  showTable();
  cin>>choice;                     //输入功能选择
  if (choice>5||choice<0) 
  {
   cout<<"输入错误\n";
   continue;
  }
  
  switch (choice) 
  {    
  case 1:
       if (head==NULL)     //功能1: 插入成员
       {
        cout<<"链表未建立\n";
        break;
       }
        insert_list(head,-1);
       break;
   
   case 2:                            //功能2: 删除成员
       cout<<"输入姓名:";
       cin>>name;
       del_list(head,name);
       break;
 
   case 3:                            //功能3: 饭卡充值
       cout<<"输入姓名:";
       cin>>name;
       chargeCard(head,name);
       break;
   
   case 4:                            //功能4: 饭卡消费
       cout<<"输入姓名:";
       cin>>name;
       consumeCard(head,name);
       break;
   
 
   case 5:                            //功能5:查询功能
       cout<<"<1. 按姓名查找 2.按卡号顺序列表>"<<endl;
       char selectCase5;
       cin>>selectCase5;
       if(selectCase5 == '1') {
             cout<<"输入姓名 :"<<endl;
             cin>>name;
             find_list(head,name);
       }
       else if(selectCase5 == '2')
            brow_list(head);
       else 
           cout<<"输入有误"<<endl;
       break;
   
  default:
   return;
  }
  system("pause");
 } while (1);
}
 
/*函数实现*/
stud *create_list()     //新建链表
{
    
 stud * head;
 head=new stud;
 
 if (head!=NULL)
  cout<<"链表已建立\n";
 else
  cout<<"没有足够存储空间\07\n";
 head->next=NULL;
 head->num=0;
 
 return head;
}
 
int insert_list(stud * head,int n) //插入成员
{
 stud *p, *q, *s;
 s=new stud;
 
 if (s==NULL) 
 {
  cout<<"没有足够空间!\07\n";
  return 0;
 }
 
 q=head;
 p=head->next;
 while (p!=NULL&&n!=q->num) 
 {
  q=p;
  p=p->next;
 }
 q->next=s;
 s->next=p;
/**************************************
    Cstudent(STUDENT _stu,CLASSNUM _classNUM,NAME _name,MOMEY _balance,SEX _sex,IDNUM _id)
    ***************************************/
    STUDENT stu_temp;
    CLASSNUM classNum_temp;
    NAME name_temp;
    MOMEY balance_temp;
    SEX sex_temp;
    IDNUM id_temp;
    /**************************************/
    cout<<"输入办卡人姓名:"<<endl;
    cin>>name_temp;
    cout<<"输入办卡人班级号:"<<endl;
    cin>>classNum_temp;
    cout<<"输入充值金额:"<<endl;
    cin>>balance_temp;
    cout<<"输入性别<0.男 1.女>"<<endl;
    cin>>sex_temp;
    cout<<"输入ID号:"<<endl;
    cin>>id_temp;
    cout<<"输入办卡人类别<0.本科生 1.研究生>"<<endl;
    cin>>stu_temp;
    /**************************************/
    Cstudent cstudent_temp(stu_temp,classNum_temp,name_temp,balance_temp,sex_temp,id_temp);
    (s->stu)=cstudent_temp;
    cstudent_temp.~Cstudent();
 s->num=q->num+1;
 return 1;
}
 
stud * find_list(stud * head, char * name) //查找成员
{
 stud * p;
 p=head;
 while(p!=NULL&&strcmp(p->stu.showName(),name))
 {
  p=p->next;
 }
 if (p!=NULL)
 {
   cout<<"学号:"<<p->num<<endl;
   (p->stu).showCstudent();
 }
 else
  cout<<"查无此人!\n";
 return p;
}
 
int del_list(stud * head, char *name)  //删除成员
{
 stud *p, *q;
 q=head;
 p=head->next;
 while (p!=NULL&&strcmp(p->stu.showName(),name))
 {
  q=p;
  p=p->next;
 }
 if (p!=NULL)
 {
  q->next=p->next;
  delete p;
  cout<<"删除完成\n";
  return 1;
 }
 else
 {
  cout<<"查无此人\07\n";
  return 0;
 }
}
 
void brow_list(stud * head)            //显示全部成员
{
 stud *P;
 P=head->next;
 while (P!=NULL)
 {
  cout<<"学号:"<<P->num<<endl;
  (P->stu).showCstudent();
  P=P->next;
 }
}
 
void chargeCard(stud * head, char * name) //饭卡充值
{
 stud * p;
 p=head;
 while(p!=NULL&&strcmp(p->stu.showName(),name))
 {
  p=p->next;
 }
 if (p!=NULL)
 {
   MOMEY momey_temp;
   cout<<"输入充值数额:"<<endl;
   cin>>momey_temp;
   (p->stu).ChargeCard(momey_temp);
 }
 else
  cout<<"查无此人!\n";
}
 
void consumeCard(stud * head, char * name) //饭卡充值
{
 stud * p;
 p=head;
 while(p!=NULL&&strcmp(p->stu.showName(),name))
 {
  p=p->next;
 }
 if (p!=NULL)
 {
   MOMEY momey_temp;
   cout<<"输入消费数额:"<<endl;
   cin>>momey_temp;
   (p->stu).ConsumeCard(momey_temp);
 }
 else
  cout<<"查无此人!\n";
}
 
void showTable()
{
    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<<"**0 --退出系统        **"<<endl;
    cout<<"************************"<<endl;
}