program for Laplace criteria

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

//program for Laplace criteria


#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class laplace
{
private :
int A[100][100],i,j,m,n,sum,r,r1;
float prob,t[100],s[100],small,large;
public :
void getdata(void);
void disp(void);
};
void laplace :: getdata(void)
{
cout<<“\n\n\t Enter the size of Matrix… “;
cout<<“\n\n\t Number of row’s : “;
cin>>m;
cout<<“\n\n\t Number of col’s : “;
cin>>n;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cout<<“\n\n\t Enter the value for row “<<i+1<<” : “;
cin>>A[i][j];
}
}
}

void laplace :: disp(void)
{
prob = float(1)/n;
sum = 0;
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
sum = sum + A[i][j];
}
s[i] = sum;
t[i] = s[i] * prob;
sum = 0;
}
small = t[0];
large = t[0];
for(i=0;i<m;i++)
{
if(small<=t[i])
small = small;
else
small = t[i];
if(large>=t[i])
large = large;
else
large = t[i];
}

for(i=0;i<m;i++)
{
if(t[i] == small)
r = i+1;
}

for(i=0;i<m;i++)
{
if(t[i] == large)
r1 = i+1;
}

cout<<“\n\n\t Your entered matrix is :\t\tProb.\tSum\tSum*Prob”;
cout<<“\n\n\t\t”;
for(i=0;i<m;i++)
{
cout<<” A”<<i+1<<” –>”;
for(j=0;j<n;j++)
{
cout<<” “<<setw(4)<<A[i][j];
}
cout<<setprecision(2)<<” “<<prob;
cout<<setprecision(2)<<” “<<setw(3)<<s[i];
cout<<” “<<setw(3)<<t[i];
cout<<“\n\n\t\t”;
}
cout<<“\n\n\t Maximum is “<<large;
cout<<“\n\n\t So, for profit the answer is : A”<<r1<<” Alternatives.”;
cout<<“\n\n\n\n\t And Minimum is “<<small;
cout<<“\n\n\t So, for cost the answer is : A”<<r<<” Alternatives.”;

}

void main()
{
clrscr();
laplace l;
l.getdata();
clrscr();
l.disp();
getch();
}


output :

Enter the size of Matrix…

Number of row’s : 3
Number of col’s : 3

Enter the value for row 1 : 8000
Enter the value for row 1 : 3500
Enter the value for row 1 : 5000

Enter the value for row 2 : 4500
Enter the value for row 2 : 4500
Enter the value for row 2 : 5000

Enter the value for row 3 : 2000
Enter the value for row 3 : 5000
Enter the value for row 3 : 4000

Your entered matrix is :
Prob. Sum Sum*Prob

A1 –> 8000 3500 5000 0.33 1.65e+04 5.5e+03

A2 –> 4500 4500 5000 0.33 1.4e+04 4.67e+03

A3 –> 2000 5000 4000 0.33 1.1e+04 3.67e+03

Maximum is 5.5e+03

So, for profit the answer is : A1 Alternatives.

And Minimum is 3.67e+03

So, for cost the answer is : A3 Alternatives.

Leave a Reply

Your email address will not be published. Required fields are marked *