Site icon T4Tutorials.com

C++ Program to display the sum of the series using classes and objects

Write a program in C++ to display the sum of the series using classes and objects.

#include <iostream>
using namespace std;
class T4Tutorials
{
	public:
		long int num,i,k;
		int sum;
		public:
			int function()
			{
				k=9;
				sum=0;
				cout<<"input the number of terms.";
				cin>>num;
				for(i=1;i<=num;i++)
				{
					sum=sum+k;
					k=k*10+9;
				}
				cout<<"the sum of series is"<<sum;
			}
		};
		int main()
		{
			T4Tutorials obj;
			obj.function();
		}

Output

Please input the number of terms. 5

the sum of the series is 111105.

Write a program to find the sum of the following series using classes and objects.
Different series programs in c++ using classes and objects.
All series program in C++ using classes and objects.