Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////////////////////////////////////////////////
- // Program name: Logical and Arithmetic Expressions and Actions
- //
- // What it does? - It shows all the logical and arithmetic operations
- // that can be used for a specific data type. The current data types
- // that are used in the program are: bool, integer, double and float.
- //
- // How was it made? - It was made using iosteram and conio.h. Conio.h
- // was used to expect user input from getch() function, "About the author"
- // section. iostream was used for all the specific input and output stream
- // data usage, such as cout and cin.
- //
- // Author: [Insert Name Here]
- //
- ///////////////////////////////////////////////////////////////////////////////
- #include <iostream>
- #include <conio.h>
- using namespace std;
- int main() {
- // Using key for the main menu
- int key;
- // Declaring variables from type int
- int a = 3;
- int b = 4;
- // Declaring variables from type double
- double c = 5.2;
- double d = 6.33;
- // Declaring variables from type float
- float e = 3.149349;
- float f = 5.939135;
- // Declaring variables from type bool
- bool g = true;
- bool h = false;
- // Creating the menu. Do the process, while the key is different
- // than 5.
- do {
- // Brief menu description, so the user knows what to input
- // and what to expect as an output
- cout << "Menu:" << endl;
- cout << "1. Show the variables" << endl;
- cout << "2. Comparison Actions" << endl;
- cout << "3. Logical Actions" << endl;
- cout << "4. About the author" << endl << endl;
- cout << "5. Exit" << endl;
- cout << endl << "Make your choice: ";
- cin >> key;
- // Actions for the menu
- switch (key) {
- case 1:
- // Clears the screen
- system("cls");
- cout << "Variable name: a" << " | Variable Value: " << a << " | Variable Type: Integer" << endl;
- cout << "Variable name: b" << " | Variable Value: " << b << " | Variable Type: Integer" << endl;
- cout << "Variable name: c" << " | Variable Value: " << c << " | Variable Type: Double" << endl;
- cout << "Variable name: d" << " | Variable Value: " << d << " | Variable Type: Double" << endl;
- cout << "Variable name: e" << " | Variable Value: " << e << " | Variable Type: Float" << endl;
- cout << "Variable name: f" << " | Variable Value: " << f << " | Variable Type: Float" << endl;
- cout << "Variable name: g" << " | Variable Value: " << e << " | Variable Type: Bool" << endl;
- cout << "Variable name: h" << " | Variable Value: " << f << " | Variable Type: Bool" << endl;
- break;
- case 2:
- // Clears the screen
- system("cls");
- int key2;
- // Creating a submenu for all the arithmetic operations
- do {
- cout << "Select option:" << endl;
- cout << "1. Equal or greater than" << endl;
- cout << "2. Equal or less than" << endl;
- cout << "3. Different than" << endl;
- cout << "4. Equal to" << endl;
- cout << "5. Less than" << endl;
- cout << "6. Greater than" << endl << endl;
- cout << "7. Exit" << endl;
- cout << endl << "Make your choice: ";
- cin >> key2;
- // Actions for the menu
- switch (key2) {
- case 1:
- system("cls");
- // Checks if variable a is greater than or equal to b
- if(a >= b) {
- cout << "Variable a is greater than or equal to b" << endl;
- } else {
- cout << "Variable b is greater than a" << endl;
- }
- // Checks if variable c is greater than or equal to d
- if(c >= d) {
- cout << "Variable c is greater than or equal to d" << endl;
- } else {
- cout << "Variable d is greater than c" << endl;
- }
- // Checks if variable e is greater than or equal to f
- if(e >= f) {
- cout << "Variable e is greater than or equal to f" << endl;
- } else {
- cout << "Variable f is greater than e" << endl;
- }
- // Checks if variable g is greater than or equal to h
- if(g >= h) {
- cout << "Variable g is greater than or equal to h" << endl << endl;
- } else {
- cout << "Variable h is greater than g" << endl << endl;
- }
- break;
- case 2:
- system("cls");
- // Checks if variable a is less than or equal to b
- // It stays the same for all the other expressions
- if(a <= b) {
- cout << "Variable a is less than or equal to b" << endl;
- } else {
- cout << "Variable b is less than a" << endl;
- }
- if(c <= d) {
- cout << "Variable c is less than or equal to d" << endl;
- } else {
- cout << "Variable d is less than c" << endl;
- }
- if(e <= f) {
- cout << "Variable e is less than or equal to f" << endl;
- } else {
- cout << "Variable f is less than e" << endl;
- }
- if(g <= h) {
- cout << "Variable g is less than or equal to h" << endl << endl;
- } else {
- cout << "Variable h is less than g" << endl << endl;
- }
- break;
- case 3:
- system("cls");
- // Checks if variable a is NOT equal to b
- // It stays the same for all the other expressions
- if(a != b) {
- cout << "Variable a is different from b" << endl;
- } else {
- cout << "Variable b is not different from a" << endl;
- }
- if(c != d) {
- cout << "Variable c is different from d" << endl;
- } else {
- cout << "Variable d is not different from c" << endl;
- }
- if(e != f) {
- cout << "Variable e is different from f" << endl;
- } else {
- cout << "Variable f is not different from e" << endl;
- }
- if(g != h) {
- cout << "Variable g is different from h" << endl << endl;
- } else {
- cout << "Variable h is not different from g" << endl << endl;
- }
- break;
- case 4:
- system("cls");
- // Checks if variable a is equal to b
- // It stays the same for all the other expressions
- if(a == b) {
- cout << "Variable a is equal to b" << endl;
- } else {
- cout << "Variable b is not equal to a" << endl;
- }
- if(c == d) {
- cout << "Variable c is equal to d" << endl;
- } else {
- cout << "Variable d is not equal to c" << endl;
- }
- if(e == f) {
- cout << "Variable e is equal to f" << endl;
- } else {
- cout << "Variable f is not equal to e" << endl;
- }
- if(g == h) {
- cout << "Variable g is equal to h" << endl << endl;
- } else {
- cout << "Variable h is not equal to g" << endl << endl;
- }
- break;
- case 5:
- // Clears the screen
- system("cls");
- // Checks if variable a is less than b
- // It stays the same for all the other expressions
- if(a < b) {
- cout << "Variable a is less than b" << endl;
- } else {
- cout << "Variable a is not less than b" << endl;
- }
- if(c < d) {
- cout << "Variable c is less than d" << endl;
- } else {
- cout << "Variable c is not less than d" << endl;
- }
- if(e < f) {
- cout << "Variable e is less than f" << endl;
- } else {
- cout << "Variable e is not less than f" << endl;
- }
- if(g < h) {
- cout << "Variable g is less than h" << endl << endl;
- } else {
- cout << "Variable g is not less than h" << endl << endl;
- }
- break;
- case 6:
- system("cls");
- // Checks if variable a is greater than b
- // It stays the same for all the other expressions
- if(a > b) {
- cout << "Variable a is greater than b" << endl;
- } else {
- cout << "Variable a is not greater than b" << endl;
- }
- if(c > d) {
- cout << "Variable c is greater than d" << endl;
- } else {
- cout << "Variable c is not greater than d" << endl;
- }
- if(e > f) {
- cout << "Variable e is greater than f" << endl;
- } else {
- cout << "Variable e is not greater than f" << endl;
- }
- if(g > h) {
- cout << "Variable g is greater than h" << endl << endl;
- } else {
- cout << "Variable g is not greater than h" << endl << endl;
- }
- break;
- }
- } while(key2 != 7); // if any other key other than 7 is pressed, it will show the menu
- system("cls");
- break;
- case 3:
- // Clears the screen
- system("cls");
- int key3;
- // Creating another submenu for the logical operations
- do {
- cout << "Select option:" << endl;
- cout << "1. Logical NOT" << endl;
- cout << "2. Logical AND" << endl;
- cout << "3. Logical inclusive OR" << endl << endl;
- cout << "4. Exit" << endl;
- cout << endl << "Make your choice: ";
- cin >> key3;
- // Actions for the options
- switch (key3) {
- case 1:
- system("cls");
- // This time, we will show how it looks like one logical
- // expression and what happens if integer gets its value
- // from the expression.
- // What actually happens here?
- // The variable a is shown before it has been changed
- // On the change, the variable a receives the value
- // of a boolean statement which states: is a true?
- // In our case, a has anything but a zero, so its true.
- // Though, the opposite of true is false.Therefore:
- // a receives the value of 0. The same way goes for
- // all the other variables as shown below, except
- // for the boolean variables. They receive the
- // opposite value they have in theirelves.
- // For example: a = true; !a = false;
- cout << "Variable a value before logical NOT: " << a << endl;
- a = !a;
- cout << "Variable a value after logical NOT: " << a << endl << endl;
- cout << "Variable b value before logical NOT: " << b << endl;
- b = !b;
- cout << "Variable b value after logical NOT: " << b << endl << endl;
- cout << "Variable c value before logical NOT: " << c << endl;
- c = !c;
- cout << "Variable c value after logical NOT: " << c << endl << endl;
- cout << "Variable d value before logical NOT: " << d << endl;
- d = !d;
- cout << "Variable d value after logical NOT: " << d << endl << endl;
- cout << "Variable e value before logical NOT: " << e << endl;
- e = !e;
- cout << "Variable e value after logical NOT: " << e << endl << endl;
- cout << "Variable f value before logical NOT: " << f << endl;
- f = !f;
- cout << "Variable f value after logical NOT: " << f << endl << endl;
- cout << "Variable g value before logical NOT: " << g << endl;
- g = !g;
- cout << "Variable g value after logical NOT: " << g << endl << endl;
- cout << "Variable h value before logical NOT: " << h << endl;
- h = !h;
- cout << "Variable h value after logical NOT: " << h << endl << endl;
- break;
- case 2:
- system("cls");
- // What it actually happens?
- // Even tho it's written in the cout, let's explain
- // The logical AND statement states that both of the
- // expression sides are equally true or false.
- // What does that mean?
- // If one expression is false and the other is true
- // the whole statement doesn't make it true at all,
- // because to be true, it needs both sides to be
- // true or false, depending on the expression
- // It covers the same for the other if statement
- if(a <= b && c >= d) {
- cout << "Both expressions are correct" << endl;
- } else {
- cout << "One of the expressions is not correct" << endl;
- }
- if(e <= f && g == h) {
- cout << "Both expressions is correct" << endl << endl;
- } else {
- cout << "One of the expressions is not correct" << endl << endl;
- }
- break;
- case 3:
- system("cls");
- // What it actually happens?
- // Even tho it's written in the cout, let's explain
- // The logical inclusive OR statement states that one of the
- // expression sides is true.
- // What does that mean?
- // If one expression is false and the other is true
- // the whole statement is not false at all.
- // You can have only one true expression and the
- // whole statement will be turned out as a true
- // It stays the same for the other statement
- // as well.
- if(a <= b || c >= d) {
- cout << "One of the expressions is correct" << endl;
- } else {
- cout << "None of the expressions are correct" << endl;
- }
- if(e == f || g == h) {
- cout << "One of the expressions is correct" << endl << endl;
- } else {
- cout << "None of the expressions are correct" << endl << endl;
- }
- break;
- }
- } while(key3 != 4);
- system("cls");
- break;
- case 4:
- system("cls");
- // Some author notes and about the author.
- cout << "Program Name: Logical and Arithmetic Expressions and Actions" << endl;
- cout << "The program was made by [Insert Girl Name Here]" << endl;
- cout << "Best Regards!" << endl << endl;
- cout << "Press any key to get back in the main menu....";
- //Expects the user to press any key to get back to the main menu
- getch();
- system("cls");
- break;
- }
- } while(key != 5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement