Posts

Showing posts from August, 2025

4.Relational Operators

               When you want to compare two values in terms of operands, this operator is used. List of relational   operators: ‘==’ – it checks that both operands are equal or not. ‘>’ – it checks the first operand is greater than the second operand. ‘<’ – it checks the first operand is less than or not. ‘>=’ – it checks for greater than or equal to ‘<=’ – it checks for less than or equal to ‘!=’ -it checks for not equal The c++ program example is given below. #include <iostream> using namespace std; int main() {     int x = 6, y = 4;     // checks for Equal operator     cout << "x == y is " << (x == y) << endl;     // checks for x is Greater than y     cout << "x > y is " << (x > y) << endl;     // checks for Greater than Equal     cout <...

3.Logical Operators

              Some symbols are used to find the logical values from the conditions. It returns the output as Boolean values either true or false. There are three logical operators in c++. Let us list out as follows… ‘&&’ – Logical AND Operator ‘||’ – Logical OR Operator ‘!’ – Logical NOT Operator Each and every logical operator is illustrated with examples…. ------------------------------------------------------------------------------------------------------------------------- Logical AND Operator(&&):               This operator returns true value when both of the operands are true. The truth table is given below. Operand1 Operand2 Output False False False False True False True False False True True True ...

2.Assignment Operators

               Assignment Operators are mainly used to assign the value. It uses the right to left assignment. The operators are listed below. ‘=’ – Assigns a value. ‘+=’ -Add the value and assign it. ‘-=’ – subtract the value and assign the value. ‘*=’ – multiply it and assign the value. ‘/=’ – divide and assign. Eg: x+=y means x=x+y; x-=y means x=x-y; x*=y means x =x*y; x/=y means x=x/y; A program displays the functionality of assignment operators #include <iostream> using namespace std;   int main() {     int x = 18, y = 3;       // Assignment Operator example.     cout << "x = " << x << endl;     cout << "y = " << y << endl;       //  Addition and Assignment Operator.     cout << "x += y is " << (x += y) << endl;       // Subtraction and ...

Operators in C++

              Operators are key components in any programming language. Operators can be classified into many types listed as follows…        Arithmetic Operators        Assignment Operators        Logical Operators         Relational Operators        Unary operators        Ternary Operators or Conditional Operators        Bitwise operators Each and every operators are detailed explained here. 1.Arithmetic Operators               As the name indicates, these are the operators for perform arithmetic expressions. It has ‘+’ for addition, ’-‘ for subtraction, ‘/’ for division, ‘*’ for multiplication and ‘%’ for mod operation. Each one is expressed in coding. C++ program to use Arithmetic operators:     ...

C++ Program to find ASCII value of Character and Vice Versa

       ASCII stands for American Standard Code for Information Interchange. It is an encoding standard mainly deals with electronic communication. Letters, digits and special characters are assigned with unique ASCII code. How it started?   In 1963, the first edition was developed from telegraph code.   Subsequent revisions in 1967 and 1986. ASCII character Set: It has 128 characters. It has unique seven-bit binary code. These characters include printable and control characters. For eg : null charcter   - it is represented by 0 00000000 For ‘A’, the ascii value is 65. It’s binary code is 01000001. It is world widely accepted character encoding. The upgraded version includes additional 128 characters. Let us create two c++ programs to convert ascii value into character and character into ascii value. C++ program to find ASCII Value of a character: #include <iostream> using namespace std; int main() {     ...

How to get inputs from the user in c++ ?

       Inputs are the important in any programming language. For any language, the processing and outputs are based on the input only. In c++, there are two ways to get the input as follows…       1.  ' cin’ method       2. 'getline()’ method Each one is built-in functions in c++. 1. ‘cin’ method:               This method is included in iostream header file. It reads the input from the user directly. Syntax : cin>> variable name; Eg: cin>> name; Let us create a c++ program to get the input and print it. C++ program: #include <iostream> #include <string> using namespace std; int main() {   int n; char a; string name; float no1; cout<< "Enter the number :"; cin >> n; cout << "Enter the character :" <<endl; cin >> a; cout << "Enter the float number :" <<en...

C++ Variables

               A value or data stored in a memory. It is identified using a name. That is called a 'Variable'. First, a variable should be declared. The syntax is given below…                Datatype variable-name; Eg: int n; float a; double b; char s[]; bool d; Next, the variable should be initialised. ‘int n = 5;’ ‘float a =3.4;’ ‘double b = 5.67;’ ‘char s[] = “string”; ‘bool d = true;’ Let us create a sample program to display the customer details using C++ C++ Program: #include <iostream> using namespace std; int main() {     int   c_age;          // integer variable     string c_id;;          // character variable     string c_name; //String     float c_salary; // float variable...

C++ data types and variables

               Variables are used to store information. It reserves memory. To reverse the memory, it needs to specify the data types. The data types are commonly used are given below…. ·        Integer(int) ·        Float number(float) ·        Double float number(double) ·        Character(char) ·        Void(void) ·        wide character(wchar_t) These data types can be used with these type modifiers. signed unsigned short long let us create a c++ programs to display the size and range of data types. C++ program: #include <iostream> using namespace std; int main() {    cout << "Size of char : " << sizeof(char) <<" byte" << endl;    cout << "char range is-127 to 127 or 0 to...

C++ program to print a message based on the time of the day

              A day has morning, afternoon, evening and night. If the program displays a greeting message based on the time, it will be nice. Let us try this concept in C++. There are three methods to print the message. 1.       Based on the user input. 2.       Based on the system time. 3.       By using functions. Let us implement this. 1.     Based on the user input.      This program reads the input from the user. According to the input, the time message is displayed. #include <iostream> using namespace std; int main() {     int t_hour;     cout << "Enter the hour from the value 0-23: ";     cin >> t_hour;     if (t_hour >= 0 && t_hour < 12) {         cout << "Good Morning! Have a nice...

C++ - an introduction:

  C++ was developed by Bjarne Stroustrup. It is an object-oriented programming language. It is an extension of C. Features: Cross-platform language: It can be executed in multiple platforms. High performance: code execution is efficient. Standard Template Library: it has a rich set of library functions. Compatibility: it is compatible in C. Extensibility: the user can create new data types which makes the language extensible. Exception handling: the exceptions are handled robustly. Memory management: it supports both static and dynamic memory allocation. Multi paradigm development: It supports procedural, object oriented and generic programming. let us create a simple c++ program to display a message. C++ program to display a message: First, include a built -in header file #include<iostream.h> Next, include a namespace std. it includes the standard input and output functionalities. Using namespace std; Create a main() function with retu...

Text editor in C

               Text editor is a simple application to start with developing applications. A simple text editor makes you to create a file, write the contents to the newly created file. It also add some more data to already existing files. If you want read the file, open the existing file and read the contents. Finally, exit option also available in this text editor. Let us implement the simple text editor. C implementation: The functionalities are created as options. It includes f_create(),f_write(),f_read(),f_append(), and main() functions. Here, the implementation uses ‘FILE’ built in pointer to create this text editor in c. The built-in functions used here: “fopen(),fclose(),fgets(),fputs(),fprintf()”. C Program: #include <stdio.h> #include <stdlib.h> #include <string.h> #define max 1000 char text[max]; char ch; void f_create(const char *fname) {     FILE *fp = fopen(fname, "w"); ...