Q) Write a C++ [cpp] program to find the largest and smallest among 3 numbers using the concepts of class, object, scope resolution operator & functions.
ANSWER_____________________________________________//find largest & smallest among 3 no:
#include<conio.h>
#include<iostream.h>
class domain
{
public:
int a[3],large,small;
void get();
void check();
void disp()
{
cout<<"\n largest= "<<large<<endl<<" smallest= "<<small<<endl<<"\nBYE!";
}
};
void domain::get()
{
int i;
cout<<"Enter 3 numbers:"<<endl;
for(i=0;i<3;i++)
cin>>a[i];
cout<<"OK\n";
};
void domain::check()
{
int i;
large=a[0];
small=a[0];
for(i=0;i<3;i++)
{
if(a[i]>large) large=a[i];
if(a[i]<small) small=a[i];
}
};
void main()
{
clrscr();
domain obj;
obj.get();
obj.check();
obj.disp();
getch();
}
__________________________________________________
Having trouble in executing the program? Suggestions? helps / need help? Share it..!
Comments
Post a Comment