SlideShare a Scribd company logo
1 of 47
TOPIC 1 :
INTRODUCTION TO FUNDAMENTALS OF
PROGRAMMING
DFC20113
AT THE END OF THE LESSON, STUDENTS SHOULD BE ABLE TO
:
1.1 Define the C++ program basic
structure
1.2 Explain identifier and data types
1.1 DEFINE THE C++ PROGRAM BASIC
STRUCTURE
1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE
// my first program in C++
#include <iostream>
using namespace std;
int main ()
{
cout << "Hello World!“<<endl;
return 0;
}
comment
Preprocessor
Directives
Main function
braces
output
Return statement
Header file
1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE
a. comments
Program comments are explanatory statements that you can include in the C++ code. These
comments help anyone reading the source code. All programming languages allow for some
form of comments.
C++ supports single-line and multi-line comments. All characters available inside any
comment are ignored by C++ compiler.
1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE
#include < Filename.h >
#include tells the computer to copy, or include the given file name into
C++ program. #include tells the preprocessor to dump in the contents
of another file, here the iostream file, which defines the procedures
for input/output.
< Filename.h> is called an include file or header file.
< > symbol use to tell computer to looks in the primary system default
directory and not the current working directory.
DO NOT terminate a preprocessor directive with a semicolon.
#include <filename.h> ; Wrong!
b. preprocessor directives
1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE
.h files or "headers" are libraries of code you may insert in your program by including
them by reference in the top block.
The point of header files is to create libraries of code that can be used over and over
#include< stdio.h > is the Standard Input and Output header file. Expl : printf, scanf.
#include< iostream.h > is the Input and Output Stream header file. Expl : cout, cin.
Class declaration from the executable code of the associated methods or function,
because we need the definitions and declaration to be known in a variety of places
through a large program. Example of common standard header file:
<stdio>
<fstream>
<iostream>
c. header files
<list>
<map>
<stack>
<math>
<numeric>
<functional>
1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE
Types of Header Files :
i. iostream.h -Input/Output, interaction with the program. Expl : getline.
ii. math.h –For using mathematic formula
iii. string.h- C++ has no built-in string handling. Use this library to copy strings, find string
length, etc.
iv. stdio.h- Similar to stdlib but also has some file functions. printf, scanf(for C language)
c. header files
1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE
d. main() function
int main()
{
return 0;
}
void main()
{
}
Is the place where the code execution begins.
C++ program is simply a collection of function blocks.
void main() {...}
- defines the code that should execute first when the program starts up.
- The curly braces represent grouping of multiple commands into a block.
1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE
d. main() function
void is a keyword, follow by the function’s name, and then all C++ program is written
within this open and closing curly brace { }.
void main ( ) {…}
// void mean that the function named main do not return a value.
void function2 ( ) {…}
// the function named function2 do not return a value.
1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE
e. return statements
The return statements will stop the execution and returns to the calling
function.
Return optional in void functions
Return required in non-void functions
1.1.2 DESCRIBE TWO TYPES OF COMMENTS THAT SUPPORTED BY
C++ PROGRAM
There are 2 types
of comment
// Double Forward Slash
//This program is for lab1
Computer will ignore
anything you write after
the double forward slash
but for one line comment
only.
/*Multiline
Comment*/
/*This program is for
you to understand
how to write multiline
comments
using multiline
comment symbol */
1.1.2 DESCRIBE TWO TYPES OF COMMENTS THAT SUPPORTED BY
C++ PROGRAM
C++ comments start with /* and end with */. For example −
1.1.2 DESCRIBE TWO TYPES OF COMMENTS THAT SUPPORTED BY
C++ PROGRAM
A comment can also start with //, extending to the end of the line. For example −
1.1.2 DESCRIBE TWO TYPES OF COMMENTS THAT SUPPORTED BY
C++ PROGRAM
A comment can also start with //, extending to the end of the line. For example −
When the above code is compiled, it will ignore // prints Hello World and final executable will produce
the following result −
1.1.2 DESCRIBE TWO TYPES OF COMMENTS THAT SUPPORTED BY
C++ PROGRAM
Within a /* and */ comment, // characters have no special meaning. Within a // comment, /* and */ have no
special meaning. Thus, you can "nest" one kind of comment within the other kind. For example −
1.1.3 EXPLAIN CODING STANDARDS BEST PRACTICES.
Definition and Purpose of coding standards and best practices
Coding best practices are a set of informal rules that the software development community has
learned over time which can help improve the quality of software.
To develop reliable and maintainable applications, you must follow coding standards and best
practices.
There are several standards exists in the programming industry. None of them are wrong or
bad and you may follow any of them. What is more important is, selecting one standard
approach and ensuring that everyone is following it.
1.1.3 EXPLAIN CODING STANDARDS BEST PRACTICES.
How to follow the standards across the team
If you have a team of different skills and tastes, you are going to have a tough time convincing everyone to follow the
same standards. The best approach is to have a team meeting and developing your own standards document. You may
use this document as a template to prepare your own document.
Distribute a copy of this document (or your own coding standard document) well ahead of the coding standards meeting.
All members should come to the meeting prepared to discuss pros and cons of the various points in the document. Make
sure you have a manager present in the meeting to resolve conflicts.
Discuss all points in the document. Everyone may have a different opinion about each point, but at the end of the
discussion, all members must agree upon the standard you are going to follow. Prepare a new standards document with
appropriate changes based on the suggestions from all of the team members. Print copies of it and post it in all
workstations.
After you start the development, you must schedule code review meetings to ensure that everyone is following the rules. 3
types of code reviews are recommended: Peer review, Architect review and Group review
1.1.3 EXPLAIN CODING STANDARDS BEST PRACTICES.
Best Practices for Writing Super Readable Code
Commenting &
Documentation
Consistent Indentation
Avoid Obvious Comments
Code Grouping
Consistent Naming Scheme
Avoid Deep Nesting
Limit Line Length
File and Folder Organization
1.2 EXPLAIN IDENTIFIER AND DATA
TYPES
1.2.1 EXPLAIN IDENTIFIER, VARIABLE AND CONSTANT.
Identifiers refers to the name of variables, functions, arrays, classes, etc. created by the user. Identifiers
are the fundamental requirement of any language.
A variable is a meaningful name of data storage location in computer memory. When using a variable you
refer to memory address of computer.
Constants refers to fixed values that do not change during the execution of a program.
1.2.2 STATE THE RULES FOR NAMING AN IDENTIFIER.
Naming conventions rules for Identifier
i. Only alphabetic characters, digits and underscores are permitted.
Ex: sum_of_squares, box_22A, GetData
i. First letter must be an alphabet or underscore (_).
Ex: box_22A, _GetData
iii. Identifiers are case sensitive.
Ex: box, BOX, Box
iv. Reserved keywords cannot be used as an identifier's name. Reserved words or keywords are identifiers
reserved for system use.
Ex: local, private, int
v. The blank space cannot be used.
Ex: Get Data - cannot be an identifier as blanks are not allowed in identifiers
vi. Avoid excessively long identifiers.
1.2.2 STATE THE RULES FOR NAMING AN IDENTIFIER.
vii. You can develop your own conventions like below:
A single word identifier will be written in lower case only.
Ex: grade, number, sum.
If an identifier is made up of several words, the first letter will be lower case. Subsequent words will begin
with upper case.
Some examples are: stringType, passingScore, largestNum.
Identifiers used as constants are often fully capitalized.
Ex: PI, MAXSTRLEN.
1.2.3 NAME THE VARIABLES ACCORDING THE STANDARDS.
We know that in C, all variables must be declared before they are used, this is true with C++.
The main difference in C and C++ with regards to the place of their declaration in the program.
C requires all the variables to be defined in the beginning of scope.
C++ allows the declaration of a variable anywhere in the scope, this means that a variable can
be declared right at the place of its first use.
How to declare variable?
1.2.3 NAME THE VARIABLES ACCORDING THE STANDARDS.
How to declare variable?
When you ask user to input a data, you need to save the data into a
memory location inside computer. To do so, you need to Define the
variable, a variable is a named location in memory.
i) Give the computer the name or address of a memory location where
the data to be save.
ii) Tell the computer, the data type you want to save.
After you define a variable, computer will reserves a location inside
the computer memory for the variable value.
1.2.3 NAME THE VARIABLES ACCORDING THE STANDARDS.
Before you can
use a variable in
C++, it must be
defined.
When you defined a
variable, the compiler
reserves a location
inside the computer
memory for the
variable value.
You can define a
variable anyplace
within a program
as long as it is
defined before it is
used.
How to declare variable?
1.2.3 NAME THE VARIABLES ACCORDING THE STANDARDS.
Abu ! = abu
charA9 ; //Correct
char 9A; //Incorrect
char_ali ; //Correct
char_9A; //Correct
char Nama1; //Correct
char Nama 1; //Incorrect
char Nama1! ;//Incorrect
Length is depend on the type of compiler.
Difference compiler may have different
rules. As an example, Microsoft VC++
allowed until 32 character long for the
identifier Name.
Case-sensitive
start with a Letter
or Underscore
No spaces or
punctuation
Cannot use
KEYWORD
Length
char public; //InCorrect
char void1; //Incorrect
char main! ;//Incorrect
Rules of Naming Variables
1.2.4 EXPLAIN THE DATA TYPES.
While writing program in any language, you need to use various variables to store various information.
Variables are nothing but reserved memory locations to store values. This means that when you create a
variable you reserve some space in memory.
You may like to store information of various data types like character, wide character, integer, floating point,
double floating point, boolean etc. Based on the data type of a variable, the operating system allocates
memory and decides what can be stored in the reserved memory.
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
byte is the minimum amount
of memory that we can
manage in C++.
1 byte = 8 bit
the computer has to know
what kind of data we want to
store in them
Things to be consider ??
defines which kind of data will store in variables and also defines memory storage of data
.
Data type concept
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
A byte can store a relatively small amount of data.
One single character or a small integer (generally an integer between
0 and 255).
The computer can manipulate more complex data types
By forming grouping of several bytes
e.g; long numbers or non-integer numbers.
.
Data type constraints
Why ?
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
Data type size in byte
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
Data type range
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
Data type size & range Name Description Size* Range*
char Character or small integer. 1byte signed: -128 to 127
unsigned: 0 to 255
short int
(short)
Short Integer 2bytes signed: -32768 to 32767
unsigned: 0 to 65535
int Integer 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
long int
(long)
Long integer 4bytes signed: -2147483648 to 2147483647
unsigned: 0 to 4294967295
bool Boolean value. It can take one of
two values: true or false.
1byte true or false
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
double Double precision floating point
number.
8bytes +/- 1.7e +/- 308 (~15 digits)
long double Long double precision floating
point number.
8bytes +/- 1.7e +/- 308 (~15 digits)
wchar_t Wide character. 2 or 4
bytes
1 wide character
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
Integer
Floating
point
Character
Boolean
String
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
a. Integer
int is used to declare integers, whole numbers either positive, negative or 0.
Examples :1, 4, 67, 89, 98, 344, 2777, 0, - 3, -89, -999
The following statement shows how the variables of int type are declared.
Examples :
int var1;
int b = 10;
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
a. Integer
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
b. Floating point
Floating point include all of the whole number that must be represented using decimal point/decimal
places.
Example 1 : 3.14, 2.90, 0.0, -8.98, -99.7
Example 2 :
13200 = 1.32 x 104 = 1.32e4
0.00000045 = 0.45 x 10-6 = 1.45e-6
-13330000 = -1.333 x 10-7 = -1.333e7
This keyword float and double is used to declare floating point decimal numbers. A sample declaration would
be:
float var2; //Sample declaration for float
double var2 = 18.52;
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
b. Floating point
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
c. Character
All of the symbols on your keyboard are character. Includes lowercase or uppercase A to z, punctuation,
numbers and special symbols.
Example 1 : a, A, h, H, z, Z, &, !, 2, 3, <,+.@, #
This keyword is used to declare characters. The characters that can be used with this data type are ASCII
characters.
char a[9]=“Malaysia”;
char a[]=“Malaysia”;
char noPhone[11]=“0134022331”;
Character VS String
Character = ‘a’, ‘d’, ‘D’. Using single quote ‘
String = “ Hello”, “Abu?”. Using double quotes “
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
c. Character
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
d. Boolean
The result of a comparison or a logical association using AND or
OR is a boolean value, which can be true or false.
C++ uses the bool type to represent boolean values.
An expression of the type bool can either be true or false,
where the internal value for true will be represented as the
numerical value 1 and false by a zero.
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
d. Boolean
To declare a boolean variable, we use the keyword bool.
bool bValue;
When assigning values to boolean variables, we use the keywords true and false.
bool bValue1 = true;
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
e. String
A string is a series of characters treated as a single unit.
A string may include letters, digits and various special characters such as +, -, *, / and $.
String literals, or string constants, in C++ are written in double quotation marks.
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
e. String  Must include header file string.h
#include <iostream.h>
#include <string.h>
Int main()
{
……
…..
string mystring = "This is a string";
……
return 0;
}
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
Example :
15.25F - float
1000.5L - Long double
25000L - Long integer
25 - integer
Data Type ?
Data Type ?
Data Type ?
Data Type ?
Did you know that
long,short,signed and
unsigned are called qualifier
purpose of qualifier :
to manipulate the range of a
particular data type or its size
size qualifiers :
long and short
sign qualifiers :
signed and unsigned
1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH
EXAMPLES
Things to ponder :
Integer data type :
int is normally 2 bytes
with range of 0 to 255
What will happen if ?
1. you declare it as long int
2. you declare it as short int
3. you declare it as unsigned int
1. size will increase to 4 bytes
2. size will reduce to 1 byte
3. range increase from 0 to 65535

