发牌程序求高手支招 。。。。。谢谢。
#include <iostream>#include <string>
using namespace std;
class card
{
public:
card(){}
void put(int x[],int y[],int z[],int w[])
{
int i,j=0;
for(i=0;i<13;i++,j++)
{
a[j]=x[i];
a[j+13]=y[i];
a[j+26]=z[i];
a[j+39]=w[i];
}
}
void set(int c[],int n)
{
int temp,flag,i,j;
for(i=0;i<n-1;i++)
{
flag=1;
for(j=1;j<n-i;j++)
if(c[j]<c[j-1])
{
temp=c[j-1];
c[j-1]=c[j];
c[j]=temp;
flag=0;
}
if(flag==1)
break;
}
}
void get(int b[],int n)
{
for(int i=0;i<n;i++)
switch(b[i])
{
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 10:
cout<<b[i]<<' ';break;
case 11:
cout<<'J'<<' ';break;
case 12:
cout<<'Q'<<' ';break;
case 13:
cout<<'K'<<' ';break;
case 14:
cout<<'A'<<' ';break;
}
cout<<'\n';
}
protected:
int a[52];
};
class bridge:public card
{
public:
bridge(){}
bridge(int g){put(m,n,k,h);}
void deal()
{
int i,j=0;
for(i=0;i<13;j+=4,i++)
{
m[i]=a[j];
n[i]=a[j+1];
k[i]=a[j+2];
h[i]=a[j+3];
}
}
void get1()
{
set(m,13);
cout<<"爽哥:";
get(m,13);
set(n,13);
cout<<"胖子:";
get(n,13);
set(k,13);
cout<<"猪头:";
get(k,13);
set(h,13);
cout<<"马子:";
get(h,13);
}
private:
int m[13],n[13],k[13],h[13];
};
class poker:public card
{
public:
poker(){}
poker(int n){
s=new string[n];
b=new int[5*n];
cout<<"输入参加者的名字"<<endl;
for(int i=0;i<n;i++)
cin>>s[i];
}
void deal(int n)
{
int i,j=0;
for(i=1;i<=n;i++)
{
for(;j<i*5;j++)
b[j]=a[2*j/52];
j+=5;
}
}
void get2(int n)
{
int i,j=0;
int* p;
p=new int[n];
for(i=0;i<n;i++)
{
cout<<s[i]<<':';
for(0;j<(i+1)*5;j++)
{
p[i]+=b[j];
cout<<b[j];
}
j+=5;
cout<<' '<<"总点数为:"<<p[i]<<endl;
}
}
private:
int* b;
string* s;
};
void main()
{
int a[13]={2,3,4,5,6,7,8,9,10,11,12,13,14};
int b[13]={14,13,12,11,10,9,8,7,6,5,4,3,2};
int c[13]={8,7,6,5,4,3,2,9,10,11,12,13,14};
int d[13]={8,9,10,11,12,13,14,7,6,5,4,3,2};
card s1;
s1.put(a,b,c,d);
bridge s2;
s2.deal();
char s;
do
{
cout<<"***洗牌***"<<endl;
bridge s3(4);
s3.deal();
cout<<"是否发牌,按y或n"<<endl;
if(getchar()=='y')
s3.get1();
cout<<"继续娱乐请按n"<<endl;
cin>>s;
}while(s=='n');
int n;
do
{
cout<<"输入参加人数"<<endl;
cin>>n;
cout<<"***洗牌***"<<endl;
poker s4(n);
s4.deal(n);
cout<<"是否发牌,按y或n"<<endl;
if(getchar()=='y')
s4.get2(n);
else
break;
cout<<"继续娱乐请按回车"<<endl;
}while(getchar()=='\n');
}
为什么运行没错但是没有结果输出呢?求帮忙按这种发牌的方式把这个程序解决一下,能正常的发牌。谢谢了。