![](https://csdnimg.cn/release/download_crawler_static/6535459/bgb.jpg)
voidsetbox(box*pb);
intmain(void)
{
boxcarton={"BingoBoxer",2,3,5};//novolumeprovided
setbox(&carton);
showbox(carton);
return0;
}
voidshowbox(boxb)
{
usingnamespacestd;
cout<<"Boxmaker:"<<b.maker
<<"\nheight:"<<b.height
<<"\nlwidth:"<<b.width
<<"\nlength:"<<b.length
<<"\nvolume:"<<b.volume<<"\n";
}
voidsetbox(box*pb)
{
pb->volume=pb->height*pb->width*pb->length;
}
//pe7-4.cpp-- probability ofwinning
#include<iostream>
longdoubleprobability(unsignednumbers,unsignedpicks);
intmain()
{
usingnamespacestd;
doubletotal,choices;
doublemtotal;
doubleprobability1,probability2;
cout<<"Entertotalnumberofgamecardchoicesand\n"
"numberofpicksallowedforthefield:\n";
while((cin>>total>>choices)&&choices<=total)
{
cout<<"Entertotalnumberofgamecardchoices"
"forthemeganumber:\n";
if(!(cin>>mtotal))
break;
cout<<"Thechancesofgettingall"<<choices<<"picksisonein
"
<<(probability1=probability(total,choices))<<".\n";
cout<<"Thechancesofgettingthemegaspotisonein"
<<(probability2=probability(mtotal,1))<<".\n";
cout<<"Youhaveonechancein";
cout<<probability1*probability2;//computetheprobability
cout<<"ofwinning.\n";
cout<<"Nextsetofnumbers(qtoquit):";
}
cout<<"bye\n";
return0;
}
//thefollowingfunctioncalculatestheprobabilityofpickingpicks
//numberscorrectlyfromnumberschoices
longdoubleprobability(unsignednumbers,unsignedpicks)
{
longdoubleresult=1.0;//herecomesomelocalvariables
longdoublen;