0% found this document useful (0 votes)
10 views64 pages

Programming Fundamental 3 Lec

The document outlines the basics of C++ programming, focusing on fundamental concepts such as functions, data types, and syntax rules. It emphasizes the importance of hands-on practice in learning programming and introduces key elements like variables, operators, and comments. Additionally, it categorizes data types into simple, structured, and pointers, detailing integral and floating-point types along with their specific uses.

Uploaded by

cyberexpert997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views64 pages

Programming Fundamental 3 Lec

The document outlines the basics of C++ programming, focusing on fundamental concepts such as functions, data types, and syntax rules. It emphasizes the importance of hands-on practice in learning programming and introduces key elements like variables, operators, and comments. Additionally, it categorizes data types into simple, structured, and pointers, detailing integral and floating-point types along with their specific uses.

Uploaded by

cyberexpert997
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 64

Programming

Fundamental
s
Week 2 Day 1

Instructor: Noor Ullah Khan


Chap 2: Basic
Elements of C+
+
Become familiar
with functions, Explore Simple
Special Symbols data types
and identifiers.

Today’s How to use


arithmetic
Evaluate
arithmetic
Agenda operators? expressions.

Assignments
String data type statement and
what it does?
Previously

• A computer program, or a program, is a sequence of


statements whose objective is to accomplish a task.
• Programming is a process of planning and creating a program.
How to learn
programming/coding?

• Learning a programming language is like learning to become a


chef or learning to play a musical instrument.
• All three require direct interaction with the tools.
• You cannot become a good chef just by reading recipes.
• Similarly, you cannot become a musician by reading books
about musical instruments.
How to learn
programming/coding?

• You must have a fundamental knowledge of the language.


• you must test your programs on the computer to make sure
that each program does what it is supposed to do.
A quick look at a c++ program
Various parts of a c++
program
Basics of a c++ Program
What is variable?
What is variable?
Syntax rules

• If you have never seen a program written in a programming


language, the C++ program may look like a foreign language.
• To make meaningful sentences in a foreign language, you
must learn its alphabet, words, and grammar.
• The same is true of a programming language.
• To write meaningful programs, you must learn the
programming language’s special symbols, words, and syntax
rules.
Syntax rules

• The syntax rules tell you which statements (instructions) are


legal or valid, that is, which are accepted by the programming
language and which are not
Programming Language

• A set of of rules, symbols and special words.


Comments

• The program that you write should be clear not only to you, but
also to the reader of your program.
• Part of good programming is the inclusion of comments in the
program.
Comments
Comments

• There are two types of comments:


• Single-line comments
• Double-line comments
Comments
Special Symbols

• The smallest individual unit of a program written in any


language is called a token.
• C++’s tokens are divided into special symbols, word
symbols, and identifiers.
Special Symbols
Special Symbols

• Tokens made up of two characters are regarded as a single


symbol.
• Blank is a special symbol.
Reserved words(Keywords)

• A second category of tokens is reserved word symbols.


• Example: int, float, double, char, const, void, return
• Reserved words are also called keywords.
• Imp: The letters that make up a reserved word are always
lowercase.
Reserved words(keywords)

• Reserved words cannot be redefined within any program.


• They cannot be used for anything other than their intended use
Identifiers

• A third category of tokens is identifiers.


• Identifiers are names of things that appear in programs, such
as variables, constants, and functions.
• All identifiers must obey C++’s rules for identifiers.
Identifier Rules

• A C++ identifier consists of letters, digits, and the underscore


character (_).
• It must begin with a letter or underscore.
• Identifiers can be made of only letters, digits, and the
underscore character; no other
• Symbols are permitted to form an identifier.
Identifier Rules

• C++ is case sensitive—uppercase and lowercase letters are


considered different.
• Thus, the identifier NUMBER is not the same as the identifier
number.
• Similarly, the identifiers X and x are different.
Identifiers

• Some identifiers are predefined; others are defined by the user.


• Examples for predefined are: cout, cin etc.
• Examples of user-defined are: length, height etc.
Identifiers
Identifiers
Whitespaces

• Every C++ program contains whitespaces.


• Whitespaces include blanks, tabs, and newline characters.
• Whitespaces are nonprintable in the sense that when they are
printed on a white sheet of paper, the space between special
symbols, reserved words, and identifiers is white.
Data type

• The objective of a C++ program is to manipulate data.


