Untitled


SUBMITTED BY: Guest

DATE: Feb. 7, 2014, 1:41 p.m.

FORMAT: Text only

SIZE: 996 Bytes

HITS: 666

  1. #include <iostream>
  2. using namespace std;
  3. class number
  4. {
  5. private:
  6. int value;
  7. public:
  8. number(int x){value=x;}
  9. bool isPrime();
  10. bool isOdd();
  11. long long factorial();
  12. };
  13. bool number::isPrime()
  14. {
  15. int a;
  16. int n=value;
  17. if(n<=1)
  18. return false;
  19. for(a=2;a<n;a++)
  20. if(n%a==0)
  21. return false;
  22. return true;
  23. }
  24. bool number::isOdd()
  25. {
  26. if(value%2==0)
  27. return false;
  28. else
  29. return true;
  30. }
  31. long long number::factorial()
  32. {
  33. int i;
  34. long long factValue=1;
  35. for(i=1;i<=value;i++)
  36. {
  37. factValue=factValue*i;
  38. }
  39. return factValue;
  40. }
  41. int main()
  42. {
  43. int x;
  44. cout<< "Enter an interger(Must be greater than 0): ";
  45. cin>>x;
  46. number a(x);
  47. if(a.isPrime()==true)
  48. cout <<"Prime"<< endl;
  49. else
  50. cout <<"Not Prime"<< endl;
  51. if(a.isOdd()==true)
  52. cout <<"Odd"<< endl;
  53. else
  54. cout <<"Even"<< endl;
  55. cout<< "Factorial: "<<a.factorial()<<endl;
  56. return 0;
  57. }

comments powered by Disqus