More Related Content

Similar to Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptx

Similar to Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptx (20)

POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Bcsl 031 solve assignment
Bcsl 031 solve assignmentBcsl 031 solve assignment
Bcsl 031 solve assignment
 
Presentation c++
Presentation c++Presentation c++
Presentation c++
 
Unit-2.pptx
Unit-2.pptxUnit-2.pptx
Unit-2.pptx
 
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTTC programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
C programming notes BATRACOMPUTER CENTRE IN Ambala CANTT
 
Cp week _2.
Cp week _2.Cp week _2.
Cp week _2.
 
Prog1-L1.pdf
Prog1-L1.pdfProg1-L1.pdf
Prog1-L1.pdf
 
C Language
C LanguageC Language
C Language
 
The smartpath information systems c pro
The smartpath information systems c proThe smartpath information systems c pro
The smartpath information systems c pro
 
Unit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptxUnit-1 (introduction to c language).pptx
Unit-1 (introduction to c language).pptx
 
C Programming UNIT 1.pptx
C Programming  UNIT 1.pptxC Programming  UNIT 1.pptx
C Programming UNIT 1.pptx
 
Lecture 01 2017
Lecture 01 2017Lecture 01 2017
Lecture 01 2017
 
C programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdfC programming language tutorial for beginers.pdf
C programming language tutorial for beginers.pdf
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Learning the C Language
Learning the C LanguageLearning the C Language
Learning the C Language
 
