0% found this document useful (0 votes)
52 views

Introduction To Programming Fundamentals

Programming Fundamentals discusses: 1. The need for a translator to communicate between humans and computers, as computers understand binary while humans understand higher level languages. Translators like compilers, interpreters, and assemblers are used to bridge this gap. 2. Key differences between compilers and interpreters - compilers convert source code completely to machine code while interpreters execute instructions step-by-step, making compilers faster but less fault-tolerant. 3. Core programming concepts like variables, data types, expressions, operators, and functions. Variables store values that can change, expressions combine operands and operators, and functions allow breaking a problem into smaller pieces.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Introduction To Programming Fundamentals

Programming Fundamentals discusses: 1. The need for a translator to communicate between humans and computers, as computers understand binary while humans understand higher level languages. Translators like compilers, interpreters, and assemblers are used to bridge this gap. 2. Key differences between compilers and interpreters - compilers convert source code completely to machine code while interpreters execute instructions step-by-step, making compilers faster but less fault-tolerant. 3. Core programming concepts like variables, data types, expressions, operators, and functions. Variables store values that can change, expressions combine operands and operators, and functions allow breaking a problem into smaller pieces.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Programming Fundamentals

Language:-
- Way of communication
- Should be Common Medium between two persons for communications
Language of Computer / Machine Language / Binary Language:-
- Computer is an electronic machine which can take inputs, process it and produces outputs
- Language of computer is the sequence of zeros and ones
Think, if we people want to communicate with computer, it will be very difficult for us to learn the language of zeros and
ones. Therefore, we need a Translator for communication with computer.
Translator (Software) :- watmytu +
1. Compiler
2. Interpreter
3. Assembler
NOTE:- To work on a computer in a particular language, we need two type of software :-
a) Editor of that particular language for writing source code.
b) Translator of that particular language
Programming Fundamentals
Compiler:- object code / machine code
- As a whole (just like a briefing in press conference)
- Source code converts completely into machine code / machine language / object code
- Execution Fast
- If there exists any error, it will never executes your program
- With object code, program may be executed again and again without translating it each time.
- High level languages first converts into machine code, then executes
- C and C++ use compiler
Interpreter:-
- Step by step / instruction by instruction ( just like translator in meeting )
- Execution slow
- It executes the program until it finds the error in the instruction (stop execution then)
- Each time translation is required for execution
Assembler:-
- Used in Assembly Language
Programming Fundamentals
Program:-
- Set of instructions which solve a user specific problem
Instruction:-
- Statements / Executable expressions
- Statement causes the computer to carry out some action
1. Expression Statements
- Expression followed by a semicolon ; e.g. A =5; or c=a+b ; or x= 5+2 ;

2. Control Statements
- Are used to create special program features such as logical tests / loops etc.
- Other statements may be imbedded in control statements

3. Compound Statements
- Consists of several individual statements enclosed within a pair of braces { } Block of statements
- It may contain expression statements, control statements or compound statements
- Does not end with semicolon after braces
Programming Fundamentals
Expression:-
- Combination of operands and operators
Operands:- ( VARIABLES or CONSTANTS … ?)
- Basic symbols which receive some action. 5 + 3; x+y; 14 / 5.5 ;
Operators:-
- Symbols which can perform some operation. For example + , -, *, / etc 5+ 3
1. Arithmetic Operators
- Unary operators: 1) Unary minus - 2) Postfix a) Increment ++ b) Decrement -- 3) Prefix a) Increment ++ b) Decrement --
- Binary operators: 1) * 2) / 3) % modulus / remainder
- 4) + 5) -
2. Relational Operators / Comparison / true or false
- 1) < 2) <= 3) > 4) >=
- (Equality operators) 5) == 6) !=

3. Logical Operators / logical connectives


- 1) OR !! 2) AND && 3) NOT !

4. Assignment Operators
- 1) = x = 5+9+7 ;
- 2) += 3) -= 4) *= 5) /= 6) %= x += 5 ; x = x+5;
Programming Fundamentals
Rule of Precedence:-
The order of evaluation of operators
- 3 + 4*5 (Answer: ?) 3 + 20 23
- 6 / 10 * 5 (Answer: ?) 15 - 13 / 5 (Answer: ?) 3 + 4 / 5 ( Answer: ?)
- 6 + 4 * 5 *(2+3) (Answer: ?)
- 6 + 4 * 5 / (2+3) + 10 (Answer: ?)
- etc

