Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ Program

Status
Not open for further replies.

SOLIDKSINGH

Programmer
Nov 28, 2002
3
US
Plese send me the code for the following program.....

Write a scheduling program that schedules singles tennis matches among P players
over W weeks. The program must ensure that no one player P1 is assigned to
player P2 if there exists another player P3 who has played P1 fewer times. In
general, no repeat matches should occur while there are other matchups possible
that have occurred fewer times.

Consider the use of 2D arrays to keep track of the number of times each matchup
has occurred. For instance, when players P1 and P3 play, increment a counter in
(row1, column3) and (row3, column1).
The entries in row P denote the number of matchups that have occurred between
player P and each other player. Before assigning a matchup between P1 and Pn,
verify that no other matchup between P1 and Pj occurred fewer times.Use
(rand () %P+1) to select a player. You may also want to use a 1D array of P
elements to keep track if a player has been assigned yet for the current week.

Prompt the user for the number of players (<10) and the number of weeks (<52).
Try 6 players and 32 weeks. For each week, print the week number, and the
pair of players. For instance, print:

Week1: (1,3), (2,4), (5,6)
Week2: (1,2), (3,5), (4,6)
...
...


Also, print the contents of your 2-D array after the printout above.
This will confirm that all matchups occur the same number of times.
 
Is this a school project? If so, I'll try to teach you how to write the program, but not write it for you.
 
ya it is skol problem......but i don't have much time i have hand it tomorrow....but i did got some code....plese see that .if u can improve ................this is for 6 players and 32 week..........but have to make it in general.......
plese see this code.......

thanks....


#include<iostream.h>
#include<cstdlib>
#include<iomanip.h>
int main()
{
int p1,p2,p3,p4,p5,p6,w1,w2,w3,w4,w5,w6;
int a[32][6]={0},p[6][6]={0};
for(int i=0;i<32;i++)
{
p1 = (rand() % 6+1);
while(1)
{
p2= (rand() % 6+1);

if(p1==p2)
continue;
else
break;

}


while(1)
{
p3 = (rand() % 6+1);
if(p1==p3||p2==p3)
continue;
else
break;
}

while(1)
{
p4 = (rand() % 6+1);
if(p1==p4||p2==p4||p3==p4)
continue;
else
break;
}

while(1)
{
p5 = (rand() % 6+1);
if(p1==p5||p2==p5||p3==p5||p4==p5)
continue;
else
break;
}

while(1)
{
p6 = (rand()% 6+1);
if(p1==p6||p2==p6||p3==p6||p4==p6||p5==p6)
continue;
else
break;
}




a[0]=p1;
a[1]=p2;
a[2]=p3;
a[3]=p4;
a[4]=p5;
a[5]=p6;

cout<<&quot;week&quot;<<i+1<<&quot;:&quot;<<&quot;(&quot;<<a[0]<<&quot;,&quot;<<a[1]<<&quot;)&quot;<<setw(5)<<&quot;(&quot;

<<a[2]<<&quot;,&quot;<<a[3]<<&quot;)&quot;<<setw(5)<<&quot;(&quot;<<a[4]<<&quot;,&quot;<<a[5]<<&quot;)&quot;<<endl;


}


for(int q=0;q<32;q++)
{



w1=a[q][0];
w2=a[q][1];
w3=a[q][2];
w4=a[q][3];
w5=a[q][4];
w6=a[q][5];

p[w1-1][w2-1]=p[w1-1][w2-1]+1;
p[w2-1][w1-1]=p[w2-1][w1-1]+1;
p[w3-1][w4-1]=p[w3-1][w4-1]+1;
p[w4-1][w3-1]=p[w4-1][w3-1]+1;
p[w5-1][w6-1]=p[w5-1][w6-1]+1;
p[w6-1][w5-1]=p[w6-1][w5-1]+1;




}

cout<<setw(7)<<&quot;p1&quot;<<setw(5)<<&quot;p2&quot;<<setw(6)<<&quot;p3&quot;<<setw(4)
<<&quot;p4&quot;<<setw(6)<<&quot;p5&quot;<<setw(5)<<&quot;p6&quot;<<endl;

for(int l=0;l<6;l++)
{
cout<<&quot;p&quot;<<l+1<<setw(5);
for(int d=0;d<6;d++)

cout<<p[l][d]<<setw(5);
cout<<endl;
}
return 0;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top