Question

In: Computer Science

Write a C++ program that uses all the relational operators.

Write a C++ program that uses all the relational operators.

Solutions

Expert Solution

An operator is a symbol that is used to perform some manipulations with the values

There are several types of operators:

Arithematic operator

Relational operator

Bitwise operator ,etc

Relational operators are the operators that are used to compare two values.

Syntax:

value1 operator value2

Here , value1 and value2 can be of string , integer or any data type

operator used as part of relational operations are :

< : Less than operator - Checks if left value is less than right value , then the result is true otherwsie false

Example: 5<7 -> true , if 7<5 -> false

> : Greater than operator - Checks if left value is greater than right value , then the result is true otherwsie false

Example: 7>5 -> true , if 5>7 -> false

== : Equal to   - Checks if left value is equal to right value , then the result is true otherwsie false

Example: 7==7 -> true , if 5==7 -> false

<= :   Less than Equal to operator - Checks if left value is less than or equal to right value , then the result is true otherwsie false

Example: 5<=7 -> true , if 7<=7 -> true , if 7<=5 -> false

>= :   Greater than Equal to operator - Checks if left value is greater than or equal to right value , then the result is true otherwsie false

Example: 7>=5 -> true , if 7>=7 -> true , if 5>=7 -> false

!= : Not equal to  - Checks if left value is not equal to right value , then the result is true otherwsie false

Example: 5!=7 -> true , if 7!=7 -> false

Precedence of operators:

>= , > , <= ,< - Higher precedence operators

== , !=   - Lower precedence operators

Meaning , if an expression is having both high and low precedence operator , then higher precedence operators will be evaluated first and low precedence will be evaluated after that

\n -> is a formatting character used for new line . It is used to print ouput in new line.

Code in C++ :

#include <iostream>

using namespace std; //used for input output streams to printoutput /take input in console

int main()
{
cout<<"Relation operators example : "<<"\n";
int value1= 100;
int value2= 70;
//Not Equal to opertor usage
if(value1 != value2){
cout<<"Value1 and Value2 are not equal "<<"\n";
}
else{
cout<<"Value1 and Value2 are equal "<<"\n";
}
//Equal to opertor usage
if(value1 == value2){
cout<<"Value1 and Value2 are equal "<<"\n";
}
else{
cout<<"Value1 and Value2 are not equal "<<"\n";
}
//less than opertor usage
if(value1 < value2){
cout<<"Value1 is less than Value2 "<<"\n";
}
else{
cout<<"Value1 is not less than Value2 "<<"\n";
}
//Greater than opertor usage
if(value1 > value2){
cout<<"Value1 is greater than Value2 "<<"\n";
}
else{
cout<<"Value1 is not greater than Value2 "<<"\n";
}
//value change of value2 variable
value2= 100;
//less than Equal to opertor usage
if(value1 <= value2){
cout<<"Value1 is less than or equal to Value2 "<<"\n";
}
else{
cout<<"Value1 is not less than or equal to Value2 ";
}
//Greater than Equal to opertor usage
if(value1 >= value2){
cout<<"Value1 is greater than or equal to Value2 ";
}
else{
cout<<"Value1 is not greater than or equal to Value2 ";
}
}

OUTPUT:


Related Solutions

Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
Relational Operators For Cpp Discuss why relational operators can be used with enumeration types. Provide at...
Relational Operators For Cpp Discuss why relational operators can be used with enumeration types. Provide at least 2 examples of relational expressions with enumeration types. Explain your examples
USING C++: Consider the precedence levels of the relational, logical, and arithmetic operators of the PySub...
USING C++: Consider the precedence levels of the relational, logical, and arithmetic operators of the PySub language to be as follows (NOTE: 5 has highest precedence and 0 lowest): 5 *, /, % 4 +, - 3 <, <=, >, >=, !=, == 2 not 1 and 0 or 1.  Infix-Postfix Conversion and Evaluation with Logical and Relational operators – Convert the following infix expression to a postfix expression and evaluate the result (assume that true=1 and false=0). Provide both the...
Write the following questions as queries in RELATIONAL ALGEBRA. Use only the operators discussed in class...
Write the following questions as queries in RELATIONAL ALGEBRA. Use only the operators discussed in class (select, project, Cartesian product, join, union, intersection, set difference and renaming). The following database schema is given: ATHLETE(name,age,height,weight,country) RACE(id,location,date,time-start,distance) COMPETES(aname,rid,time,position) where ATHLETE has information about runners (their name, age, height, weight, and nationality); RACE has information about races (id, location, date when it’s held, time it starts, and distance ran); and COMPETES keeps track of which runners run on with race, the time it...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
C++ Write a program that produces the truth table of the following logical operators. You aresupposed...
C++ Write a program that produces the truth table of the following logical operators. You aresupposed to output one table with all the operators (one column for each operator). Write theheader of the table - this is the name of the columns-. Output the result on the file prog1 output.txt. The table should contain the letters T and F, it should NOT print 1s and 0s. Show theresults on the following order: 1. negation (!) 2. disjunction (AND operator, &)...
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a...
*****For C++ Program***** Overview For this assignment, write a program that uses functions to simulate a game of Craps. Craps is a game of chance where a player (the shooter) will roll 2 six-sided dice. The sum of the dice will determine whether the player (and anyone that has placed a bet) wins immediately, loses immediately, or if the game continues. If the sum of the first roll of the dice (known as the come-out roll) is equal to 7...
Write a C Program that uses file handling operations of C language. The Program should perform...
Write a C Program that uses file handling operations of C language. The Program should perform following operations: 1. The program should accept student names and students’ assignment marks from the user. 2. Values accepted from the user should get saved in a .csv file (.csv files are “comma separated value” files, that can be opened with spreadsheet applications like MS-Excel and also with a normal text editor like Notepad). You should be able to open and view this file...
c++ Write a program that displays the status of an order. a) Program uses 2 functions...
c++ Write a program that displays the status of an order. a) Program uses 2 functions (in addition to main ()). b) The first function asks the user for the data below and stores the input values in reference parameters. c) Input data from user: # of spools ordered, # of spools in stock, any special shipping & handling charges over and above the $10 rate. d) The second function receives as arguments any values needed to compute and display...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT