Advertisement
noob339

Untitled

Nov 5th, 2021
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.78 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. // prototype for my functions
  7. void funcMenu();
  8. double quadratic (double a, double b, double c);
  9. bool isEven (int num);
  10. void isItPosNegOrZero(double num);
  11. double absoluteValue(double num);
  12. void printChar(char c1);
  13.  
  14. int main() {
  15.    
  16.     //This is the equivalent of our start button to engage with the program
  17.     int program;
  18.     cout << "Type 1 to enter program and 0 to exit: ";
  19.     cin >> program;
  20.    
  21.     int choice;
  22.     //this if statement allows us to enter the program
  23.     if (program == 1)
  24.     {
  25.         //this do while statement executes the menu and the choice selection
  26.         do
  27.         {
  28.             funcMenu();
  29.             cin >> choice;
  30.        
  31.             // this switch statement allows us to pick which feature of the program we desire to engage, from quadratic equation, determining if it's even, whether its negative or positive or 0, the absolute value and the change of character from upper to lower and vice versa.
  32.             switch (choice) {
  33.                    
  34.                 case 1:
  35.                     double num1, num2, num3;
  36.                     cout << "Enter three consecutive real numbers each followed by a space: ";
  37.                     cin >> num1 >> num2 >> num3;
  38.                     double result1;
  39.                     result1 = quadratic(num1, num2, num3);
  40.                     cout << result1 << endl;
  41.                     break;
  42.                
  43.                 case 2:
  44.                     int num4;
  45.                     cout << "Enter an integer to determine if it's even: ";
  46.                     cin >> num4;
  47.                     bool result2;
  48.                     result2 = isEven(num4);
  49.                     cout << result2 << endl;
  50.                     break;
  51.                
  52.                 case 3:
  53.                     double num5;
  54.                     cout << "Enter an integer to determine whether it's positive or negative: ";
  55.                     cin >> num5;
  56.                     isItPosNegOrZero(num5);
  57.                     cout << endl;
  58.                     break;
  59.                
  60.                 case 4:
  61.                     double num6;
  62.                     cout << "Enter a positive or negative integer to determine its absolute value: ";
  63.                     cin >> num6;
  64.                     double result3;
  65.                     result3 = absoluteValue(num6);
  66.                     cout << result3 << endl;
  67.                     break;
  68.                    
  69.                 case 5:
  70.                     char character;
  71.                     cout << "Enter a character: ";
  72.                     cin >> character;
  73.                     printChar(character);
  74.                     cout << endl;
  75.             }
  76.         }
  77.         while (choice < 1 || choice > 6);
  78.     }
  79.     else
  80.     {
  81.         cout << "Please come again whenever you need!\n";
  82.     }
  83.     return 0;
  84. }
  85. //here are our functions for the program, including the menu and the functions that perform the operations selected from the menu itself
  86. void funcMenu ()
  87. {
  88.     //don't need all these cout's, evidently from textbook, but it makes it feel uniform
  89.     cout << "\n\t\t Menu of Functions\n\n";
  90.     cout << "1. Quadratic Formula\n";
  91.     cout << "2. Is it Even or Odd\n";
  92.     cout << "3. Postive Negative or Zero\n";
  93.     cout << "4. The Absolute Value\n";
  94.     cout << "5. Character Case Changer\n";
  95.     cout << "6. Exit\n\n";
  96.     cout << "Enter your choice: ";
  97. }
  98. // Here are our functions which perform the neccesary, well, functions to determine our objectives
  99. double quadratic (double a, double b, double c)
  100. {
  101.     double results;
  102.    
  103.     if (a == 0)
  104.     {
  105.         cout << "no solution for a=0 ";
  106.         return 0;
  107.        
  108.     }
  109.     else if (pow(b,2) - 4*a*c < 0)
  110.     {
  111.         cout << " no real solutions ";
  112.         return 0;
  113.     }
  114.     else
  115.     {
  116.         results = (-b + sqrt(pow(b,2) - 4*a*c))/(2*a);
  117.         return results;
  118.     }
  119. }
  120.  
  121. bool isEven (int num)
  122. {
  123.     bool testValue;
  124.     if (num%2 == 0)
  125.     {
  126.         testValue = true;
  127.     }
  128.     else
  129.     {
  130.         testValue = false;
  131.     }
  132.     return testValue;
  133. }
  134.  
  135. void isItPosNegOrZero(double num)
  136. {
  137.     if (num == 0)
  138.     {
  139.         cout << 0 << endl;
  140.     }
  141.     else if(num > 0)
  142.     {
  143.         cout << '+' << endl;
  144.     }
  145.     else
  146.     {
  147.         cout << '-' << endl;
  148.     }
  149.     return;
  150. }
  151.  
  152. double absoluteValue(double num)
  153. {
  154.     double num1;
  155.    
  156.     if (num > 1)
  157.     {
  158.         num1 = num;
  159.     }
  160.     else
  161.     {
  162.         num1 = num * -1;
  163.     }
  164.     return num1;
  165. }
  166.  
  167. void printChar(char c1)
  168. {
  169.     char letter;
  170.     if(c1 >= 65 && c1 <= 90)
  171.     {
  172.         letter = c1 + 32;
  173.         cout << letter << endl;
  174.     }
  175.     else if (c1 >= 97 && c1 <= 122)
  176.     {
  177.         letter = c1 - 32;
  178.         cout << letter << endl;
  179.     }
  180.     return;
  181. }
  182.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement