C++ Program to find the sum of the series using constructor destructor
Write a program in C++ to find the sum of the series using constructor destructor.
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 41 42 43 44 45 | #include<iostream> using namespace std; class T4Tutorials { public : T4Tutorials(); ~T4Tutorials(); void read(); }; T4Tutorials::T4Tutorials() { cout<<endl; } void T4Tutorials::read() { { cout<<"enter the value"; int n; cin>>n; int s=0; int t=1,i=1; for(i=1;i<=n;i++ ) { cout<<" "<<t<<" "; if (i<n) { cout<<"+"; } s=s+t; t=(t*10)+1; } cout<<endl<<"The sum is :"<<s; } } T4Tutorials::~T4Tutorials() { cout<<endl<<"detail is clear"; } int main() { T4Tutorials u; u.read(); } |