// Lab 13
// Note modifiers like const and static can be used 
// ONLY for functions that are memebrs of a class.
/*
Write a class call it myInt with one private data memebr of type int 
(call it integer) and 5 public methods with no parameters to determine 
if the number is a multiple of 7, 11, or 13; 
if the number is prime;
if the sum of the digits of the number is even or odd;
if the number is a perfect number;
and to find the square root of the number.
*/
#include <iostream>
#include <cmath>
using namespace std;
class myInt
{
	int integer;
public:
	myInt(int m);
	bool isMultiple() const;
	bool isSumDigitsEven() const;
	float root() const;
	bool isPrime() const;
	bool isPerfect() const;
};
int main()
{
	int n;
	cout << "Enter a positive integer greater than 1: ";
	cin >> n;
	if (n > 1)
	{
		myInt a(n);
		cout << "For the integer " << n << ": " << endl;
		if (a.isMultiple())
			cout << "It's a multiple of 7 or 11 or 13.\n";
		else
			cout << "It is not a multiple of 7 or 11 or 13.\n";
		if (a.isSumDigitsEven())
			cout << "The sum of the digits is even.\n";
		else
			cout << "The sum of the digits is odd.\n";
		cout << "The square root is: " << a.root() << endl;
		if (a.isPrime())
			cout << "It's prime.\n";
		else
			cout << "It is not prime.\n";
		if (a.isPerfect())
			cout << "It's a perfect square.\n";
		else
			cout << "It is not a perfect square.\n";
	}
	else
		cout << "The number must be a positive integer "
			<< "greater than 1." << endl;
	return 0;
}

myInt::myInt(int m)
{
	integer = m;
}
bool myInt::isMultiple() const
{
	if (integer % 7 == 0
		|| integer % 11 == 0
		|| integer % 13 == 0)
		return true;
	else
		return false;
}
bool myInt::isSumDigitsEven() const
{
	int n = integer, sum = 0, rem;
	while (n > 0)
	{
		rem = n % 10;
		sum += rem;
		n = n / 10;
	}
	if (sum % 2 == 0)
		return true;
	else
		return false;
}
float myInt::root() const
{
	return sqrt(integer);
}
bool myInt::isPrime() const
{
	if (integer == 2)
		return true;
	int i;
	for (i = 2; i < integer; i++)
		if (integer % i == 0)
			return false;
	return true;
}
bool myInt::isPerfect() const
{
	int i, sum = 0;
	for (i = 1; i < integer; i++)
		if (integer % i == 0)
			sum += i;
	if (sum == integer)
		return true;
	else
		return false;
}
