Sunday, October 27, 2013

Vegetable Market Problem: Priority Queue implementation in C++

#include <iostream>
#include <string>
using namespace std;

class veg
{

public:
int a[20][20],b[20];
void display(int [20][20],int);
};

void veg::display(int a[20][20],int c)
{
for(int i=0;i<c;i++)
{
cout<<(i+1)<<")"<<"\t";
for(int j=0;j<4;j++)
{
cout<<a[i][j]<<"\t";
}
cout<<"\n";
}
}
class queue
{
int data;
int top;
int start;
int end;
public:
queue();
int size(int);
int* qpush(int *,int *,int);
void qdisplay(int *,int);
};
queue::queue()
{
data=0;
top=-1;
start=-1;
end=-1;
}
int queue::size(int a)
{
return a;
}
int* queue::qpush(int *a,int *b,int y)
{
for(int i=0;i<4;i++)
{
end++;
b[end]=a[i];
}
return b;
}
void queue::qdisplay(int *n,int y)
{
int temp1=start+1;
while(temp1!=y)
{
cout<<n[temp1]<<"\t";
temp1++;
}
}


int main()
{
veg v1;
string s[4]={"Apple","Mangoes","Banana","Grapes"};
int c,i,j,temp=0,temp1;

cout<<"\n Enter no of customers:";
cin>>c;
for(int i=0;i<c;i++)
{
cout<<"\n Customer no:"<<(i+1)<<" Enter quantity for Apples,Mangoes,Banana,Grapes:";
for(int j=0;j<4;j++)
{
cin>>v1.a[i][j];
}
}
cout<<"Customer Apples\tMangoes\tBanana\tGrapes\n";
v1.display(v1.a,c);
cout<<"\nTotal\t";
for(int j=0;j<4;j++)
{
for(int i=0;i<c;i++)
{
temp=v1.a[i][j]+temp;
}
v1.b[j]=temp;
cout<<v1.b[j]<<"\t";
temp=0;
}
cout<<"\n";
string temps[1];
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(v1.b[j]<v1.b[i])
{
temp1=v1.b[i];
v1.b[i]=v1.b[j];
v1.b[j]=temp1;
temps[0]=s[i];
s[i]=s[j];
s[j]=temps[0];

}
}
}
cout<<"\n";
queue q1;
int arr[4];
int* ch=q1.qpush(v1.b,arr,4);
cout<<"Items\t\t";
for(int i=0;i<4;i++)
{
cout<<s[i]<<"\t";
}
cout<<"\n\n";
cout<<"Quantity\t";
q1.qdisplay(ch,4);
return 0;
}

No comments:

Post a Comment

Perform a suitable assignment using Xen Hypervisor or equivalent open source to configure it. Give necessary GUI.

 To install kvm on Fedora:  yum install kvm  yum install virt-manager libvirt libvirt-python python-virtinst  su -c "yum install @v...