© 2012 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies
« NS2  Projects »

Home Lab Exercise Object Oriented Programming Lab Exercise ProgramsCPP Program For Accessing Member Function Through Object▼


CPP Program For Accessing Member Function Through Object

Alogarithm steps:

  1. Create the class
  2. Declare the data members and member function
  3. Create the object for class in the main function]
  4. Call the member function using the object
  5. Compile end execute the program

CPP Program For Accessing Member Function Through Object

#include #include class Power { double b; int e; double val; public: Power(double base, int exp); double getPower() { return val; } }; Power::Power(double base, int exp) { b = base; e = exp; val = 1; if(exp == 0) return; for( ; exp > 0; exp--) val = val * b; } int main() { clrscr(): Power x(4.0, 2), y(2.5, 1), z(5.0, 0); cout << x.getPower() << " "; cout << y.getPower() << " "; cout << z.getPower() << endl; getch(); return 0; }

SAMPLE INPUT AND OUTPUT:

 16.000000 6.250000 25.000000

 
SLogix Student Projects

⇓ Student Projects ⇓
⇑ Student Projects ⇑
bottom