unit2.pptx
unit2.pptxunit2.pptx
unit2.pptx
 
NamingConvention
NamingConventionNamingConvention
NamingConvention
 
CS8251_QB_answers.pdf
CS8251_QB_answers.pdfCS8251_QB_answers.pdf
CS8251_QB_answers.pdf
 
Unit 2 introduction to c programming
Unit 2   introduction to c programmingUnit 2   introduction to c programming
Unit 2 introduction to c programming
 
Aniket tore
Aniket toreAniket tore
Aniket tore
 

Recently uploaded

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 

Recently uploaded (20)

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 

Chapter vvxxxxxxxxxxx1 - Part 1 (3).pptx

  • 1. TOPIC 1 : INTRODUCTION TO FUNDAMENTALS OF PROGRAMMING DFC20113
  • 2. AT THE END OF THE LESSON, STUDENTS SHOULD BE ABLE TO : 1.1 Define the C++ program basic structure 1.2 Explain identifier and data types
  • 3. 1.1 DEFINE THE C++ PROGRAM BASIC STRUCTURE
  • 4. 1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE // my first program in C++ #include <iostream> using namespace std; int main () { cout << "Hello World!“<<endl; return 0; } comment Preprocessor Directives Main function braces output Return statement Header file
  • 5. 1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE a. comments Program comments are explanatory statements that you can include in the C++ code. These comments help anyone reading the source code. All programming languages allow for some form of comments. C++ supports single-line and multi-line comments. All characters available inside any comment are ignored by C++ compiler.
  • 6. 1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE #include < Filename.h > #include tells the computer to copy, or include the given file name into C++ program. #include tells the preprocessor to dump in the contents of another file, here the iostream file, which defines the procedures for input/output. < Filename.h> is called an include file or header file. < > symbol use to tell computer to looks in the primary system default directory and not the current working directory. DO NOT terminate a preprocessor directive with a semicolon. #include <filename.h> ; Wrong! b. preprocessor directives
  • 7. 1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE .h files or "headers" are libraries of code you may insert in your program by including them by reference in the top block. The point of header files is to create libraries of code that can be used over and over #include< stdio.h > is the Standard Input and Output header file. Expl : printf, scanf. #include< iostream.h > is the Input and Output Stream header file. Expl : cout, cin. Class declaration from the executable code of the associated methods or function, because we need the definitions and declaration to be known in a variety of places through a large program. Example of common standard header file: <stdio> <fstream> <iostream> c. header files <list> <map> <stack> <math> <numeric> <functional>
  • 8. 1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE Types of Header Files : i. iostream.h -Input/Output, interaction with the program. Expl : getline. ii. math.h –For using mathematic formula iii. string.h- C++ has no built-in string handling. Use this library to copy strings, find string length, etc. iv. stdio.h- Similar to stdlib but also has some file functions. printf, scanf(for C language) c. header files
  • 9. 1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE d. main() function int main() { return 0; } void main() { } Is the place where the code execution begins. C++ program is simply a collection of function blocks. void main() {...} - defines the code that should execute first when the program starts up. - The curly braces represent grouping of multiple commands into a block.
  • 10. 1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE d. main() function void is a keyword, follow by the function’s name, and then all C++ program is written within this open and closing curly brace { }. void main ( ) {…} // void mean that the function named main do not return a value. void function2 ( ) {…} // the function named function2 do not return a value.
  • 11. 1.1.1 DESCRIBE THE ITEM IN C++ PROGRAM STRUCTURE e. return statements The return statements will stop the execution and returns to the calling function. Return optional in void functions Return required in non-void functions
  • 12. 1.1.2 DESCRIBE TWO TYPES OF COMMENTS THAT SUPPORTED BY C++ PROGRAM There are 2 types of comment // Double Forward Slash //This program is for lab1 Computer will ignore anything you write after the double forward slash but for one line comment only. /*Multiline Comment*/ /*This program is for you to understand how to write multiline comments using multiline comment symbol */
  • 13. 1.1.2 DESCRIBE TWO TYPES OF COMMENTS THAT SUPPORTED BY C++ PROGRAM C++ comments start with /* and end with */. For example −
  • 14. 1.1.2 DESCRIBE TWO TYPES OF COMMENTS THAT SUPPORTED BY C++ PROGRAM A comment can also start with //, extending to the end of the line. For example −
  • 15. 1.1.2 DESCRIBE TWO TYPES OF COMMENTS THAT SUPPORTED BY C++ PROGRAM A comment can also start with //, extending to the end of the line. For example − When the above code is compiled, it will ignore // prints Hello World and final executable will produce the following result −
  • 16. 1.1.2 DESCRIBE TWO TYPES OF COMMENTS THAT SUPPORTED BY C++ PROGRAM Within a /* and */ comment, // characters have no special meaning. Within a // comment, /* and */ have no special meaning. Thus, you can "nest" one kind of comment within the other kind. For example −
  • 17. 1.1.3 EXPLAIN CODING STANDARDS BEST PRACTICES. Definition and Purpose of coding standards and best practices Coding best practices are a set of informal rules that the software development community has learned over time which can help improve the quality of software. To develop reliable and maintainable applications, you must follow coding standards and best practices. There are several standards exists in the programming industry. None of them are wrong or bad and you may follow any of them. What is more important is, selecting one standard approach and ensuring that everyone is following it.
  • 18. 1.1.3 EXPLAIN CODING STANDARDS BEST PRACTICES. How to follow the standards across the team If you have a team of different skills and tastes, you are going to have a tough time convincing everyone to follow the same standards. The best approach is to have a team meeting and developing your own standards document. You may use this document as a template to prepare your own document. Distribute a copy of this document (or your own coding standard document) well ahead of the coding standards meeting. All members should come to the meeting prepared to discuss pros and cons of the various points in the document. Make sure you have a manager present in the meeting to resolve conflicts. Discuss all points in the document. Everyone may have a different opinion about each point, but at the end of the discussion, all members must agree upon the standard you are going to follow. Prepare a new standards document with appropriate changes based on the suggestions from all of the team members. Print copies of it and post it in all workstations. After you start the development, you must schedule code review meetings to ensure that everyone is following the rules. 3 types of code reviews are recommended: Peer review, Architect review and Group review
  • 19. 1.1.3 EXPLAIN CODING STANDARDS BEST PRACTICES. Best Practices for Writing Super Readable Code Commenting & Documentation Consistent Indentation Avoid Obvious Comments Code Grouping Consistent Naming Scheme Avoid Deep Nesting Limit Line Length File and Folder Organization
  • 20. 1.2 EXPLAIN IDENTIFIER AND DATA TYPES
  • 21. 1.2.1 EXPLAIN IDENTIFIER, VARIABLE AND CONSTANT. Identifiers refers to the name of variables, functions, arrays, classes, etc. created by the user. Identifiers are the fundamental requirement of any language. A variable is a meaningful name of data storage location in computer memory. When using a variable you refer to memory address of computer. Constants refers to fixed values that do not change during the execution of a program.
  • 22. 1.2.2 STATE THE RULES FOR NAMING AN IDENTIFIER. Naming conventions rules for Identifier i. Only alphabetic characters, digits and underscores are permitted. Ex: sum_of_squares, box_22A, GetData i. First letter must be an alphabet or underscore (_). Ex: box_22A, _GetData iii. Identifiers are case sensitive. Ex: box, BOX, Box iv. Reserved keywords cannot be used as an identifier's name. Reserved words or keywords are identifiers reserved for system use. Ex: local, private, int v. The blank space cannot be used. Ex: Get Data - cannot be an identifier as blanks are not allowed in identifiers vi. Avoid excessively long identifiers.
  • 23. 1.2.2 STATE THE RULES FOR NAMING AN IDENTIFIER. vii. You can develop your own conventions like below: A single word identifier will be written in lower case only. Ex: grade, number, sum. If an identifier is made up of several words, the first letter will be lower case. Subsequent words will begin with upper case. Some examples are: stringType, passingScore, largestNum. Identifiers used as constants are often fully capitalized. Ex: PI, MAXSTRLEN.
  • 24. 1.2.3 NAME THE VARIABLES ACCORDING THE STANDARDS. We know that in C, all variables must be declared before they are used, this is true with C++. The main difference in C and C++ with regards to the place of their declaration in the program. C requires all the variables to be defined in the beginning of scope. C++ allows the declaration of a variable anywhere in the scope, this means that a variable can be declared right at the place of its first use. How to declare variable?
  • 25. 1.2.3 NAME THE VARIABLES ACCORDING THE STANDARDS. How to declare variable? When you ask user to input a data, you need to save the data into a memory location inside computer. To do so, you need to Define the variable, a variable is a named location in memory. i) Give the computer the name or address of a memory location where the data to be save. ii) Tell the computer, the data type you want to save. After you define a variable, computer will reserves a location inside the computer memory for the variable value.
  • 26. 1.2.3 NAME THE VARIABLES ACCORDING THE STANDARDS. Before you can use a variable in C++, it must be defined. When you defined a variable, the compiler reserves a location inside the computer memory for the variable value. You can define a variable anyplace within a program as long as it is defined before it is used. How to declare variable?
  • 27. 1.2.3 NAME THE VARIABLES ACCORDING THE STANDARDS. Abu ! = abu charA9 ; //Correct char 9A; //Incorrect char_ali ; //Correct char_9A; //Correct char Nama1; //Correct char Nama 1; //Incorrect char Nama1! ;//Incorrect Length is depend on the type of compiler. Difference compiler may have different rules. As an example, Microsoft VC++ allowed until 32 character long for the identifier Name. Case-sensitive start with a Letter or Underscore No spaces or punctuation Cannot use KEYWORD Length char public; //InCorrect char void1; //Incorrect char main! ;//Incorrect Rules of Naming Variables
  • 28. 1.2.4 EXPLAIN THE DATA TYPES. While writing program in any language, you need to use various variables to store various information. Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. You may like to store information of various data types like character, wide character, integer, floating point, double floating point, boolean etc. Based on the data type of a variable, the operating system allocates memory and decides what can be stored in the reserved memory.
  • 29. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES
  • 30. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES byte is the minimum amount of memory that we can manage in C++. 1 byte = 8 bit the computer has to know what kind of data we want to store in them Things to be consider ?? defines which kind of data will store in variables and also defines memory storage of data . Data type concept
  • 31. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES A byte can store a relatively small amount of data. One single character or a small integer (generally an integer between 0 and 255). The computer can manipulate more complex data types By forming grouping of several bytes e.g; long numbers or non-integer numbers. . Data type constraints Why ?
  • 32. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES Data type size in byte
  • 33. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES Data type range
  • 34. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES Data type size & range Name Description Size* Range* char Character or small integer. 1byte signed: -128 to 127 unsigned: 0 to 255 short int (short) Short Integer 2bytes signed: -32768 to 32767 unsigned: 0 to 65535 int Integer 4bytes signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 long int (long) Long integer 4bytes signed: -2147483648 to 2147483647 unsigned: 0 to 4294967295 bool Boolean value. It can take one of two values: true or false. 1byte true or false float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits) double Double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits) long double Long double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits) wchar_t Wide character. 2 or 4 bytes 1 wide character
  • 35. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES Integer Floating point Character Boolean String
  • 36. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES a. Integer int is used to declare integers, whole numbers either positive, negative or 0. Examples :1, 4, 67, 89, 98, 344, 2777, 0, - 3, -89, -999 The following statement shows how the variables of int type are declared. Examples : int var1; int b = 10;
  • 37. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES a. Integer
  • 38. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES b. Floating point Floating point include all of the whole number that must be represented using decimal point/decimal places. Example 1 : 3.14, 2.90, 0.0, -8.98, -99.7 Example 2 : 13200 = 1.32 x 104 = 1.32e4 0.00000045 = 0.45 x 10-6 = 1.45e-6 -13330000 = -1.333 x 10-7 = -1.333e7 This keyword float and double is used to declare floating point decimal numbers. A sample declaration would be: float var2; //Sample declaration for float double var2 = 18.52;
  • 39. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES b. Floating point
  • 40. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES c. Character All of the symbols on your keyboard are character. Includes lowercase or uppercase A to z, punctuation, numbers and special symbols. Example 1 : a, A, h, H, z, Z, &, !, 2, 3, <,+.@, # This keyword is used to declare characters. The characters that can be used with this data type are ASCII characters. char a[9]=“Malaysia”; char a[]=“Malaysia”; char noPhone[11]=“0134022331”; Character VS String Character = ‘a’, ‘d’, ‘D’. Using single quote ‘ String = “ Hello”, “Abu?”. Using double quotes “
  • 41. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES c. Character
  • 42. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES d. Boolean The result of a comparison or a logical association using AND or OR is a boolean value, which can be true or false. C++ uses the bool type to represent boolean values. An expression of the type bool can either be true or false, where the internal value for true will be represented as the numerical value 1 and false by a zero.
  • 43. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES d. Boolean To declare a boolean variable, we use the keyword bool. bool bValue; When assigning values to boolean variables, we use the keywords true and false. bool bValue1 = true;
  • 44. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES e. String A string is a series of characters treated as a single unit. A string may include letters, digits and various special characters such as +, -, *, / and $. String literals, or string constants, in C++ are written in double quotation marks.
  • 45. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES e. String  Must include header file string.h #include <iostream.h> #include <string.h> Int main() { …… ….. string mystring = "This is a string"; …… return 0; }
  • 46. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES Example : 15.25F - float 1000.5L - Long double 25000L - Long integer 25 - integer Data Type ? Data Type ? Data Type ? Data Type ? Did you know that long,short,signed and unsigned are called qualifier purpose of qualifier : to manipulate the range of a particular data type or its size size qualifiers : long and short sign qualifiers : signed and unsigned
  • 47. 1.2.5 LIST THE DATA TYPES AND THEIR RESPECTIVE RANGE WITH EXAMPLES Things to ponder : Integer data type : int is normally 2 bytes with range of 0 to 255 What will happen if ? 1. you declare it as long int 2. you declare it as short int 3. you declare it as unsigned int 1. size will increase to 4 bytes 2. size will reduce to 1 byte 3. range increase from 0 to 65535