This is what the instructions say: During a recent University disturbance some s
ID: 3619401 • Letter: T
Question
This is what the instructions say:During a recent University disturbance some studentscamebackintothe back of the lecture hall and began throwing bagsofredpaintover the students seated in the class. Thispresentedagreatopportunity for students to analyze the potentialresultsofsuchan act for future references.
The following assumptions are made based on thereportedincident.Thelecture hall consists of 10 rows of 12 seatseach.Onebag ofpaintfalling on a certain seat leaves 2 cups ofpaint overtheperson inthe seat and 1 cup of paint over each personinadjacentseats.
(Situation 1.)
With this information, write a program to calculatetheaveragenumberof cups of paint that would be received by thepeopleineach seat if35 bags of paint were thrown. One simulationdoesnotyield validresults so you will need to simulate thesituation50times. From theruns you can take an average of the 50runsandmake somejudgments.
(Situation 2.)
If you were a student in this class and you knewthatthisdisturbancewas about to happen, but you did not wantanyonetoknow you knew,also you had to come to class toavoidanysuspicion, what seat wouldyou sit in (smallest)? Whatseatwouldyou like your instructor to sitin (largest)?
(Situation 3.)
Suppose you were the instigator of such a dastardlyfeat.Youaretrying to determine how many bags of paint youneedintheclassroom to make it a successful disturbance.Youwouldconsider asuccessful disturbance if 75% of the peoplewerecoveredwith 3cups of paint, because you don't want to drownsomepoorsole, ifany row or column receivesan average of 5 cupsperperson,thenthis simulation run would terminate. Runthesimulationagain(continue with the current random number) 50timesanddeterminethe number of bags needed to accomplish this featandstaywithinthe constraints.
Restrictions: You are to use two-dimensional array(s)toholdseatedstudents.
Youareto use Functions/Procedures in your implementation.
Output: Print out the average paint received for eachseatintableform.
Indicate where you and the instructor would sit.
Print out the number of bags the instigator would bring.
Show the number of times constraints were met for situation 3.
Explanation / Answer
please rate - thanks see the comment, about getting rid of all the intermediateoutput #include <iostream>#include <iomanip>
#define ROWS 10
#define COLS 12
using namespace std;
void throwbags(double[][COLS]);
void print(double[][COLS]);
bool percentage(double[][COLS]);
bool drown(double[][COLS]);
double checkcol(double[][COLS],int);
double checkrow(double[][COLS],int);
int main()
{double seats[ROWS ][COLS]={0};
double bag;
int bags=0,runs,run=50,i,j;
srand(time(0));
bool done;
for(runs=1;runs<=run;runs++)
{done=false;
for(i=0;i<ROWS;i++)
for(j=0;j<COLS;j++)
seats[i][j]=0;
while(!done)
{bags++;
throwbags(seats);
done=percentage(seats)||drown(seats);
}
cout<<" seats after run "<<runs<<" bags usedso far "<<bags<<endl; //you can getrid
print(seats); //of these 2 linesof code
}
bag=(double)bags/run;
cout<<"average bags needed for successful disturbance is"<<bag<<endl;
system("pause");
return 0;
}
bool percentage(double seat[][COLS])
{int i,j,count=0;
for(i=0;i<ROWS;i++)
for(j=0;j<COLS;j++)
if(seat[i][j]>=3)
count++;
if(count>=.75*(ROWS*COLS))
return true;
else
return false;
}
bool drown(double seats[][COLS])
{
int i;
for(i=0;i<ROWS;i++)
if(checkrow(seats,i)>=5)
return true;
for(i=0;i<COLS;i++)
if(checkcol(seats,i)>=5)
return true;
return false;
}
double checkcol(double seat[][COLS],int m)
{int i;
double count=0;
for(i=0;i<ROWS;i++)
count+=seat[i][m];
return count/ROWS;
}
double checkrow(double seat[][COLS],int m)
{int i;
double count=0;
for(i=0;i<COLS;i++)
count+=seat[m][i];
return count/COLS;
}
void print(double seat[][COLS])
{int i,j;
cout<<"row/col ";
for(i=1;i<=COLS;i++)
cout<<setw(2)<<i<<" ";
cout<<endl;
for(i=0;i<ROWS ;i++)
{cout<<setw(2)<<i+1<<" ";
for(j=0;j<COLS;j++)
cout<<setw(6)<<setprecision(2)<<seat[i][j];
cout<<endl;
}
}
void throwbags(double seat[][COLS])
{int row,col;
row=rand()%ROWS ;
col=rand()%COLS;
seat[row][col]+=2;
if(col!=0)
seat[row][col-1]++;
if(col!=COLS-1)
seat[row][col+1]++;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.