DFC20113 - Chapter 1 (Introduction To Fundamentals of Programming)
DFC20113 - Chapter 1 (Introduction To Fundamentals of Programming)
CHAPTER 1
INTRODUCTION TO FUNDAMENTALS
OF PROGRAMMING
CLO 2:
SHOW SIMPLE PROGRAMS BY DEVELOPING CODE TO SOLVE PROBLEMS IN
A COMPUTER USING C++ PROGRAMMING LANGUAGE.
( P2, PLO 3 )
LEARNING OUTCOMES
1.1 Define the C++ program basic structure
Describe the item in C++ program structure
- Comments
- Preprocessor directives
- Header files
- main() function
- return statements.
Describe two types of comments that supported by C++
program
Explain coding standard best practices
TOPIC 1.1
Probably the best way to start learning a programming
language is by writing a program.
Therefore, here is our first program:
a) Comment Style
TOPIC 1.1
Entries in the source code which are ignored by the compiler
C++ support 2 style/form of comments:
//Single Line Comments
- for simple 'side' notes
- best places to put these comments are next to variable
declarations, and next to pieces of code that may need
explanation.
02 05
- floating point numbers - single character
adipiscing elit, sed do
- 8 bytes -1 byte
eiusmod
float
01 06
bool
- floating point numbers - boolean value (true/false)
- 4 bytes - 1 byte
CHARACTER
• Equivalent to ‘letters’ in English language
• Example of characters:
- Numeric digits: 0 - 9
- Lowercase/uppercase letters: a - z and A - Z
- Space (blank)
- Special characters: , . ; ? “ / ( ) [ ] { } * & % ^ < > etc.
• Single character
• Keyword: char
• Sample values:
‘B’ ‘d’ ‘4’ ‘?’ ‘*’
INTEGER
• used to declare numeric program variables of integer type
• whole numbers, positive and negative
• keyword: int
• Example code :
• Sample values:
4578 -4578 0
DOUBLE
• used to declare floating point variable of higher precision or
higher range of numbers
• exponential numbers, positive and negative
• keyword: double
• Example code :
• Sample values:
45.000500 5.9999999 0.550
FLOAT
• Fractional parts, positive and negative
• Real numbers with a decimal point
• Keyword: float
• Example code:
• Sample values
95.274 95.5 2.265
FLOAT
The bool data type is capable of holding a Boolean
value.
Objects of type bool may have only the values true or
false.
Keyword: bool
Example code:
STRING
A string is a sequence of characters enclosed in double
quotes (" ").
String sample values:
“Hello” “Year 2000” “1234”
The empty string (null string) contains no characters
and is written as “ ” .
Keyword: string
Example code:
string name = “Ahmad Albab”;
CODE PROGRAM
CODE PROGRAM
TOPIC 1.3
•IDENTIFY THE BASIC OF COMPUTER PROGRAM
Portability
It is the concept of carrying the instruction from one system to another
system. In C++ Language .cpp file contain source code, we can edit also
this code. .exe file contain application, only we can execute this file. When
we write and compile any C++ program on window operating system that
program easily run on other window based system.
Powerful
C++ is a very powerful programming language, it have a wide verity of
data types, functions, control statements, decision making statements,
etc.
Platform dependent
A language is said to be platform dependent whenever the program is
execute in the same operating system where that was developed and
compiled but not run and execute on other operating system. C++ is
platform dependent language.
Object oriented
This main advantage of C++ is, it is object oriented programming
language. It follow concept of oops like polymorphism, inheritance,
encapsulation, abstraction.
Case sensitive
C++ is a case sensitive programming language. In C++ programming
'break and BREAK' both are different.
Compiler based
C++ is a compiler based programming language that means without
compilation no C++ program can be executed. First we need compiler to
compile our program and then execute.
Use of Pointers
Pointers is a variable which hold the address of another variable, pointer
directly direct access to memory address of any variable due to this
performance of application is improve.
•INTEGRATED DEVELOPMENT ENVIRONMENT
An integrated development environment (IDE) is a software application that
provides comprehensive facilities to computer programmers for software
development.
Example:
a. Misspelled variable and function names.
b. Missing semicolons (;)
c. Improperly matches parentheses, square brackets[ ],
and curly braces{ }
d. Incorrect format in selection and loop statements
RUN TIME ERRORS
Occur when a program with no syntax errors asks the
computer to do something that the computer is unable to
reliably do.
Example:
a. Trying to divide by a variable that contains a value of zero
b. Trying to open a file that doesn't exist
c. There is no way for the compiler to know about these kinds
of errors when the program is compiled.
LOGICAL ERRORS
Logic errors occur when there is a design flaw in your
program.
Example:
a. Multiplying when you should be dividing
b. Adding when you should be subtracting
c. Opening and using data from the wrong file
d. Displaying the wrong message
•SPECIAL CHARACTERS
•DEBUGGING PROCESS
Debugging is the process of locating and fixing or by passing
bugs (errors) in computer program code or the engineering of a
hardware device. Debugging is a generalized term which essentially
means to step through a process in order to systematically
eliminate errors.