//Inline function square, computes the square of x.
#include<iostream.h>#include<conio.h>class{
{
cout<<
cin>>x;
}
}; abcint x;public:void get()"Enter the value of x ";inline void square();void
{
s=x*x;
cout<<
} abc::square()int s=0;"The square of "<<x<<" is = "<<s;void
{
abc A;
clrscr();
A.get();
A.square();
getch();
} main()************************//OUTPUT//************************Enter the value of x 5
The square of 5 is = 25
PROGRAM:-2
//Program for Bubble sort using Function.
#include<iostream.h>#include<conio.h>
class sort
{
int i,j,n,no[100],temp;
public:
void get();
void sortdata();
void put();
};
void sort::get()
{
cout<<"enter how many numbers: ";
cin>>n;
cout<<"enter "<<n<<" numbers:\n";
for(i=0;i<n;i++)
{
cin>>no[i];
}
}
void sort::sortdata()
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(no[i]<no[j])
{
temp=no[i];
no[i]=no[j];
no[j]=temp;
}
}
}
}
void sort::put()
{ cout<<"\n--------------------OUTPUT-----------------------\n\n";
cout<<"Sorted no's :- "<<endl;
for(i=0;i<n;i++)
{
cout<<no[i]<<endl;
}
}
void main()
{
clrscr();
sort s;
s.get();
s.sortdata();
s.put();
getch();
}
*******************//OUTPUT//***********************
enter how many numbers:
5
enter 5 numbers:
999
1000
555
111
689
--------------------OUTPUT-----------------------
Sorted no's :-
111
555
689
999
1000
Please write your name at the end of program
ReplyDelete