STEP 2: Create the class name as a data base with members and member functions.
STEP 3: The function get () is used to read input from the user 2.
STEP 4: Declare friend functions mean (base ob) in the classroom .
STEP 5: On the outside of the class to define the function of your friends and do the following.
STEP 6: Return the average value (ob.val1 ob.val2 +) / 2 as a float.
STEP 7: Stop the program.
PROGRAM :
#include<iostream.h>
#include<conio.h>
class base
{
int val1,val2;
public:
void get()
{
cout<<"Enter two values:";
cin>>val1>>val2;
}
friend float mean(base ob);
};
float mean(base ob)
{
return float(ob.val1+ob.val2)/2;
}
void main()
{
clrscr();
base obj;
obj.get();
cout<<"\n Mean value is : "<<mean(obj);
getch();
}
#include<conio.h>
class base
{
int val1,val2;
public:
void get()
{
cout<<"Enter two values:";
cin>>val1>>val2;
}
friend float mean(base ob);
};
float mean(base ob)
{
return float(ob.val1+ob.val2)/2;
}
void main()
{
clrscr();
base obj;
obj.get();
cout<<"\n Mean value is : "<<mean(obj);
getch();
}
OUTPUTNYA :
Masukkan dua nilai: 10, 20
Rata - rata Nilai adalah: 15
0 comments:
Post a Comment