Welfare Lottery and Sports Lottery

来源:互联网 发布:js 修改不了样式 编辑:程序博客网 时间:2024/05/01 15:58

# include<iostream>
# include<ctime>
# include<cstdlib>
# include<string>
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<nRnd;j++)
        {
            nNum=rand()%10;
            cout<<nNum<<'/b';
        }
        cout<<nNum;
        LotNum[i]=nNum;
    }
}
void CSportLot::PrintLot()
{
    for(int i=0;i<7;i++)
        cout<<LotNum[i]<<'/t';
    cout<<endl;
}
void  CWelfareLot::SetLot()
{
    int nRnd,nNum;
    for(int i=0;i<6;i++)
    { nRnd=rand();
    for(int j=0;j<nRnd;j++)
    { nNum=rand()%21;
    
if(nNum<10)
        cout<<nNum<<'/b';
    else
        cout<<nNum<<'/b'<<'/b';
    }
cout<<nNum<<" ";
LotNum[i]=nNum;
    }
}

void  CWelfareLot::PrintLot()
{
    for(int i=0;i<6;i++)
        cout<<LotNum[i]<<'/t';
    cout<<endl;
}
void  SportLottery()
{
    cout<<"/n/t/t体育彩票,机会多多!/n/n";
    cout<<"/t请输入7位(0~9)数字:/n";
    int usersport[7];
    for(int i=0;i<7;i++)
    {
        cout<<"第"<<i+1<<"位数字:";
        cin>>usersport[i];
        if(usersport[i]>=10||usersport[i]<0)
        {
            cout<<"输入的数字应在0~9之间,请重新输入!/n";
            i--;
        }
    }
    CCustomer  customer;
    CSportLot  sport;
    customer.SetSport(usersport);
    cout<<"/t现在开始开奖,按任意键开始/n";
    cin.get();
    cout<<"/n/t/t激动人心的一刻,体育彩票开奖!/n/n";
    sport.SetLot();
    cout<<endl;
    cout<<"/t大奖号码为:/n";
    sport.PrintLot();
    int nRank;
    nRank=customer.Compare(sport);
    if(nRank==7)
        cout<<"/t很遗憾,这次你没有中奖年,请以后继续努力!/n/n/n";
    else
        cout<<"/t恭喜你,你中的奖是"<<nRank<<"等奖,该请客了!/n/n/n";
}
void WelfareLottery()
{
    cout<<"/n/t/t福利彩票,惊喜无限!/n/n";
    cout<<"/t请输入6位(0~20)数字:/n";
    int  userwelfare[6];
    for(int i=0;i<6;i++)
    {
        cout<<"第"<<i+1<<"位数字:";
        cin>>userwelfare[i];
        if(userwelfare[i]>20||userwelfare[i]<0)
        {
            cout<<"输入的数字应在0~20之间,请重新输入!/n";
            i--;
        }
    }
    CCustomer  customer;
    CWelfareLot welfare;
    customer.SetWelfare(userwelfare);
    cout<<"/t现在开始开奖,按任意键开始/n";
    cin.get();
    cout<<"/n/t/t激动人心的一刻,福利彩票开奖!/n/n";
    welfare.SetLot();
    cout<<endl;
    cout<<"/t大奖号码为:/n";
    welfare.PrintLot();
    int nRank;
    nRank=customer.Compare(welfare);
    if(nRank==6)
        cout<<"/t小钢炮,哈哈!你也来摸奖,去!去!完美去!/n/n/n";
         //    cout<<"/t很遗憾,这次你没有中奖年,请以后继续努力!/n/n/n";

    else
        cout<<"/t恭喜你,你中的奖是"<<nRank<<"等奖,该请客了!/n/n/n";
}
int  main(void)
{

string strChoice;
do
{
    cout<<"/t/tJi  Baby : 欢迎进入彩票游戏,祝你好运!/n/n/n";
    cout<<"/t/t1.体育彩票/n";
    cout<<"/t/t2.福利彩票/n";
    cout<<"/t/t3.退出/n";
    cout<<"/n/n/t/t请选择下注福彩还是体彩:";
    cin>>strChoice;
    if(strChoice=="1")
        SportLottery();
    else if(strChoice=="2")
        WelfareLottery();
    else if(strChoice=="3")
        cout<<"/t/t输入错误,请重新选择:/n";
}
while(strChoice!="3");
cout<<"/n/n/t/t谢谢使用,下次再见!/n";
return 0;
}
        

有好几十处错误,要删,要把主函数里的时间函数去掉。
感悟:写出代码不是最重要的,后期的维护与扩展更加。。。一个东西的问世就是要有人用,要有需求,无人用的东西是没有用的!市场随时是变化的!需要你有超前的观点!
 

原创粉丝点击