-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day19_Interfaces.cpp
47 lines (44 loc) · 1.22 KB
/
Day19_Interfaces.cpp
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
// THE PROBLEM
// ***************************
// The AdvancedArithmetic interface and the method declaration
// for the abstract divisorSum(n) method are provided for you in the editor below.
// Complete the implementation of Calculator class, which implements the AdvancedArithmetic interface.
// The implementation for the divisorSum(n) method must return the sum of all divisors of n.
// Solution Created By: Dustin Kaban
// Date: June 14th, 2020
// ***************************
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
class AdvancedArithmetic{
public:
virtual int divisorSum(int n)=0;
};
class Calculator : public AdvancedArithmetic {
public:
int divisorSum(int n)
{
//return the values that the number is evenly divisible by
int sum = 0;
for(int i=1;i<=n;i++)
{
if(n%i == 0)
{
sum+= i;
}
}
return sum;
}
};
int main(){
int n;
cin >> n;
AdvancedArithmetic *myCalculator = new Calculator();
int sum = myCalculator->divisorSum(n);
cout << "I implemented: AdvancedArithmetic\n" << sum;
return 0;
}