Professional Documents
Culture Documents
: 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 :