हिंदी

Give a Suitable Example in C++ to Illustrate with Its Definition Within a Class and a Declaration of an Object with the Help of It. - Computer Science (C++)

Advertisements
Advertisements

प्रश्न

Give a suitable example in C++ to illustrate with its definition within a class and a declaration of an object with the help of it.

उत्तर

#include<isotream.h>
#include<conio.h>
Class copy
{ 
   int, val, fact;
Public:copy(int temp)
{ 
   val = + temp;
}

Double calculate()
{ 
   fact = 1;
   For(int i = 1; i < val; i++)
   { 
      fact = fact * i;
   }
   return fact;
}
};

void main ()
{ 
  clrscr();
  int n;
  cout << "Enter Number";
  cin >> n;
  copy obj(n);
  copy cpy = obj;
  cout << n << "factorial is : " << obj.calculate();
  cout <<n<< "factorial is :" << cpy.calculate();
  getch();
}
}
shaalaa.com
Class and Object in C++
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
2014-2015 (March) All India Set 4
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×