Recent Post

MATLAB : Fourier transform

Image
By Nuno Nogueira, CC BY-SA 2.5, https://commons.wikimedia.org/w/index.php?curid=3912826 MATLAB has been  crucial programming language across worldwide that let us express matrix and array mathematics directly. In signal processing and communication it plays vital role in analysing and exploring time series data in time domain or frequency domain. For analysing non periodic signals in frequency domain we use Fourier transform instead of Fourier series ,which is used to express periodic signals in terms of infinite sum of sinusoidal terms .   Fourier transform can exist for :      1. Energy signals      2. Power signals       3. Impulse signals  That means absolutely integrable signals can have their Fourier transform only.  Formula for Fourier transform;   Then its come to use Fourier transform in MATLAB. So here is the code for Fourier transform of sinusoidal wave , for any other signal we ...

How to clear input buffer in c++(use of cin.ignore() function)

How to clear input buffer in c++(use of cin.ignore() function)

A temporary storage area is called a buffer. Sometimes we need to clear the unwanted buffer, so when the next input is taken, it stores into the desired container, but not in the buffer of the previous variable.

Let's see the following example

we take a number and a character array as input through the keyboard and print it on the screen as output. 


In this example, we have entered a number and a string but when the program run then we get only a number as the output.

This is because off after entering a number 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 the previous variable.

To resolve this issue we need cin.ignore()
function. After taking first input it will clear the buffer and it will take second input.

The syntax of cin.ignore() function is given below

cin.ignore(numeric_limits<streamsize>::max(),'\n');

In the following program we have used cin.ignore() function to clear the input buffer :-

Comments

Popular posts from this blog

Chandrayaan : A glorious legacy

Voyager : Journey of the twin to interstellar space

ISRO: From bicycle to a billion dreams