You are on page 1of 16

C++ Program

• Variables
• Cin >> varName;
What is a Variable?
Definition of terms
• string
• char or character
• boolean of bool
• integer or int
• Floating point number (float,double)
• cin
Strings
-Is used for data values that are made up of ordered
sequences of characters, such as "hello world". A string
can contain any sequence of characters, visible or
invisible, and characters may be repeated. The number
of characters in the string is called its length, and "hello
world" has length 11 - made up of 10 letters and 1 space.
It is comprised of a set of characters that can also
contain spaces and numbers. For example, the word
"hamburger" and the phrase "I ate 3 hamburgers" are
both strings. Even "12345" could be considered a string,
if specified correctly.
The abbreviation char is short for character, which is
a data type that holds one character (letter, number,
etc.) of data. For example, the value of a char variable
 could be any one-character value, such as 'A', '4', or
'#'.
In computer science, a boolean or bool is
a data type with two possible values: true
 or false.

It is named after the English


mathematician and logician George Boole,
whose algebraic and logical systems are
used in all modern digital computers.
An integer is a whole number (not a fraction) that
can be positive, negative, or zero. Therefore, the
numbers 10, 0, -25, and 5,148 are all integers.
Unlike floating point numbers, integers cannot
have decimal places.

As the name implies, floating point numbers are


numbers that contain floating decimal points. For
example, the numbers 5.5, 0.001, and -2,345.6789
are floating point numbers. Numbers that do not
have decimal places are called integers.
.

A small table that gives the memory requirement and range of float and
double is shown below –
Floating point type Memory requirement Range
±3.40282347E+38F i.e. 6-7
Float 4 bytes
significant digits
±1.79769313486231570E+
Double 8 bytes 308 i.e. 15-16 significant
digits
cin (character input)
The cin object in C++ is used to accept the input from the
standard input device i.e. keyboard.

The "c" in cin refers to "character" and 'in' means "input",


hence cin means "character input".

The cin object is used along with the extraction operator (>>) in


order to receive a stream of characters.
The general syntax is: cin >> varName:
Syntax in computer programming as the concept of giving specific
word sets in specific orders to computers so that they do what we
want them to do. Every programming language uses different word
sets in different orders, which means that each programming
language uses its own syntax.

In programming, syntax refers to the rules that specify the correct


combined sequence of symbols that can be used to form a
correctly structured program using a given programming language.
What is the syntax for the following object?

cout = cout << varName; or cout << “ Text ”; (Display the output)

string = string varName; or string varName = “ Text ”; (Enter Text)

cin = cin >>varName; (input data in the console)

int = int varName; (input whole number)

float = float varName; (input numbers with decimal)

You might also like