Associativity:-
The evaluation order of operators having same precedence (either from left to right OR from
right to left)
- 30 / 2 * 3 – 5 + 10 (Answer: ?)
- 10 + 10 * 3 / 3 – 5 (Answer: ?)
- etc
-Prefix, assignment (right to left ?)
Programming Fundamentals
Set of C++ Characters:-
-ABC…Z (A to Z upper case: 26)
- abc … z ( a to z lower case:26)
-012…9 ( 0 to 9 digits :10)
- Special characters (+ - blank spaces … etc : ?)
Note: how many number of C++ characters….? Must visit ( http://aboutc.weebly.com/c-character-set.html )

List of Keywords / Reserved Words in C++ ( 63 )


Operators of C++:-
- all operators symbols…. ? How may in C++
- Symbols which can perform some operation. For example + , -, *, / etc Y+ 3
1. Arithmetic Operators
- Unary operators: 1) Unary minus - 2) Postfix a) Increment ++ b) Decrement -- 3) Prefix a) Increment ++ b) Decrement --
- Binary operators: 1) * 2) / 3) % modulus / remainder
- 4) + 5) -
2. Relational Operators / Comparison / true or false
- 1) < 2) <= 3) > 4) >=
- (Equality operators) 5) == 6) !=

3. Logical Operators / logical connectives


- 1) OR !! 2) AND && 3) NOT !

4. Assignment Operators
- 1) = x = 5+9+7 ;
- 2) += 3) -= 4) *= 5) /= 6) %= x += 5 ; x = x+5;
Programming Fundamentals

Variable:- 5+9; 5+x; x+y;


- Name given to memory location in which we can store a value and that value may change during the program execution.
- One variable ---- One value at a time
- Value of variable may vary as per need of program
- Value can be stored and can be accessed in the program by Referencing Variable Name
- Declaration of the variable is compulsory before use in the program … ? / Declare ?
- Initialization is just recommended … ?
Declaration of the variable syntax :-
- Datatype Identifier;
- For example: int x; x = 5; x + 8; int y; y=10; cout<< x+y ; // 15
Note:- Identifier means Name of the Variable and Datatype determines two things:
1) how many bytes will be reserved on the RAM to form a memory location. A memory location may be comprised of one byte, two bytes or more…
2) which type of value will be stored in this memory location

Initialization of the variable syntax :-


- Datatype Identifier = value;
-For example: int x = 0;
Programming Fundamentals – Variable / Identifier

Rules for Identifier:-


- Identifier means Name of any program element
-for example… variable name, function name, array name, class name, object name, … etc
- always start from alphabet or underscore ( 26 + 26+1 = 53 )
- 0,1,2,3 … 9 ( 10: digits from 0 to 9 OR their combinations may come after alphabet or under score. You cannot start from digit)
- means identifier may be written with only above 63 characters
- Length of identifier depends upon the compiler, anyways first 31 characters are significant.
- Keywords cannot be used as identifiers
  -Identifiers must be meaningful, short, quickly and easily typed and easily read.

Valid identifiers:       total   sum     average          _x        y_        mark_1           x1 x2


Invalid identifiers:   
                                                     1x       -           begins with a digit
                                                    char    -           reserved word
                                                    x+y      -           special character
Note: Underscore character is usually used as a link between two words in long identifiers. St_marks
Must visit: ( http://aboutc.weebly.com/identifiers.html )
Difference between Keyword and Identifier ?
Programming Fundamentals: Constant

Constant:-
-A quantity that cannot change its value during program execution
- Two types of constants in C++ A) Literal Constant B) Symbolic Constant
A) Literal Constant: Literal Constant is a value that is typed directly in a program where it is needed
1) Integer Constants:
i. Numeric values without decimal point / fraction : (… -3, -2, -1, 0, 1, 2, 3…)
ii. Both positive and negative integer constant may be used in the program
iii. negative sign will be used for negative integers and no sign will be used for positive integers (by default value is positive)
iv. For example: 50, 30, -20, -10, 65000L. (L at the end of integer indicates that it is a long integer)
2) Floating Point Constants / Real Constant:
i. Numeric values with decimal point or fraction : ( 234.56, 20.45, 4.5, … -4.5, -20.89, … )
ii. A real constant is combination of a whole number followed by a decimal point and the fractional part. Example: 0.0083,   -0.75,   0.95  etc  
iii. Both positive and negative floating point constants may be used in the program
iv. negative sign will be used for negative floating point and no sign will be used then value is positive by default
v. For example: 10.45 , 56.78, …, 50.89F, 43.12f, …, 34.56L, 88.99L, … (use of F or f at the end, indicates that the value is float. L at the end indicates that the value is long
double. No F or L at the end indicates that the value is double)
vi. The Real or Floating-point constants can be written in two forms: (see next slide)

                    1.      Fractional or Normal form          


                    2.      Exponential or Scientific form
3) Character Constants: Single character enclosed in single quotation marks / inverted commas
1) For example: ‘a’ , ‘b’, … ‘A’, ‘B’, …, ‘1’, ‘2’, ‘3’, …, ‘+’, ‘*’, … etc
2) All alphabetic characters, digits and special characters may used as character constants
4) String Constants / String: Sequence of characters enclosed in double quotation marks
1) May be combinations of alphabets, digits or special characters enclosed in double quotation marks
2) For example: “Naveed”, “ABC123”, “XYZ ABC + 567”, “123”, “Hello World” … etc
Programming Fundamentals: Constant / Real Constant:
• The Real or Floating-point constants can be written in two forms: 1) Fractional or Normal form     2)Exponential or Scientific form

