C++ Program to display the cube of the number upto a given integer using Destructor
Write C++ Program to display the cube of the number upto a given integer using Destructor.
The destructor ~T4Tutorialst()
is a member function of the class T4Tutorialst
. Destructor ~T4Tutorialst()
has the same name as the name of its class T4Tutorialst
. The tild sign ∼ is used before the name of the destructor ~T4Tutorials_Series().
- When the object
T4Tutorialst obj(p,q);
of the classT4Tutorialst
destroyed, then the destructor~T4Tutorialst()
also destroyed automatically. - One class
T4Tutorialst
can have only one destructor~T4Tutorialst()
. However, one class can have many constructors. - Destructor
~T4Tutorialst()
overloading is impossible. - The Destructor
~T4Tutorialst()
can’t have any arguments(parameters). - The destructor
~T4Tutorialst()
has no data type.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include<iostream> #include<conio.h> using namespace std; class T4Tutorialst { private: int i,n; public: T4Tutorialst() { i=1; n=0; } T4Tutorialst(int p, int q) { i=p; n=q; } void display() { cout<<"enter the number :"<<endl; cin>>n; for(i=1; i<=n; i++) { cout<<" The cube of"<<i<<"is ="<<(i*i*i)<<endl; } } ~T4Tutorialst() { cout<<" clear :"<<endl; } }; int main() { int p,q; T4Tutorialst obj(p,q); obj.display(); getch(); } |
Output
Please enter the number:
4
cube of 1 is: 1
cube of 2 is: 8
cube of 3 is: 27
cube of 4 is: 64