-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCPP-10-Sum-of-series.txt
More file actions
54 lines (39 loc) · 1 KB
/
Copy pathCPP-10-Sum-of-series.txt
File metadata and controls
54 lines (39 loc) · 1 KB
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
47
48
49
50
51
52
53
54
/*
Steps
1. Define headers
2. Define class series with private variables and public functions
3. Create constructor to initialize the object values
4. Define calculate() function to calculate the sum of the series
5. Define main() function and get user input
6. Create object using constructor and call calculate() function and display result
*/
#include<iostream>
using namespace std;
class series {
private:
int x,n,nt;
public:
int calculate();
series(int p, int q){
x=p;
n=q;
}
};
int series::calculate(){
int i,sum=1, nt;
nt=x;
for(i=1;i<=n;i++){
sum = sum + nt;
nt= nt*x;
}
return sum;
}
int main(){
int x, n;
cout<<"Enter the base and power values ";
cin>>x>>n;
series obj(x,n);
series cpy = obj;
cout<<"Object 1 : sum of the series = "<<obj.calculate()<<endl;
cout<<"Object 2 : Sum of the series = "<<cpy.calculate();
}