#include #include #include #include using namespace std; class CSportLot; //声明体彩类 class CWelfareLot; //声明福彩类 class CCustomer //定义用户类 { private: int *pSport; //体彩投注号码 int *pWelfare; //福彩投注号码 public: CCustomer(){pSport=pWelfare=NULL;} void SetSport(int *p){pSport=p;} void Setwelfare(int *p){pWelfare=p;} int Compare(CSportLot &); //比较体彩,返回中奖等级 int Compare(CWelfareLot &); //比较福彩,返回中奖等级 }; class CSportLot //定义体彩 { private: int LotNum[7]; //定义中奖号码 public: CSportLot(){} void SetLot(); //开奖过程 void PrintLot(); //输出大奖号码 friend int CCustomer::Compare(CSportLot &); //用户类,比较是否中奖 }; class CWelfareLot //定义福彩,具体运作与体彩类似 { private: int LotNum[6]; public: CWelfareLot(){} void SetLot(); void PrintLot(); friend int CCustomer::Compare(CWelfareLot &); }; int CCustomer::Compare(CSportLot &sportlot) //比较是否中奖,返回中奖等级 { int t=0; for(int i=0;i<7;i++) if(sportlot.LotNum[i]==pSport[i]) t++; return 7-t; } int CCustomer::Compare(CWelfareLot &welfarelot) { int t=0; for(int i=0;i<6;i++) if(welfarelot.LotNum[i]==pWelfare[i]) t++; return 6-t; } void CSportLot::SetLot(void) //开奖 { int nRnd,nNum; for(int i=0;i<7;i++) { nRnd=rand(); for(int j=0;j