//3 store five nos in an array and display max and min ammong them using scop resulution operator.
#include<iostream.h>
#include<conio.h>
class test
{
private:
int a[5];
public:
void input();
void display();
int max();
int min();
};
void test ::input()
{
for(int i=0;i<=5;i++)
{cout<<"enter a ["<<i<<"]:";
cin>>a[i];
}}
void test ::display()
{
for(int i=0;i<=5;i++)
cout<<"a["<<i<<"]:"<<a[i]<<endl;
}
int test ::max()
{
int m;
m=a[0];
for(int i=0;i<=5;i++)
{if(m<a[i])
m=a[i];}
return m;
}
int test ::min()
{
int m;
m=a[0];
for(int i=0;i<=5;i++)
{if(m>a[i])
m=a[i];}
return m;
}
void main()
{
test t;
t.input();
cout<<"you entered:\n";
t.display();
int x=t.max();
cout<<"\n\nmaximum number is\n\n"<<x;
int y=t.min();
cout<<"\n\nminimum number is\n\n"<<y;
getch();
}
#include<iostream.h>
#include<conio.h>
class test
{
private:
int a[5];
public:
void input();
void display();
int max();
int min();
};
void test ::input()
{
for(int i=0;i<=5;i++)
{cout<<"enter a ["<<i<<"]:";
cin>>a[i];
}}
void test ::display()
{
for(int i=0;i<=5;i++)
cout<<"a["<<i<<"]:"<<a[i]<<endl;
}
int test ::max()
{
int m;
m=a[0];
for(int i=0;i<=5;i++)
{if(m<a[i])
m=a[i];}
return m;
}
int test ::min()
{
int m;
m=a[0];
for(int i=0;i<=5;i++)
{if(m>a[i])
m=a[i];}
return m;
}
void main()
{
test t;
t.input();
cout<<"you entered:\n";
t.display();
int x=t.max();
cout<<"\n\nmaximum number is\n\n"<<x;
int y=t.min();
cout<<"\n\nminimum number is\n\n"<<y;
getch();
}
0 comments:
Post a Comment