This code helps us to understand how to define a member function outside the class definition in C++.
A User-defined datatype which can be declared and used in the program to create objects is called as a Class.
#include using namespace std; class unit { int number; float cost; public: void getdata(int a, float b); void putdata(void) { cout<<"number:"<<number<<endl; cout<<"cost:"<<cost<<endl; } }; void unit::getdata(int a, float b) { number=a; cost=b; } int main() { unit p; cout<<"\nobject p"<<endl; p.getdata(100,299.95); p.putdata(); unit r; cout<<"\nobject p"<<endl; r.getdata(200,1759.95); r.putdata(); return 0; }
Submitted by Pratyasha Sahu (pratyashasahu)
Download packets of source code on Coders Packet
Comments