• A program designed to calculate an employee’s paycheck will
add, subtract, multiply, and divide numbers.
• Some of the numbers might represent hours worked and pay
rate.
• Similarly, you wouldn’t use a program designed to perform
arithmetic calculations to manipulate alphabetic characters.
Data Type

• Reflecting these kinds of underlying differences, C++


categorizes data into different types.
• Only certain operations can be performed on particular types
of data.
Data Type

• A set of values together with a set of allowed operations.


• C++ data types fall into the following three categories:
• Simple Data Type
• Structured Data Type
• Pointers

• For now, on we will only be concerned about Simple Data


type
Simple Data Type

• The simple data type is the fundamental data type in C++.


• There are three categories of simple data:
• Integral, which is a data type that deals with integers, or numbers
without a decimal part.
• Floating point, which is a data type that deals with decimal numbers.
• Enumeration, which is a user-defined data type.
Integral Data Types

• Integral data types are further classified into the following


categories:
• char, short, int, long, bool, unsigned char, unsigned short, unsigned int,
unsigned long, long long, and unsigned long long.
Integral Data Types

• Why are there so many categories of the same data type?


• Every data type has a different set of values associated with it.

• char data type is used to represent integers between -128


and 127.
• The int data type is used to represent integers between 
-2147483648 and 2147483647.
• The data type short is used to represent integers between 
-32768 and 32767
Integral Data Types

• Which data type you use, depends on how big a number your
program needs to deal with.
Integral Data Types
int Data Type

• Integers in C++, as in mathematics, are numbers such as the


following:
• -6728, -67, 0, 78, 36782, +763

• Note the following two rules from these examples:


• Positive integers do not need a + sign in front of them.
• No commas are used within an integer. Recall that in C11, commas are
used to separate items in a list.
• So, 36,782 would be interpreted as two integers: 36 and 782.
bool Data Type

• The data type bool has only two values: true and false.
• Also, true and false are called the logical (Boolean) values.
• In C++, bool, true, and false are reserved words.
char Data Type

• The data type char is mainly used to represent single


characters—that is, letters, digits, and special symbols.
• Thus, the char data type can represent every key on your
keyboard.
• When using the char data type, you enclose each character
represented within single quotation marks.
• Example:
• 'A’, 'a’, ‘0’, '*’, '+’, '$’, '&’, ' '
char Data Type

• Note that a blank space is a character and is written as ‘


’, with a space between the single quotation marks.
• The data type char allows only one symbol to be placed
between the single quotation marks.
• Thus, the value 'abc' is not of the type char.
Floating-Point Data Type

• To deal with decimal numbers, C++ provides the floating-point


data type.
Floating-Point Data Type
Floating-Point Data Type

• To represent decimal numbers, C++ uses a form of scientific


notation called floating-point notation.
Floating-Point Data Type
Floating-Point Data Type

• C++ provides three data types to manipulate decimal


numbers: float, double, and long double.
float

• The data type float is used in C++ to represent any decimal


number between -3.4 * 1038 and 3.4 * 1038.
• The memory allocated for a value of the float data type is four
bytes.
double

• The data type double is used in C++ to represent any decimal


number between -1.7 * 10308 and 1.7 * 10308.
• The memory allocated for a value of the double data type is
eight bytes.
Data Types, Variables,
and Assignment
Statements
How to declare a variable?

• When we declare a variable.


• We specify the name of the variable.
• We also specify what type of data a variable can store.
Syntax of declaring a variable
How to store a value in a variable?

• Using assignment operator.


• Syntax:
• variable = expression

• Where expression is evaluated, and its value is assigned to


variable. In C++, = is called the assignment operator.
How to store a value in a variable?
Arithmetic Operators, Operator Precedence,
and Expressions

• One of the most important uses of a computer is its ability to


calculate.
• You can use the standard arithmetic operators to manipulate
integral and floating-point data types.
Arithmetic Operators, Operator Precedence,
and Expressions

• There are five arithmetic operations:


• + (addition)
• - (subtraction or negation)
• * (multiplication)
• / (division)
• % (mod, (modulus or remainder))
Arithmetic Operators, Operator Precedence,
and Expressions
Arithmetic Operators,
Operator Precedence, and
Expressions
Arithmetic Operators, Operator Precedence,
and Expressions

• What is operand?
• What is operator?
• Unary operand
• Binary Operator
Operator Precedence

• BDMAS

You might also like