0% found this document useful (0 votes)
17 views

4 Functions Cont

Uploaded by

kimhenry756
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

4 Functions Cont

Uploaded by

kimhenry756
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

INSIDE THE CLASS DEF1NATION:

Another method of defining a member function is to replace the function declaration by the
actual function definition inside the class .
Example:
class item
{
Intnumber;
float cost;
public:
void getdata (int a ,float b);
void putdata(void)
{
cout<<number<<endl; cout<<cost<<endl;
}
};
A C++ PROGRAM WITH CLASS:
# include< iostream. h>
class item
{
int number;
float cost;
public:
void getdata ( int a , float b);
void putdala ( void)
{
cout<<“number:”<<number<<endl;
cout<<”cost :”<<cost<<endl;
}
};
void item :: getdata (int a , float b)
{
number=a;
cost=b;
}
main ( )
{
item x;
cout<<”\nobjectx”<<endl;
x. getdata( 100,299.95);
x .putdata();
item y;
cout<<”\n object y”<<endl;
y. getdata(200,175.5);
y. putdata();
}

Output: object x
number 100
39 P.T.O

You might also like