Turbo C++ Editor Environment - Elements of C++ - Structure of C++ Program
Turbo C++ Editor Environment - Elements of C++ - Structure of C++ Program
Turbo C++ Editor Environment - Elements of C++ - Structure of C++ Program
TO
C++
Turbo C++ Editor Environment | Elements of C++ | Structure of C++ Program
M A I N M E N U SCREEN
FILE M E N U
COMPILE M E N U
RUN MENU
S U M M A R Y OF THE M A I N M E N U ITEMS
Item Description
FILE Loads and saves files, handles directories, invokes DOS,
and exits Turbo C++
EDIT Invokes the Turbo C++ editor
RUN Compiles, links, and runs the program currently loaded in the
environment
COMPILE Compiles the program currently in the environment
PROJECT Manages multiple projects
OPTIONS Sets various compiler, linker and environmental options
2. Identifiers
• Variables
• Constants
3. Data Types
4. Operators
• Assignment
• Arithmetic
• Increment / Decrement
• Relational
• Logical
IDENTIFIERS
These are a sequence of one or more
letters, digits, or underline symbols( _ ) that
are used to identify functions, classes, or
other elements of C++ language.
TYPES OF IDENTIFIERS
• Predefined Identifier – Reserved Words /
Keywords
• User-defined Identifier – Variable Names
PREDEFINED IDE NTIFIERS/C + + RE SERVED
WORDS
THE 3 2 ANSI K E
YWORDS
auto double int struct
break else long switch
case enum register typedef
char extern return union
const float short unsigned
continue for signed void
default goto sizeof volatile
do if static while
U SER-D EFIN ED I D EN TIFIER S
W O RD S
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.
HOW TO CREATE A VARIABLE NAME?
Variables can be given any name up to 31 characters in
length which is composed of any of the following
characters:
Characters a to z and A to Z
(NOTE: upper case and lower case are distinct)
The first character must be a letter.
Only letters, digits or underscores may follow the
initial letter.
Blank spaces and special characters are not
allowed .
HOW TO CREATE A VARIABLE NAME?
Use the underscore to separate words in a
name consisting of multiple words or
capitalize the first letter of one or more
words.
Do not use underscore as the first character
of a name.
Must not be any of the 32 keywords.
Variable names must be meaningful.
TELL WHETHER THE FOLLOWING VARIABLES ARE
VALID OR INVALID:
velocity @discount
#sam
unit_
break 1
day_month_year
first-variable
temp_dat
%_rat a
e pay_perio
40_birthda
d
y
2percent
TELL WHETHER THE FOLLOWING
VARIABLES ARE VALID OR INVALID:
velocity @discount
#sa
m unit_
break 1
day_month_year
first-variable
temp_data
%_rat
e pay_perio
40_birthda
d
2percent y Red means
invalid
CONSTANTS
A constant is any expression that has a
fixed value.
Unlike a variable, the value stored in a
constant cannot be changed during
program execution.
CONSTANTS C A N B E A N Y OF THE DATA TYPES:
double Double Precision 8 bytes +/- 1.7e +/- 308 (~15 digits)
float num;
int a, size,
DECLARING VARIABLES WITH INITIAL VALUES
int value1 = 0;
int value2 = 27;
T HE R E AR E T HR E E P L A C E S IN A C ++P R
OGR AM WH E R E VA R I A B L E S CA N BE D E C L
ARED:
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.
4. OPERATORS
These are the symbols that tell the compiler to
perform specific mathematical or logical
manipulations.
Types of Operators
Assignment Operator
Arithmetic Operators
Compound Operators
Relational Operators
Logical Operators
A. ASSIGNMENT OPERATOR
++, --
*, /, %
+, -
=
C. COMPOUND OPERATORS
Example:
x += y; --> this
means x=x+y
compound operator
d. Increment/Decrement Operator
Example:
a+ +
b--
d. 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).
D. RELATIONAL OPERATORS (CONT .)
OPERATORS ACTION
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
== Equal to
!= Not equal
EXAMPLE:
Expression Evaluates As
5 == 1 0 (false)
5 >= 1 1 (true)
5 != 1 1 (true)
(5+10) == (3*5) 1 (true)
e. Logical Operators
These operators work with logical values
true(1) and false(0) allowing to combine
relational operators.
OPERATORS ACTION
&& and
|| or
! not
THE TRUTH TABLE OF BASIC LOGICAL
OPERATIONS
p q p && q p|| q !p
false false false false true
false true false true true
true false false true false
true true true true false
EXAMPLES
:
Expression Evaluates As
(5 == 5) && (6 !=2) True
(5 > 1) | | (6 < 1) True
STRU CTU RE OF A
C + + P R O G RA M
GENERAL F O R M OF A C + + P R O G R A M
function1 ()
•p re p ro c e sso r d ire c t {
ive s glo b a l d e c la ra t l o c a l d e c l a ra t i
io n s; on; statement
•re m a rks 1;
:
statement n;
•m a in( ) }
•{ :
:
•lo c a l d e c la ra t i function2()
o n s ; st a te m e nt {
1; l o c a l d e c l a ra t i
•: on; Statement
1;
•:
:
•st a te m e nt Statement n;
n; g e tc h (); }
•re t urn va
lue ;
•}
1. PREPROCESSOR DIRECTIVE
Example:
#define pi 3.14159
#define taxrate 0.0725
#define g gotoxy --> renaminggo
toxy command to letter g
THE #DEFINE DIRECTIVE
Example:
void area(int l, int w);
int hypotenuse(int a, int b);
8. RETURN STATEMENT