Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <math.h>
- using namespace std;
- void printMainMenu(){
- cout << "\n+--------------+[[ Main Menu ]]+--------------+\n";
- cout << "a.Sin (x), Series.\n"
- << "b.Count Perfects, Count Digits and Prime Number.\n"
- << "c.Binary and Decimal.\n"
- << "d.Exit.\n"
- << "Your Choice: ";
- }
- void printAMenu(){
- cout << "\n+--------------+[[ A Menu ]]+--------------+\n";
- cout << "1- Sin (x) = x - x^3/3! + x^5/5! - x^7/7! ... x^n/n!\n"
- << "2- F = 1^2/3! + 3^6/7! ... n^2n/(2n+1)!\n"
- << "3- Return to the Main Menu\n"
- << "Enter Your Choice: ";
- }
- void printBMenu(){
- cout << "\n+--------------+[[ B Menu ]]+--------------+\n";
- cout << "1- Sum Perfects.\n"
- << "2- Count Of Primes.\n"
- << "3- Return to the Main Menu\n"
- << "Enter Your Choice: ";
- }
- void printCMenu(){
- cout << "\n+--------------+[[ C Menu ]]+--------------+\n";
- cout << "1- Binary To Decimal.\n"
- << "2- Decimal To Binary.\n"
- << "3- Return to the Main Menu\n"
- << "Enter Your Choice: ";
- }
- float A_Menu_Choice_One(int x, int n){
- float result = 0;
- int factorial = 1;
- for(int i = 1; i <= n; i += 2){
- for(int j = 1; j <= i; j++) factorial *= j;
- result += (pow(x, i * 1.0) / factorial * 1.0) * pow(-1.0, i+1);
- }
- return result;
- }
- float A_Menu_Choice_Two(int n){
- float result = 0;
- int factorial = 1;
- for(int i = 1; i <= n; i += 2){
- for(int j = 1; j <= i*2 + 1; j++) factorial *= j;
- result += pow(i, 2 * i * 1.0) / factorial * 1.0;
- }
- return result;
- }
- int B_Menu_Choice_One(){
- int total = 0, sum;
- for(int i = 1; i <= 1000; i++){
- sum = 0;
- for(int j = 1; j < i; j++){
- if(i % j == 0){
- sum += j;
- }
- }
- if(sum == i){
- total += i;
- }
- }
- return total;
- }
- int B_Menu_Choice_Two(){
- int count = 0, flag;
- for(int i = 2; i <= 100; i++){
- flag = 1;
- for(int j = 2; j <= i/2; j++){
- if(i % j == 0){
- flag = 0;
- }
- }
- if(flag){
- count++;
- }
- }
- return count;
- }
- long long int C_Menu_Choice_One(long long int n){
- long long int decimalNum = 0, rem, tmp = 1;
- while(n > 0){
- rem = n % 10;
- decimalNum += rem * tmp;
- tmp *= 2;
- n /= 10;
- }
- return decimalNum;
- }
- int C_Menu_Choice_Two(int n){
- int binaryNum = 0, powerOfTen = 1;
- do
- {
- binaryNum=binaryNum+(n%2)*powerOfTen;
- powerOfTen *= 10;
- n=n/2;
- }
- while(n>0);
- return binaryNum;
- }
- int main() {
- char choice;
- while(2021)
- {
- printMainMenu();
- cin >> choice;
- if(choice == 'd' || choice == 'D') break;
- else if(choice == 'a' || choice == 'A'){
- int x, n, Achoice;
- printAMenu();
- cin >> Achoice;
- if(Achoice == 3) continue;
- else if(Achoice == 1){
- cout << "Enter x then n: ";
- cin >> x >> n;
- cout << " [!] - The Result of Sin(x) is: " << A_Menu_Choice_One(x, n) << endl;
- }
- else if(Achoice == 2){
- cout << "Enter n: ";
- cin >> n;
- cout << " [!] - The Result Of The Seris Is: " << A_Menu_Choice_Two(n) << endl;
- }else{
- cout << "\nInvalid Input\n";
- }
- }
- else if(choice == 'b' || choice == 'B'){
- int Bchoice;
- printBMenu();
- cin >> Bchoice;
- if(Bchoice == 3) continue;
- else if(Bchoice == 1){
- cout << " [!] - The Sum of Perfects Numbers From 1 to 1000 Is: " << B_Menu_Choice_One() << endl;
- }
- else if(Bchoice == 2){
- cout << " [!] - The Count of Prime Numbers From 1 to 100 Is: " << B_Menu_Choice_Two() << endl;
- }
- else{
- cout << "\nInvalid Input\n";
- }
- }
- else if(choice == 'c' || choice == 'C'){
- int Cchoice;
- printCMenu();
- cin >> Cchoice;
- if(Cchoice == 3) continue;
- else if(Cchoice == 1){
- long long int n;
- cout << "Enter A Binary Number: ";
- cin >> n;
- cout << " [!] - The Decimal Number Of That Binary Number is: " << C_Menu_Choice_One(n) << endl;
- }
- else if(Cchoice == 2){
- int n;
- cout << "Enter A Decimal Number: ";
- cin >> n;
- cout << " [!] - The Binary Number Of That Decimal Number is: " << C_Menu_Choice_Two(n) << endl;
- }
- else{
- cout << "\nInvalid Input\n";
- }
- }
- else{
- cout << "\nInvalid Input\n";
- }
- }
- cout << "\n[+] - The End Of The Program!\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement