Sunday, 29 April 2012

Array Implementation of Stacks in C++ ( PUSH and POP )

#include<iostream.h>
#include<conio.h>
#define MAX 80

int y;
int a = 0;
int b = 0;
long c = 0;
int d,m,p;

class machine
{
private:
char s[10],x[10],h[10];

public:
void get()
{
cout<< "Enter machine Type : ";
cin>>h;
cout<< endl;
cout<< "Enter CPU Type : ";
cin>>x;
cout<< endl;
cout<< "Enter The Type Of OS : ";
cin>>s;
cout<< endl;
cout<< "Enter The Memory In MB : ";
cin>>m;
cout<< endl;
cout<< "Enter The Disk Space In GB : ";
cin>>d;
cout<< endl;
cout<< "Enter Yhe Price : ";
cin>>p;
cout<< endl;
}

int cmp(int i)
{
if(m>a)
{
a = m;
b = d; 
c = p;
y = i;
}
if((m==a)&&(d<b))
{
a = m;
b = d;
c = p;
y = i;
}
if((m==a)&&(d==b)&&(p< c))
{
a = m;
b = d;
c = p;
y = i;
}
return y;
}

void disp()
{
cout<< "The Details Of The Best machine Are : ";
cout<< endl;
cout<< "Disk Space :"<< d;
cout<< endl;
cout<< "Memory Space :"<< m;
cout<< endl;
cout<<"Price: "<< p;
cout<< endl;
cout<< "OS : "<< s;
cout<< endl;
cout<< "CPU : "<< x;
cout<< endl;
cout<< "Machine : "<< h;
cout<< endl;
}

};
void main()
{
clrscr();
machine d[MAX];
int r;
cout<< "Enter The Range : ";
cin>>r;
cout<< endl;

for(int i=0;i< r;i++)
{
d[i].get();
}
for(int j=0;j< r;j++)
{
d[j].cmp(j);
}
d[y].disp();
getch();
}

No comments:

Post a Comment