Posts

Showing posts from February, 2021

C++ 04: cin Functions

  1) cin.ignore() : The cin.ignore() function is used which is used to ignore or clear one or more characters from the input buffer. To get the idea about ignore() is working, we have to see one problem, and its solution is found using the ignore() function. The problem is like below. Sometimes we need to clear the unwanted buffer, so when next input is taken, it stores into the desired container, but not in the buffer of previous variable. For example, after entering into the cin statement, we need to input a character array or string. So we need to clear the input buffer, otherwise it will occupy the buffer of previous variable. By pressing the “Enter” key after the first input, as the buffer of previous variable has space to hold new data, the program skips the following input of container. Write a program to read Date of birth of a person and display it. # include <iostream> using namespace std ; main () {      int   D ,  M ,  Y ; ...

C++ 03: Operators in C++

Image
  Operators in C++ 1) Arithmetic Operators in C++ Addition Operator  +  Subtraction Operator - Multiplication Operator * Division Operator / Modulo Operator % Program in C++ to demonstrate Arithmetic Operators # include <iostream> using namespace std ; int main () { int a, b; a = 7 ; b = 2 ; // printing the sum of a and b cout << "a + b = " << (a + b) << endl ; // printing the difference of a and b cout << "a - b = " << (a - b) << endl ; // printing the product of a and b cout << "a * b = " << (a * b) << endl ; // printing the division of a by b cout << "a / b = " << (a / b) << endl ; // printing the modulo of a by b cout << "a % b = " << (a % b) << endl ; return 0 ; } Increment and Decrement Operators C++ also provides increment and decrement operators:  ++...

C++ 02: Data Types and Variables

Image
Data Types in C++ 1) To store numbers without decimal points. Data Type Memory int 2 bytes long 4bytes 2) To store numbers with decimal points. Data Type Memory float 4 bytes double 8bytes 3)To store characters like alphabets and symbols. Data Type Memory char 1byte     Variables  A memory location with specified name is called as variable. The variables are used to store the values of different data types. Syntax:               data_type_variable_name E.g.    float x = 3.14;