C++簡単な食事カード管理システム


            
/***********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<<"    
"; continue; } switch (choice) { case 1: if (head==NULL) // 1: { cout<<"
"; 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<<"
"; else cout<<" \07
"; 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
"; 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<<" !
"; 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<<"
"; return 1; } else { cout<<" \07
"; 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<<" !
"; } 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<<" !
"; } 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; }