This program takes digits of a number and calculate summation and multiplication of its digits .How can I make this code more OOP ?
//Calculate Sum and multiplication of digits of a number .
#include "stdafx.h"
#include <iostream>
#include <vector>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
int main()
{
int number , sum = 0 , multp = 0 ;
vector<int> digits;
cout << "Calculate Sum and multiplication of digits of a number ." << "\n" << "\n";
cout << "------------------------------------" << "\n";
cout << "Enter a whole number : ";
cin >> number;
if (number > 0) //Condition for inputed number
{
while (number)
{
digits.push_back(number % 10);
number /= 10;
}
for (int i = 0; i < digits.size(); i++) // summation
{
sum += digits[i];
}
cout << "sum of digits = " << sum << "\n";
for (int j = 0; j < digits.size(); j++) //multiplication
{
multp *= digits[j];
}
cout << "Multiplication of digits = " << multp << "\n";
}
else
{
cout << "Pleas enter a positive number ." << "\n";
}
cout << "\n" << "\n" << "------------------------------------" << "\n";
system("pause");
return 0;
}
Thanks in advance.
Number
class that contains a vector ofDigits
. The Number object should know how to read a line the Digit object should know how to parse their own value. The number object should know how to display itself and perform the sum of its members and the product of its members. \$\endgroup\$