1) Express a Real constant in fractional form:


                    A real constant consists for a series of digits representing the whole part of the number, followed by a decimal point, followed by a series of representing the fractional
part. The whole part or the fractional part can be omitted, but both cannot be omitted. The decimal cannot be omitted. That is, it is possible that the number may not have digits
before the decimal point or after the decimal point.         
Valid Real constants (Fractional): 0.0      -0.1     +123.456       .2         2. / Invalid Real constant: -   10, 5, 100 ( a decimal point is missing)
                                                        
Rules for Constructing Real Constants in Fractional Form
1.    A real constant must have at least one digit.
2.    It must have a decimal point.
3.    It could be either positive or negative.
4.    Default sign is positive.
5.    Commas or blanks are not allowed within a real constant.

• 2) Express a real constant in Exponential form


                    A real constant is combination of a whole number followed by a decimal point and the fractional part. If the value of a constant is either too small or too large,
exponential form of representation of real constants is usually used.

In exponential form, the real constant is represented in two parts.


 Mantissa       -           The part appearing before e, the mantissa is either a real number expressed in decimal notation or an integer.
 Exponent      -           The part following e, the exponent is an integer with an optional plus or minus sign followed by a series of digits. The letter e separating the mantissa and the
exponent can be written in either lowercase or uppercase.
 Example:         0.000342 can be represented in exponential form as 3.42e-4 and 7500000000 can be represented in exponential form as 7.5e9 or 75E8

Rules for Constructing Real Constants in Exponential Form

1.      The mantissa part and the exponential part should be separated by letter in exponential form
2.      The mantissa part may have a positive or negative sign.
3.      Default sign of mantissa part is positive.
4.      The exponent part must have at least one digit, which must be a positive or negative integer. Default sign is positive.
5.      Range of real constants expressed in exponential for is -3.4e38 to 3.4e38.
Programming Fundamentals : Constant /Symbolic Constant

B) Symbolic Constant:
-A symbolic constant is a NAME given to a value that cannot be changed
-It must be initialized. After initialization, its vale cannot be changed
-Symbolic constant is used to represent a value that is frequently used in a program
-Symbolic constants can be declared in two ways:
1) const Qualifier
1) “const” qualifier is used to define a constant
2) The constant is declared by specifying its name and data type
3) The constant must be initialized with some value
4) The initialized value cannot be changed during program execution
5) Syntax: const data_type Identifier = value ;
• const ketword used to define the constant
• data_type indicates the data type of the constant
• Identifier represent the name of constant
• = assignment operator
• Value represent the value with which constant has been initialized
• Example: const int X = 555; // defines a constant X that is initialized with a value (555) and this value (555) cannot be changed during program execution.
2) define Directive:
1) “define” directive is also used to define a constant
2) Difference between const qualifier and define directive is that define directive does not specify the data type of the constant.
3) “define” directive starts with #
4) It is not terminated with semicolon
5) Syntax: #define Identifier value
• # indicates the start of preprocessor directives
• defineused to define a constant
• Identifier name of the constant
• value represent the value associated with identifier
• Example: #define PI 3.141593 // the preprocessor directive will replace all the occurrences of the identifier with the value in the program
Programming Fundamentals: Constant

Data type:-
-Data type are used for declaring variables or functions of different type
- Data type determines that:-
1) how much space a variable occupies in RAM ( means that how many bytes will be reserved in RAM to form a memory location / a
memory location may be comprised of one or more bytes in RAM). Every data type requires a different amount of memory.
2) which type of value will be stored in this memory location

Basic or Primitive Data types in C++:


3) Integer Types:
i. char…. Memory Space:- 1 byte … Range :- -128 to 127
ii. int or short … Memory Space:- 2 bytes … Range:--32768 to 32767
iii. long … Memory Space:- 4 bytes … Range:-- 2147483648 to 2147483647
4) Floating Point Types:
i. float…. Memory Space:- 4 byte … Range :- 3.4 x 10-38 to 3.4 x 10+38 Precision :- 6 decimal places
ii. double… Memory Space:- 8 bytes … Range:- 1.7 x 10-308 to 3.4 x 10+308 Precision :- 15 decimal places
iii. long double Memory Space:- 10 bytes … Range:- 1.7 x 10-4932 to 3.4 x 10+4932 Precision :- 19 decimal places
5) void: Memory Space:- 0 byte …
1) Pointers are declared as void
2) Functions may also be declared as void, which has no return type.
Basic Data type in C++
• In C++, data types are declarations for variables. This determines the
type and size of data associated with variables.
• For example:-
• int age = 13;
• Here, age is a variable of type int. Meaning, the variable can only store integers of either 2
or 4 bytes.
• All variables use data-type during declaration to restrict the type of
data to be stored. Therefore, we can say that data types are used to
tell the variables the type of data it can store. Whenever a variable is
defined in C++, the compiler allocates some memory for that variable
based on the data-type with which it is declared. Every data type
requires a different amount of memory.

You might also like