C++ Program to find the sum of the series x – x^3 + x^5 + Class inheritance
Write a program in C++ to find the sum of the series x – x^3 + x^5 + using class.
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 | #include<iostream> #include<math.h> using namespace std; class series { protected: int a,sum,c; int i,n,x,xx,yy; public: void disp() { cout<<"enter the value of a="; cin>>a; cout<<"enter the number of terms"; cin>>n; sum =a; x =-1; cout<<"the valve of sercies\n"; cin>>a; for(i=1; i<n; i++) { c=(2*i+1); xx=pow(a,c); yy=xx*x; cout<<"yy"<<yy<<endl; sum=sum+yy; x=x*(-1); } cout<<"\n sum of series"<<sum; } }; int main() { series obj; obj.disp(); } |
WAP in C++ to find the sum of the series x – x^3 + x^5 + using single inheritance.
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 | #include<iostream> #include<math.h> using namespace std; class series { protected: int a,sum,c; int i,n,x,xx,yy; public: void disp() { cout<<"enter the value of a="; cin>>a; cout<<"enter the number of terms"; cin>>n; sum =a; x =-1; cout<<"the valve of sercies\n"; cin>>a; for(i=1; i<n; i++) { c=(2*i+1); xx=pow(a,c); yy=xx*x; cout<<"yy"<<yy<<endl; sum=sum+yy; x=x*(-1); } cout<<"\n sum of series"<<sum; } }; int main() { series obj; obj.disp(); } |
C++ Program to find the sum of the series x – x^3 + x^5 + using multiple inheritance.
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 46 | #include<iostream> #include<math.h> using namespace std; class numbers { public: int a,sum,c; }; class number2 { public: int i,n,x,xx,yy; }; class series:public numbers,public number2 { public: void disp() { cout<<"enter the value of a="; cin>>a; cout<<"enter the number of terms"; cin>>n; sum =a; x =-1; cout<<"the valve of sercies\n"; cin>>a; for(i=1; i<n; i++) { c=(2*i+1); xx=pow(a,c); yy=xx*x; cout<<"yy"<<yy<<endl; sum=sum+yy; x=x*(-1); } cout<<"\n sum of series"<<sum; } }; int main() { series obj; obj.disp(); } |
C++ Code to find the sum of the series x – x^3 + x^5 + with the help of multi-level inheritance.
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 46 | #include<iostream> #include<math.h> using namespace std; class numbers { public: int a,sum,c; }; class number2:public numbers { public: int i,n,x,xx,yy; }; class series:public number2 { public: void disp() { cout<<"enter the value of a="; cin>>a; cout<<"enter the number of terms"; cin>>n; sum =a; x =-1; cout<<"the valve of sercies\n"; cin>>a; for(i=1; i<n; i++) { c=(2*i+1); xx=pow(a,c); yy=xx*x; cout<<"yy"<<yy<<endl; sum=sum+yy; x=x*(-1); } cout<<"\n sum of series"<<sum; } }; int main() { series obj; obj.disp(); } |