Advertisement
Garey

Program lalala

Oct 18th, 2017
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.94 KB | None | 0 0
  1. ///////////////////////////////////////////////////////////////////////////////
  2. //  Program name: Logical and Arithmetic Expressions and Actions
  3. //
  4. //  What it does? - It shows all the logical and arithmetic operations
  5. //  that can be used for a specific data type. The current data types
  6. //  that are used in the program are: bool, integer, double and float.
  7. //
  8. //  How was it made? - It was made using iosteram and conio.h. Conio.h
  9. //  was used to expect user input from getch() function, "About the author"
  10. //  section. iostream was used for all the specific input and output stream
  11. //  data usage, such as cout and cin.
  12. //
  13. //  Author: [Insert Name Here]
  14. //
  15. ///////////////////////////////////////////////////////////////////////////////
  16.  
  17. #include <iostream>
  18. #include <conio.h>
  19.  
  20. using namespace std;
  21.  
  22. int main() {
  23.         // Using key for the main menu
  24.         int key;
  25.         // Declaring variables from type int
  26.         int a = 3;
  27.         int b = 4;
  28.         // Declaring variables from type double
  29.         double c = 5.2;
  30.         double d = 6.33;
  31.         // Declaring variables from type float
  32.         float e = 3.149349;
  33.         float f = 5.939135;
  34.         // Declaring variables from type bool
  35.         bool g = true;
  36.         bool h = false;
  37.  
  38. // Creating the menu. Do the process, while the key is different
  39. // than 5.
  40. do {
  41.     // Brief menu description, so the user knows what to input
  42.     // and what to expect as an output
  43.     cout << "Menu:" << endl;
  44.     cout << "1. Show the variables" << endl;
  45.     cout << "2. Comparison Actions" << endl;
  46.     cout << "3. Logical Actions" << endl;
  47.     cout << "4. About the author" << endl << endl;
  48.     cout << "5. Exit" << endl;
  49.  
  50.     cout << endl << "Make your choice: ";
  51.     cin >> key;
  52.     // Actions for the menu
  53.     switch (key) {
  54.         case 1:
  55.             // Clears the screen
  56.             system("cls");
  57.  
  58.             cout << "Variable name: a" << " | Variable Value: " << a << " | Variable Type: Integer" << endl;
  59.             cout << "Variable name: b" << " | Variable Value: " << b << " | Variable Type: Integer" << endl;
  60.  
  61.             cout << "Variable name: c" << " | Variable Value: " << c << " | Variable Type: Double" << endl;
  62.             cout << "Variable name: d" << " | Variable Value: " << d << " | Variable Type: Double" << endl;
  63.  
  64.             cout << "Variable name: e" << " | Variable Value: " << e << " | Variable Type: Float" << endl;
  65.             cout << "Variable name: f" << " | Variable Value: " << f << " | Variable Type: Float" << endl;
  66.  
  67.             cout << "Variable name: g" << " | Variable Value: " << e << " | Variable Type: Bool" << endl;
  68.             cout << "Variable name: h" << " | Variable Value: " << f << " | Variable Type: Bool" << endl;
  69.             break;
  70.         case 2:
  71.             // Clears the screen
  72.             system("cls");
  73.  
  74.             int key2;
  75.             // Creating a submenu for all the arithmetic operations
  76.             do {
  77.             cout << "Select option:" << endl;
  78.             cout << "1. Equal or greater than" << endl;
  79.             cout << "2. Equal or less than" << endl;
  80.             cout << "3. Different than" << endl;
  81.             cout << "4. Equal to" << endl;
  82.             cout << "5. Less than" << endl;
  83.             cout << "6. Greater than" << endl << endl;
  84.             cout << "7. Exit" << endl;
  85.  
  86.             cout << endl << "Make your choice: ";
  87.             cin >> key2;
  88.             // Actions for the menu
  89.             switch (key2) {
  90.                 case 1:
  91.  
  92.                     system("cls");
  93.                     // Checks if variable a is greater than or equal to b
  94.                     if(a >= b) {
  95.                         cout << "Variable a is greater than or equal to b" << endl;
  96.                     } else {
  97.                         cout << "Variable b is greater than a" << endl;
  98.                     }
  99.                     // Checks if variable c is greater than or equal to d
  100.                     if(c >= d) {
  101.                         cout << "Variable c is greater than or equal to d" << endl;
  102.                     } else {
  103.                         cout << "Variable d is greater than c" << endl;
  104.                     }
  105.                     // Checks if variable e is greater than or equal to f
  106.                     if(e >= f) {
  107.                         cout << "Variable e is greater than or equal to f" << endl;
  108.                     } else {
  109.                         cout << "Variable f is greater than e" << endl;
  110.                     }
  111.                     // Checks if variable g is greater than or equal to h
  112.                     if(g >= h) {
  113.                         cout << "Variable g is greater than or equal to h" << endl << endl;
  114.                     } else {
  115.                         cout << "Variable h is greater than g" << endl << endl;
  116.                     }
  117.                     break;
  118.                 case 2:
  119.  
  120.                     system("cls");
  121.                     // Checks if variable a is less than or equal to b
  122.                     // It stays the same for all the other expressions
  123.                     if(a <= b) {
  124.                         cout << "Variable a is less than or equal to b" << endl;
  125.                     } else {
  126.                         cout << "Variable b is less than a" << endl;
  127.                     }
  128.  
  129.                     if(c <= d) {
  130.                         cout << "Variable c is less than or equal to d" << endl;
  131.                     } else {
  132.                         cout << "Variable d is less than c" << endl;
  133.                     }
  134.  
  135.                     if(e <= f) {
  136.                         cout << "Variable e is less than or equal to f" << endl;
  137.                     } else {
  138.                         cout << "Variable f is less than e" << endl;
  139.                     }
  140.  
  141.                     if(g <= h) {
  142.                         cout << "Variable g is less than or equal to h" << endl << endl;
  143.                     } else {
  144.                         cout << "Variable h is less than g" << endl << endl;
  145.                     }
  146.                     break;
  147.                 case 3:
  148.  
  149.                     system("cls");
  150.                     // Checks if variable a is NOT equal to b
  151.                     // It stays the same for all the other expressions
  152.                     if(a != b) {
  153.                         cout << "Variable a is different from b" << endl;
  154.                     } else {
  155.                         cout << "Variable b is not different from a" << endl;
  156.                     }
  157.  
  158.                     if(c != d) {
  159.                         cout << "Variable c is different from d" << endl;
  160.                     } else {
  161.                         cout << "Variable d is not different from c" << endl;
  162.                     }
  163.  
  164.                     if(e != f) {
  165.                         cout << "Variable e is different from f" << endl;
  166.                     } else {
  167.                         cout << "Variable f is not different from e" << endl;
  168.                     }
  169.  
  170.                     if(g != h) {
  171.                         cout << "Variable g is different from h" << endl << endl;
  172.                     } else {
  173.                         cout << "Variable h is not different from g" << endl << endl;
  174.                     }
  175.                     break;
  176.                 case 4:
  177.  
  178.                     system("cls");
  179.                     // Checks if variable a is equal to b
  180.                     // It stays the same for all the other expressions
  181.                     if(a == b) {
  182.                         cout << "Variable a is equal to b" << endl;
  183.                     } else {
  184.                         cout << "Variable b is not equal to a" << endl;
  185.                     }
  186.  
  187.                     if(c == d) {
  188.                         cout << "Variable c is equal to d" << endl;
  189.                     } else {
  190.                         cout << "Variable d is not equal to c" << endl;
  191.                     }
  192.  
  193.                     if(e == f) {
  194.                         cout << "Variable e is equal to f" << endl;
  195.                     } else {
  196.                         cout << "Variable f is not equal to e" << endl;
  197.                     }
  198.  
  199.                     if(g == h) {
  200.                         cout << "Variable g is equal to h" << endl << endl;
  201.                     } else {
  202.                         cout << "Variable h is not equal to g" << endl << endl;
  203.                     }
  204.                     break;
  205.                 case 5:
  206.                     // Clears the screen
  207.                     system("cls");
  208.                     // Checks if variable a is less than b
  209.                     // It stays the same for all the other expressions
  210.                     if(a < b) {
  211.                         cout << "Variable a is less than b" << endl;
  212.                     } else {
  213.                         cout << "Variable a is not less than b" << endl;
  214.                     }
  215.  
  216.                     if(c < d) {
  217.                         cout << "Variable c is less than d" << endl;
  218.                     } else {
  219.                         cout << "Variable c is not less than d" << endl;
  220.                     }
  221.  
  222.                     if(e < f) {
  223.                         cout << "Variable e is less than f" << endl;
  224.                     } else {
  225.                         cout << "Variable e is not less than f" << endl;
  226.                     }
  227.  
  228.                     if(g < h) {
  229.                         cout << "Variable g is less than h" << endl << endl;
  230.                     } else {
  231.                         cout << "Variable g is not less than h" << endl << endl;
  232.                     }
  233.                     break;
  234.                 case 6:
  235.  
  236.                     system("cls");
  237.                     // Checks if variable a is greater than b
  238.                     // It stays the same for all the other expressions
  239.                     if(a > b) {
  240.                         cout << "Variable a is greater than b" << endl;
  241.                     } else {
  242.                         cout << "Variable a is not greater than b" << endl;
  243.                     }
  244.  
  245.                     if(c > d) {
  246.                         cout << "Variable c is greater than d" << endl;
  247.                     } else {
  248.                         cout << "Variable c is not greater than d" << endl;
  249.                     }
  250.  
  251.                     if(e > f) {
  252.                         cout << "Variable e is greater than f" << endl;
  253.                     } else {
  254.                         cout << "Variable e is not greater than f" << endl;
  255.                     }
  256.  
  257.                     if(g > h) {
  258.                         cout << "Variable g is greater than h" << endl << endl;
  259.                     } else {
  260.                         cout << "Variable g is not greater than h" << endl << endl;
  261.                     }
  262.                     break;
  263.             }
  264.         } while(key2 != 7); // if any other key other than 7 is pressed, it will show the menu
  265.             system("cls");
  266.             break;
  267.  
  268.         case 3:
  269.                 // Clears the screen
  270.                 system("cls");
  271.  
  272.                 int key3;
  273.                 // Creating another submenu for the logical operations
  274.                 do {
  275.                 cout << "Select option:" << endl;
  276.                 cout << "1. Logical NOT" << endl;
  277.                 cout << "2. Logical AND" << endl;
  278.                 cout << "3. Logical inclusive OR" << endl << endl;
  279.                 cout << "4. Exit" << endl;
  280.  
  281.                 cout << endl << "Make your choice: ";
  282.                 cin >> key3;
  283.                 // Actions for the options
  284.                 switch (key3) {
  285.                     case 1:
  286.                         system("cls");
  287.                         // This time, we will show how it looks like one logical
  288.                         // expression and what happens if integer gets its value
  289.                         // from the expression.
  290.                         // What actually happens here?
  291.                         // The variable a is shown before it has been changed
  292.                         // On the change, the variable a receives the value
  293.                         // of a boolean statement which states: is a true?
  294.                         // In our case, a has anything but a zero, so its true.
  295.                         // Though, the opposite of true is false.Therefore:
  296.                         // a receives the value of 0. The same way goes for
  297.                         // all the other variables as shown below, except
  298.                         // for the boolean variables. They receive the
  299.                         // opposite value they have in theirelves.
  300.                         // For example: a = true; !a = false;
  301.                         cout << "Variable a value before logical NOT: " << a << endl;
  302.                         a = !a;
  303.                         cout << "Variable a value after logical NOT: " << a << endl << endl;
  304.  
  305.                         cout << "Variable b value before logical NOT: " << b << endl;
  306.                         b = !b;
  307.                         cout << "Variable b value after logical NOT: " << b << endl << endl;
  308.  
  309.                         cout << "Variable c value before logical NOT: " << c << endl;
  310.                         c = !c;
  311.                         cout << "Variable c value after logical NOT: " << c << endl << endl;
  312.  
  313.                         cout << "Variable d value before logical NOT: " << d << endl;
  314.                         d = !d;
  315.                         cout << "Variable d value after logical NOT: " << d << endl << endl;
  316.  
  317.                         cout << "Variable e value before logical NOT: " << e << endl;
  318.                         e = !e;
  319.                         cout << "Variable e value after logical NOT: " << e << endl << endl;
  320.  
  321.                         cout << "Variable f value before logical NOT: " << f << endl;
  322.                         f = !f;
  323.                         cout << "Variable f value after logical NOT: " << f << endl << endl;
  324.  
  325.                         cout << "Variable g value before logical NOT: " << g << endl;
  326.                         g = !g;
  327.                         cout << "Variable g value after logical NOT: " << g << endl << endl;
  328.  
  329.                         cout << "Variable h value before logical NOT: " << h << endl;
  330.                         h = !h;
  331.                         cout << "Variable h value after logical NOT: " << h << endl << endl;
  332.  
  333.                         break;
  334.                     case 2:
  335.  
  336.                         system("cls");
  337.                         // What it actually happens?
  338.                         // Even tho it's written in the cout, let's explain
  339.                         // The logical AND statement states that both of the
  340.                         // expression sides are equally true or false.
  341.                         // What does that mean?
  342.                         // If one expression is false and the other is true
  343.                         // the whole statement doesn't make it true at all,
  344.                         // because to be true, it needs both sides to be
  345.                         // true or false, depending on the expression
  346.                         // It covers the same for the other if statement
  347.                         if(a <= b && c >= d) {
  348.                             cout << "Both expressions are correct" << endl;
  349.                         } else {
  350.                             cout << "One of the expressions is not correct" << endl;
  351.                         }
  352.  
  353.                         if(e <= f && g == h) {
  354.                             cout << "Both expressions is correct" << endl << endl;
  355.                         } else {
  356.                             cout << "One of the expressions is not correct" << endl << endl;
  357.                         }
  358.  
  359.                         break;
  360.                     case 3:
  361.  
  362.                         system("cls");
  363.                         // What it actually happens?
  364.                         // Even tho it's written in the cout, let's explain
  365.                         // The logical inclusive OR statement states that one of the
  366.                         // expression sides is true.
  367.                         // What does that mean?
  368.                         // If one expression is false and the other is true
  369.                         // the whole statement is not false at all.
  370.                         // You can have only one true expression and the
  371.                         // whole statement will be turned out as a true
  372.                         // It stays the same for the other statement
  373.                         // as well.
  374.                         if(a <= b || c >= d) {
  375.                             cout << "One of the expressions is correct" << endl;
  376.                         } else {
  377.                             cout << "None of the expressions are correct" << endl;
  378.                         }
  379.  
  380.                         if(e == f || g == h) {
  381.                             cout << "One of the expressions is correct" << endl << endl;
  382.                         } else {
  383.                             cout << "None of the expressions are correct" << endl << endl;
  384.                         }
  385.  
  386.                         break;
  387.                 }
  388.             } while(key3 != 4);
  389.  
  390.             system("cls");
  391.             break;
  392.         case 4:
  393.             system("cls");
  394.             // Some author notes and about the author.
  395.             cout << "Program Name: Logical and Arithmetic Expressions and Actions" << endl;
  396.             cout << "The program was made by [Insert Girl Name Here]" << endl;
  397.             cout << "Best Regards!" << endl << endl;
  398.             cout << "Press any key to get back in the main menu....";
  399.             //Expects the user to press any key to get back to the main menu
  400.             getch();
  401.             system("cls");
  402.             break;
  403.     }
  404.  
  405. } while(key != 5);
  406.  
  407.     return 0;
  408. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement