You are on page 1of 3

Roll No.

: 101
Practical 17 : Program to implement Maximax criterion.
#include<iostream.h>
#include<conio.h>
class Optimism
{
private :
int r,c;
long int ns[20][20],maxs[20], payoff;
public :
void showdata();
private :
void getdata();
void calculate();
void showmat();
};
void Optimism :: getdata()
{
cout<<"\nEnter the no. of states of nature : ";
cin>>r;
cout<<"\nEnter the no. of alternatives : ";
cin>>c;
cout<<"\nEnter "<<r*c<<" values :";
for (int i=1;i<=r;i++)
{
for (int j=1;j<=c;j++)
{
cin>>ns[i][j];
}
}
}
void Optimism :: showmat()
{
getdata();
cout<<"\nThe Payoff Matrix : \n";
for (int i=1;i<=r;i++)
{
for (int j=1;j<=c;j++)
{
cout<<ns[i][j]<<"\t";
}
cout<<"\n";

}
}
void Optimism :: calculate()
{
showmat();
int i,j;
long int max;
for (i=1;i<=c;i++)
{
max = ns[1][i];
for (j=1;j<=r;j++)
{
if (max < ns[j][i])
{
max = ns[j][i];
}
maxs[i] = max;
}
}
max = maxs[1];
for (i=1;i<=c;i++)
{
if (max < maxs[i])
{
max = maxs[i];
}
}
payoff = max;
}
void Optimism :: showdata()
{
calculate();
cout<<"\nPayoff = "<<payoff;
}
void main()
{
clrscr();
Optimism O;
O.showdata();
getch();
}
Output :

Enter the no. of states of nature : 3


Enter the no. of alternatives : 3
Enter 9 values :700000 500000 300000 300000 450000 300000 150000 0 300000
The Payoff Matrix :
700000 500000 300000
300000 450000 300000
150000 0
300000
Payoff = 700000

You might also like