Advertisement
naser2345

Made By Nasr

Jan 21st, 2021
1,112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.52 KB | None | 0 0
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4. void printMainMenu(){
  5.   cout << "\n+--------------+[[ Main Menu ]]+--------------+\n";
  6.   cout << "a.Sin (x), Series.\n"
  7.   << "b.Count Perfects, Count Digits and Prime Number.\n"
  8.   << "c.Binary and Decimal.\n"
  9.   << "d.Exit.\n"
  10.   << "Your Choice: ";
  11. }
  12.  
  13. void printAMenu(){
  14.   cout << "\n+--------------+[[ A Menu ]]+--------------+\n";
  15.   cout << "1- Sin (x) = x - x^3/3! + x^5/5! - x^7/7! ... x^n/n!\n"
  16.   << "2- F = 1^2/3! + 3^6/7! ... n^2n/(2n+1)!\n"
  17.   << "3- Return to the Main Menu\n"
  18.   << "Enter Your Choice: ";
  19. }
  20.  
  21. void printBMenu(){
  22.   cout << "\n+--------------+[[ B Menu ]]+--------------+\n";
  23.   cout << "1- Sum Perfects.\n"
  24.   << "2- Count Of Primes.\n"
  25.   << "3- Return to the Main Menu\n"
  26.   << "Enter Your Choice: ";
  27. }
  28.  
  29. void printCMenu(){
  30.   cout << "\n+--------------+[[ C Menu ]]+--------------+\n";
  31.   cout << "1- Binary To Decimal.\n"
  32.   << "2- Decimal To Binary.\n"
  33.   << "3- Return to the Main Menu\n"
  34.   << "Enter Your Choice: ";
  35. }
  36.  
  37. float A_Menu_Choice_One(int x, int n){
  38.   float result = 0;
  39.   int factorial = 1;
  40.   for(int i = 1; i <= n; i += 2){
  41.     for(int j = 1; j <= i; j++) factorial *= j;
  42.     result += (pow(x, i * 1.0) / factorial * 1.0) * pow(-1.0, i+1);
  43.   }
  44.   return result;
  45. }
  46.  
  47. float A_Menu_Choice_Two(int n){
  48.   float result = 0;
  49.   int factorial = 1;
  50.   for(int i = 1; i <= n; i += 2){
  51.     for(int j = 1; j <= i*2 + 1; j++) factorial *= j;
  52.     result += pow(i, 2 * i * 1.0) / factorial * 1.0;
  53.   }
  54.   return result;
  55. }
  56.  
  57. int B_Menu_Choice_One(){
  58.   int total = 0, sum;
  59.   for(int i = 1; i <= 1000; i++){
  60.     sum = 0;
  61.     for(int j = 1; j < i; j++){
  62.       if(i % j == 0){
  63.         sum += j;
  64.       }
  65.     }
  66.     if(sum == i){
  67.       total += i;
  68.     }
  69.   }
  70.   return total;
  71. }
  72.  
  73. int B_Menu_Choice_Two(){
  74.   int count = 0, flag;
  75.   for(int i = 2; i <= 100; i++){
  76.     flag = 1;
  77.     for(int j = 2; j <= i/2; j++){
  78.       if(i % j == 0){
  79.         flag = 0;
  80.       }
  81.     }
  82.     if(flag){
  83.       count++;
  84.     }
  85.   }
  86.   return count;
  87. }
  88.  
  89. long long int C_Menu_Choice_One(long long int n){
  90.   long long int decimalNum = 0, rem, tmp = 1;
  91.   while(n > 0){
  92.     rem = n % 10;
  93.     decimalNum += rem * tmp;
  94.     tmp *= 2;
  95.     n /= 10;
  96.   }
  97.   return decimalNum;
  98. }
  99.  
  100. int C_Menu_Choice_Two(int n){
  101.   int binaryNum = 0, powerOfTen = 1;
  102.  
  103.   do
  104.   {
  105.   binaryNum=binaryNum+(n%2)*powerOfTen;
  106.   powerOfTen *= 10;
  107.   n=n/2;
  108.   }
  109.   while(n>0);
  110.   return binaryNum;
  111. }
  112.  
  113. int main() {
  114.     char choice;
  115.     while(2021)
  116.     {
  117.       printMainMenu();
  118.       cin >> choice;
  119.       if(choice == 'd' || choice == 'D') break;
  120.       else if(choice == 'a' || choice == 'A'){
  121.         int x, n, Achoice;
  122.         printAMenu();
  123.         cin >> Achoice;
  124.         if(Achoice == 3) continue;
  125.         else if(Achoice == 1){
  126.           cout << "Enter x then n: ";
  127.           cin >> x >> n;
  128.           cout << " [!] - The Result of Sin(x) is: " << A_Menu_Choice_One(x, n) << endl;
  129.         }
  130.         else if(Achoice == 2){
  131.           cout << "Enter n: ";
  132.           cin >> n;
  133.           cout << " [!] - The Result Of The Seris Is: " << A_Menu_Choice_Two(n) << endl;
  134.         }else{
  135.           cout << "\nInvalid Input\n";
  136.         }
  137.       }
  138.       else if(choice == 'b' || choice == 'B'){
  139.         int Bchoice;
  140.         printBMenu();
  141.         cin >> Bchoice;
  142.         if(Bchoice == 3) continue;
  143.         else if(Bchoice == 1){
  144.           cout << " [!] - The Sum of Perfects Numbers From 1 to 1000 Is: " << B_Menu_Choice_One() << endl;
  145.         }
  146.         else if(Bchoice == 2){
  147.           cout << " [!] - The Count of Prime Numbers From 1 to 100 Is: " << B_Menu_Choice_Two() << endl;
  148.         }
  149.         else{
  150.           cout << "\nInvalid Input\n";
  151.         }
  152.       }
  153.       else if(choice == 'c' || choice == 'C'){
  154.         int Cchoice;
  155.         printCMenu();
  156.         cin >> Cchoice;
  157.         if(Cchoice == 3) continue;
  158.         else if(Cchoice == 1){
  159.           long long int n;
  160.           cout << "Enter A Binary Number: ";
  161.           cin >> n;
  162.           cout << " [!] - The Decimal Number Of That Binary Number is: " << C_Menu_Choice_One(n) << endl;
  163.         }
  164.         else if(Cchoice == 2){
  165.           int n;
  166.           cout << "Enter A Decimal Number: ";
  167.           cin >> n;
  168.           cout << " [!] - The Binary Number Of That Decimal Number is: " << C_Menu_Choice_Two(n) << endl;
  169.         }
  170.         else{
  171.           cout << "\nInvalid Input\n";
  172.         }
  173.       }
  174.       else{
  175.         cout << "\nInvalid Input\n";
  176.       }
  177.     }
  178.     cout << "\n[+] - The End Of The Program!\n";
  179.   return 0;
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement