1107447 2021-06-22 14:43 采纳率: 100%
浏览 290
已采纳

c++写一个学生饭卡管理系统,尽量加注释,越简单越好

功能描述:

构建学生、饭卡、食堂三类:

1、学生类:民族学生,非民族学生

2、饭卡类:卡号,姓名,专业,年级,金额

3、食堂类:民族餐厅,非民族餐厅,饭菜,办卡,注销卡,充值

功能需求:

1. 从屏幕输入一组饭卡信息(卡号,姓名,专业,年级,金额)

2.  饭卡信息存入文件

3.  从文件读入饭卡信息

4.  增加一个饭卡信息

5.  删除一条指定饭卡信息

6.  根据输入条件查询饭卡信息

7.  根据条件对饭卡信息排序

8.  修改指定条件的饭卡信息

9.  刷卡买饭

技术需求:

1. 有角色登录界面认证

2.  有主界面,每个数据模块尽量有统计分析

能用这些类最好

Card.h:

    #pragma once

#ifndef card_H

#define card_H

class card

{

protected:

    char cno[12];//饭卡卡号

    char sname[10];//学生姓名

    char sdept[10];//学生专业

    char sgrade[10];//学生年级

    float cmoney;//饭卡余额

public:

    void get_cno();//输入卡号

    void get_sname();//输入姓名

    void get_sdept();//输入专业

    void get_sgrade();//输入年级

    void get_cmoney();//输入余额

    char* out_cno();//输出卡号

    char* out_sname();//输出姓名

    char* out_sdept();//输出专业

    char* out_sgrade();//输出年级

    float out_cmoney();//输出余额

    void mincrease(float);//余额增加

    void mreduce(float);//余额减少

    void cregister();//办卡

    void cdelete();//注销卡

    void cvalue();//充值

    void uselist();//刷卡消费,写入消费记录

    void returnlist();//读出消费记录

 

};

#endif // !card_H

Nationrestautant.h:

#pragma once

#ifndef nationrestaurant_H

#define nationrestaurant_H

class nationrestautant

{

public:

    char* meat;//荤菜

    char* vegetable;//素菜

    int mprice;//荤菜价格

    int vprice;//素菜价格

};

#endif // !restaurant_H

 

Negnationrestautant.h:

#pragma once

#ifndef negnationrestautant_H

#define negnationrestautant_H

class negnationrestautant

{

public:

    char* meat;//荤菜

    char* vegetable;//素菜

    int mprice;//荤菜价格

    int vprice;//素菜价格

};

#endif // !negnationrestautant_H

 

Student.h:

#pragma once

#ifndef student_H

#define student_H

class student

{

public:

    bool nationstu=1;//民族学生为1

    bool negnationstu = 0;//非民族学生为0

    void judge();//学生类别的判断

};

#endif // !student_H

  • 写回答

1条回答 默认 最新

  • CSDN专家-link 2021-06-22 14:47
    关注
    /***********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;
    }
     
     
     

    参考一下吧

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题