Brief History and Turbo C++ Editor Environment
Brief History and Turbo C++ Editor Environment
C++ was designed by Bjarne Stroustrup while he was working for AT&T Bell Labs, which
eventually packaged and marketed it. Initial versions of the language were made available
internally at AT&T beginning in 1981. C++ evolved steadily in response to user feedback.
The first edition of Stroustrup's book, The C++ Programming Language, was published
in early 1986. After the release of Version 2.0 in 1989, C++ was rapidly acknowledged as a
serious, useful language. Work began that year to establish an internationally recognized
language standard for it. In 1997, a committee of the American National Standards Institute
(ANSI) completed and published internally the Draft Standard - The C++ Language, X3J16/97-
14882, Information Technology Council (NSITC), Washington, DC.
To execute the integrated version of Turbo C++, simply use the command prompt then
go to the root directory, open the TCC folder and execute the TC.EXE application
IDENTIFIERS
TYPES OF IDENTIFIERS
PREDEFINED IDENTIFIERS
What is a variable?
A variable is a data storage location that has a value, which can change
during program execution. By using a variable’s name in your program, you are,
in effect referring to the data stored there. You must initialize a variable -
probably giving it a value of zero - before you use it in a calculation or you need
to make sure that it is given a value in some other way. All variables in C++ must
be declared prior to their use.
1. Outside of all functions, including the main() function. This sort of variable is
called global and may be used by any part of the program.
2. Inside the function. Variables in this way are called local variables and may
be used only by statements that are also in the same function.
3. In the declaration of a formal parameter of a function. The formal parameters
are used to receive the arguments when that function is called.
These are special character constants that can be expressed using its respective
backslash code
DATA TYPES
OPERATORS
These are the symbols that tell the compiler to perform specific mathematical or
logical manipulations.
Types of Operators
5. Relational Operators - These are operators that allow the comparison of two or
more numerical values, yielding a result based on whatever the comparison is
true(1) or false(0).
6. Logical Operators - These operators work with logical values true(1) and
false(0) allowing to combine relational operators.
SAMPLE PROGRAM:
void main ()
clrscr();
getch();
C++ uses a convenient abstraction called streams to perform input and output operations
in sequential media such as the screen, the keyboard or a file. A stream is an entity where a
program can either insert or extract characters to/from. There is no need to know details about
the media associated to the stream or any of its internal specifications. All we need to know is
that streams are a source/destination of characters, and that these characters are
provided/accepted sequentially.
The standard library of iostream.h defines a handful of stream objects that can be used
to access what are considered the standard sources and destinations of characters by the
environment where the program runs:
stream description
Standard Output (cout) - On most program environments, the standard output by default is the
screen, and the C++ stream object defined to access it is cout. For formatted output
operations, cout is used together with the insertion operator, which is written as << (i.e., two "less
than" signs).
Standard Input (cin) - In most program environments, the standard input by default is the
keyboard, and the C++ stream object defined to access it is cin. For formatted input
operations, cin is used together with the extraction operator, which is written as >> (i.e., two
"greater than" signs). This operator is then followed by the variable where the extracted data is
stored.
int age;
cin >> age;
Example:
//Input/Output Example Please enter an integer value: 702
The value you entered is 702 and
#include <iostream.h> its double is 1404.
#include <conio.h>
void main ()
{
clrscr();
int i;
cout << "Please enter an integer value: ";
cin >> i;
cout << "The value you entered is " << i;
cout << " and its double is " << i*2 <<
".\n";
getch();
}
conio.h header used in c programming contains functions for console input/output. Some of the
most commonly used functions of conio.h are clrscr, getch, getche, kbhit etc. Functions of
conio.h can be used to clear screen, change color of text and background, move text, check if a
key is pressed or not and many more.
clrscr() - clrscr function clears the screen amd move the cursor to upper left hand corner
of screen.
getch() - getch function prompts the user to press a character and that character is not
printed on screen, getch header file is conio.h.
gotoxy() - gotoxy function places cursor at a desired location on screen i.e. we can
change cursor position using gotoxy function.
Declaration : void gotoxy( int x, int y);
where (x, y) is the position where we want to place the cursor.
textcolor() - textcolor function is used to change the color of drawing text in c programs.
textbackground() - textbackground function is used to change of current background
color in text mode.
Conditional control statements are at the very core of programming, in almost any
language. The idea behind conditional control is that it allows you to control the flow of the code
that is executed based on different conditions in the program, input taken from the user, the
internal state of the machine the program is running on, etc.
Conditional statements specify whether another statement or block of statements should
be executed or not. These are often called "selection constructs". A conditional expression is an
expression that produces a true or false result. There are three major structures related to the
conditional execution of code in C/C++ - the if statement, the if-else statement, and the switch-
case statement.
if-statement
Syntax:
if(condition_expression)
statement;
Where condition is the expression that is being evaluated. If this condition is true,
statement is executed. If it is false, statement is ignored (not executed) and the program
continues right after this conditional structure.
Example:
if (x == 0)
if-else statement
Syntax:
if(Condition_Expression)
Statement_TRUE;
else
Statement_FALSE;
If the if statement evaluates to true, then all the statements inside the ifblock are
executed and the else if will be ignored. When the if statement is false, it will then check the
condition in the else if statement.
Example No. 1
if (x >= 0)
else
Example No. 2
if (x %2 == 0)
cout<<“It is EVEN.”;
else
cout<<“It is ODD.”;
Nested-if statement
Syntax:
if(Condition_Expression1)
Statement1;
else if(Condition_Expression2)
Statement2;
else if(Condition_Expression3)
Statement3;
else
Statement-n;
Reminders:
switch statement
switch(expression) {
case constant_value_1: statement1;
break;
case constant_value_2: statement2;
break;
case constant_value_3: statement3;