SlideShare a Scribd company logo
Lecture 03-04
Computer Programming
1
2
• Problem solving
• Six steps towards problem solution
• Basic problem solving concepts
• Data types
• Data literals
• Variables
• Constants
• Rules for naming variable and constant
• Operators
3
4
• In every day life people make decisions to solve many problems.
• The problems may be unimportant as what to watch on TV or as important
as choosing a new profession.
• If a bad decision is made, time and resources are wasted.
• So it is important that people know how to make decisions well.
5
• There are six steps to follow to ensure the best decision:
Evaluate
the solution
List
instruction
to solve
problem
Selectthe
best
solution
Identify
alternative
solutions
Understand
the
problem
Identify the
problem
6
7
• The first step towards solving a problem is to identify the problem.
• If you don’t know what the problem is, you cannot solve it.
• In a classroom situation, most problems have been identified for you and
given to you in the form of written assignments or problems out of a book.
However, when you are doing problem solving outside the classroom, you
need to make sure you identify the problem before you start solving it.
8
9
• You must understand what is involved in the problem before you can
continue toward the solution.
• You cannot solve a problem if you do not know the subject.
• For example, to solve a problem involving average of numbers, you must
know how to calculate average; to solve a problem of trigonometry, you
must know trigonometry.
10
11
• A single problem can be solved in many different ways.
• Identify and list all the possible solutions to the problem.
• For example there are multiple ways to sort the numbers as:
• Insertion sort
• Selectionsort
• Bubble sort
12
13
• Analyze and identify the pros and cons of every alternative solution.
• Choose the solution that is optimal and best matches with your
requirements.
• For example out of all the sorting options you choose bubble sort as your
best solution.
14
15
• Write down general step by step procedure to solve the problem.
• For example to solve problem of calculating average of three numbers:
• Step 01 : Ask numbers a, b, and c from the user
• Step 02 : Add a, b, c and store result insum
• Step 03 : Divide sum by 3 and store result in avg
• Step 04 : Display avg
16
17
• Finally evaluate and test the solution, means to check its result to see if it is
correct and satisfies the needs.
• For example, when a person needs a pen to write a letter, buying him marker
may be a correct solution, but it may not be very satisfactory.
• If the result is either incorrect or unsatisfactory, then the problem solver
must review the list of instructions to see that they are correct or start the
process all over again.
18
19
• Every problem involves some sort of data in it.
• The data can be:
• Numbers
• Integers (e.g. 24, 5874, -547)
• Floating (e.g. 45.214, 0.2547, -658.748)
• Characters (e.g. ‘a’, ‘f’, ‘#’, ‘?’, ‘!’, ‘w’)
• String (e.g. “mehran”, “computer”, “MUET CSE”)
• Logical (e.g. True and False, Yes and No, 0 and 1)
• The type of data is known as data type of that data item.
20
Data Item Example Value Data Type
Age of a person 35 Integer
Current year 2014 Integer
Radius of circle 27.58 Floating
Value of PI 3.14159 Floating
A vowel e Character
A key on keyboard ? Character
Person’s name Ahmed Ali String
Address of an office Department of CSE-MUET String
Is 1st number greater than 2nd? True or T or Yes or 1 Logical
Is 7 less than 5 ? False or F or No or 0 Logical
21
Data Types
Data Item Example Value Data Type
Number of students
Brand name of smartphone
Is 5 an even number?
Count of cars in parking
Speed of a car
Your grade in result
Is 13 a prime number ?
Title of book chapter
Percentage of marks
Option in MCQ
22
• A fixed value that any data type can take is called as literal.
• A number literal is always written without quotes. (15, 68, 25.14, 578.14)
• A character literal is always written in single quotes. (‘a’, ‘f’, ‘#’, ‘?’, ‘!’)
• An string literal is always written in double quotes. (“mehran”, “computer”)
• An logical literal is always written without quotes. (True, False, T,F,Yes, No, 1, 0)
23
Data Literal Type of Literal
“Ali” String
‘b’ Character
25.2 Floating
“87.5” String
‘4’ Character
4 Integer
4.0 Floating
“true” String
false Logical
“mehran” String
24
• In programming, a variable is the memory (RAM) location that can store the
data temporary.
• Every program uses some sort of data and each data item is stored
temporarily in the variables.
• Every variable has:
• Name
• Data type
• Value
25
• Consider two of the examples.
• In first example, we have a variable whose name is radius,
its data types is floating and its value is 25.5.
• In second example, we have a variable whose name is
option, its data type is character and its value is b.
• The name of the variable is called as the identifier.
25.5
radius
b
option
26
• The data type of the variable defines that what type of the data will be
stored in a variable.
• Once the data type of variable is defined, it cannot hold any value of other
data type.
• The value of the variable is changeable but its data type is not.
27
• In programming, a constant is a variable whose value remains fixed through
out the program.
• In certain programs some sort of data remains unchangeable through out
the program, hence we use constants to stored that data so that it can not be
altered.
28
• Consider three of the examples.
• In first example, we have a constant whose name is PI, its
data types is floating and its value is 3.141.
• In second example, we have a constant whose name is E
(Euler’s number), its data type is floating and its value is
2.718.
3.141
PI
2.718
E
29
• In third example, we have a constant whose name is
SPEEDOFLIGHT, its data types is floating and its value
is 3 x 108.
3E8
SPEEDOFLIGHT
30
• The name of any variable for constant is called as identifier.
• There are certain rules to follow when setting the identifier.
• Rule 1: May contain letters (A-Z, a-z), digits (0-9) or an underscore sign.
• Rule 2: It must start with letter or underscore sign.
• Rule 3: Should not contain any space in between.
• Rule 4: Should not be like any keyword of language like, int, cout, float.
• Rule 5: It is case sensitive i.e. radius is not same as Radius or RADIUS.
31
• Rule 6: Must be unique i.e. no any two variables have same identifier.
• Rule 7: Must be relevant i.e. var1 is inappropriate identifier to store the area
of circle, use area of area_circle instead.
• Rule 8: The identifier for constant is written with all capital letters. i.e. PI,
SPEEDOFLIGHT, E etc.
32
Identifier Valid/Invalid Remarks
first_number Valid
first number Invalid Must not contain space in between
number_1 Valid
1st_number Invalid Must start with a letter or underscore sign
first# Invalid Must not contain invalid character $
int Invalid Must not be like keyword
firstNumber Valid
int_first_number Valid
first_number_$ Invalid Must not contain invalid character #
1st_# Invalid Must start with a letter or underscore sign
Must not contain invalid character #
33
Rules for naming Variables and Constants
Identifier Valid/Invalid Remarks
number of items
#_of_items
price/item
number_items
itemCount
item#Price
itemPrice_1
5_itemPrice
ITEM_PRICE
$_per_item
34
• Computer performs several operations on the data. The
operations are represented by symbols known as operators.
• Operands are the data on which the operation is performed.
• Operand may be constant or stored in one of the variable.
35
• Example 1: a + b
• + is the operator
• a and b are the operands
• Both a and b are variables
• Example 1: 2 * length
• * is the operator
• 2 and length are the operands
• 2 is constant and length is avariable
36
Operator Symbol Example Operation Resultant
Addition + 10 + 26 36
Subtraction - 10 - 8 2
Multiplication * 4 * 20 80
Division / 25/5 5
Remainder/Modulus % 13 % 5 3
Power ^ 2^4 16
37
Operator Symbol Example Operation Resultant
Greater Than > 5 > 6 false
Less Than < 10 < 15 true
Greater Than or Equals To >= 41 >= 90 true
Less Than or Equals To <= 16 <=16 true
Equals To == 15 == 19 false
Not Equals To != 14 != 80 true
38
Operator Symbol Example Operation Resultant
AND & true & true true
true & false false
false & true false
false & false false
OR ¦ true ¦ true true
true ¦ false true
false ¦ true true
false ¦ false false
NOT ! ! true false
! false true
39
A B A & B
True True True
True False False
False True False
False False False
40
A B A ¦ B
True True True
True False True
False True True
False False False
41
A ! A
True False
False True
42

More Related Content

PPTX
Object oriented programming16 boolean expressions and selection statements
PPT
constants, variables and datatypes in C
PDF
Effect Sizes (ES) for Meta-Analyses.pdf
PPT
Equivalence partitions analysis
PDF
PPT
Ssad decision table
PPT
Data types and Operators
PPTX
EquivalencePartition
Object oriented programming16 boolean expressions and selection statements
constants, variables and datatypes in C
Effect Sizes (ES) for Meta-Analyses.pdf
Equivalence partitions analysis
Ssad decision table
Data types and Operators
EquivalencePartition

What's hot (20)

PDF
Equivalence partitioning
PPTX
If and select statement
PDF
Lecture 8: Machine Learning in Practice (1)
PPTX
Implementing Item Response Theory
PPT
Data Types in C
PDF
Confirmatory Factor Analysis
PDF
Analytic hierarchy process
PPTX
Java Chapter 05 - Conditions & Loops: part 4
PDF
Object oriented programming15 control structures relational operators
PPTX
Reverse+multiple choice+method--presentation 6-feb12
PPTX
Irt assessment
PPTX
Week 1: Getting Your Hands Dirty - Part 1
PPTX
Week 2: Getting Your Hands Dirty – Part 2
PPTX
Introduction to unidimensional item response model
PPTX
Structural equation modeling in amos
PPT
Bengkel smartPLS 2011
PDF
Introduction to statistical modeling in R
PDF
Istqb ctfl-series - Black Box Testing
PPT
Introduction to Item Response Theory
PPTX
Machine Learning - Simple Linear Regression
Equivalence partitioning
If and select statement
Lecture 8: Machine Learning in Practice (1)
Implementing Item Response Theory
Data Types in C
Confirmatory Factor Analysis
Analytic hierarchy process
Java Chapter 05 - Conditions & Loops: part 4
Object oriented programming15 control structures relational operators
Reverse+multiple choice+method--presentation 6-feb12
Irt assessment
Week 1: Getting Your Hands Dirty - Part 1
Week 2: Getting Your Hands Dirty – Part 2
Introduction to unidimensional item response model
Structural equation modeling in amos
Bengkel smartPLS 2011
Introduction to statistical modeling in R
Istqb ctfl-series - Black Box Testing
Introduction to Item Response Theory
Machine Learning - Simple Linear Regression
Ad

Similar to c++ computer programming language datatypes ,operators,Lecture 03 04 (20)

PPT
Token and operators
PPTX
CHAPTER 2
PDF
2 beginning problem solving concepts for the computer
PPT
Lecture 01 - Introduction and Review.ppt
PPTX
C++ Tutorial
PPTX
FDS Unit I_PPT.pptx
PPTX
Data structure and algorithm
PPT
Programming
PPTX
C++ Basics introduction to typecasting Webinar Slides 1
PPTX
Input output
PPTX
Numeric Data Types & Strings
PDF
PPTX
Programming Fundamentals
PPT
PPT slide_chapter 02 Basic element of C++.ppt
PPT
C++.ppt
PDF
Scope, binding, papameter passing techniques
PPTX
C Session 2.pptx for engninering students
PPT
Fundamentals of Programming Chapter 4
PPT
FP 201 Unit 2 - Part 2
PDF
Chapter 2 : Balagurusamy_ Programming ANsI in C
Token and operators
CHAPTER 2
2 beginning problem solving concepts for the computer
Lecture 01 - Introduction and Review.ppt
C++ Tutorial
FDS Unit I_PPT.pptx
Data structure and algorithm
Programming
C++ Basics introduction to typecasting Webinar Slides 1
Input output
Numeric Data Types & Strings
Programming Fundamentals
PPT slide_chapter 02 Basic element of C++.ppt
C++.ppt
Scope, binding, papameter passing techniques
C Session 2.pptx for engninering students
Fundamentals of Programming Chapter 4
FP 201 Unit 2 - Part 2
Chapter 2 : Balagurusamy_ Programming ANsI in C
Ad

Recently uploaded (20)

PPTX
Construction Project Organization Group 2.pptx
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PPTX
web development for engineering and engineering
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
bas. eng. economics group 4 presentation 1.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Construction Project Organization Group 2.pptx
CYBER-CRIMES AND SECURITY A guide to understanding
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Foundation to blockchain - A guide to Blockchain Tech
web development for engineering and engineering
CH1 Production IntroductoryConcepts.pptx
OOP with Java - Java Introduction (Basics)
bas. eng. economics group 4 presentation 1.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Lesson 3_Tessellation.pptx finite Mathematics
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Embodied AI: Ushering in the Next Era of Intelligent Systems
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...

c++ computer programming language datatypes ,operators,Lecture 03 04

  • 2. 2 • Problem solving • Six steps towards problem solution • Basic problem solving concepts • Data types • Data literals • Variables • Constants • Rules for naming variable and constant • Operators
  • 3. 3
  • 4. 4 • In every day life people make decisions to solve many problems. • The problems may be unimportant as what to watch on TV or as important as choosing a new profession. • If a bad decision is made, time and resources are wasted. • So it is important that people know how to make decisions well.
  • 5. 5 • There are six steps to follow to ensure the best decision: Evaluate the solution List instruction to solve problem Selectthe best solution Identify alternative solutions Understand the problem Identify the problem
  • 6. 6
  • 7. 7 • The first step towards solving a problem is to identify the problem. • If you don’t know what the problem is, you cannot solve it. • In a classroom situation, most problems have been identified for you and given to you in the form of written assignments or problems out of a book. However, when you are doing problem solving outside the classroom, you need to make sure you identify the problem before you start solving it.
  • 8. 8
  • 9. 9 • You must understand what is involved in the problem before you can continue toward the solution. • You cannot solve a problem if you do not know the subject. • For example, to solve a problem involving average of numbers, you must know how to calculate average; to solve a problem of trigonometry, you must know trigonometry.
  • 10. 10
  • 11. 11 • A single problem can be solved in many different ways. • Identify and list all the possible solutions to the problem. • For example there are multiple ways to sort the numbers as: • Insertion sort • Selectionsort • Bubble sort
  • 12. 12
  • 13. 13 • Analyze and identify the pros and cons of every alternative solution. • Choose the solution that is optimal and best matches with your requirements. • For example out of all the sorting options you choose bubble sort as your best solution.
  • 14. 14
  • 15. 15 • Write down general step by step procedure to solve the problem. • For example to solve problem of calculating average of three numbers: • Step 01 : Ask numbers a, b, and c from the user • Step 02 : Add a, b, c and store result insum • Step 03 : Divide sum by 3 and store result in avg • Step 04 : Display avg
  • 16. 16
  • 17. 17 • Finally evaluate and test the solution, means to check its result to see if it is correct and satisfies the needs. • For example, when a person needs a pen to write a letter, buying him marker may be a correct solution, but it may not be very satisfactory. • If the result is either incorrect or unsatisfactory, then the problem solver must review the list of instructions to see that they are correct or start the process all over again.
  • 18. 18
  • 19. 19
  • 20. • Every problem involves some sort of data in it. • The data can be: • Numbers • Integers (e.g. 24, 5874, -547) • Floating (e.g. 45.214, 0.2547, -658.748) • Characters (e.g. ‘a’, ‘f’, ‘#’, ‘?’, ‘!’, ‘w’) • String (e.g. “mehran”, “computer”, “MUET CSE”) • Logical (e.g. True and False, Yes and No, 0 and 1) • The type of data is known as data type of that data item. 20
  • 21. Data Item Example Value Data Type Age of a person 35 Integer Current year 2014 Integer Radius of circle 27.58 Floating Value of PI 3.14159 Floating A vowel e Character A key on keyboard ? Character Person’s name Ahmed Ali String Address of an office Department of CSE-MUET String Is 1st number greater than 2nd? True or T or Yes or 1 Logical Is 7 less than 5 ? False or F or No or 0 Logical 21
  • 22. Data Types Data Item Example Value Data Type Number of students Brand name of smartphone Is 5 an even number? Count of cars in parking Speed of a car Your grade in result Is 13 a prime number ? Title of book chapter Percentage of marks Option in MCQ 22
  • 23. • A fixed value that any data type can take is called as literal. • A number literal is always written without quotes. (15, 68, 25.14, 578.14) • A character literal is always written in single quotes. (‘a’, ‘f’, ‘#’, ‘?’, ‘!’) • An string literal is always written in double quotes. (“mehran”, “computer”) • An logical literal is always written without quotes. (True, False, T,F,Yes, No, 1, 0) 23
  • 24. Data Literal Type of Literal “Ali” String ‘b’ Character 25.2 Floating “87.5” String ‘4’ Character 4 Integer 4.0 Floating “true” String false Logical “mehran” String 24
  • 25. • In programming, a variable is the memory (RAM) location that can store the data temporary. • Every program uses some sort of data and each data item is stored temporarily in the variables. • Every variable has: • Name • Data type • Value 25
  • 26. • Consider two of the examples. • In first example, we have a variable whose name is radius, its data types is floating and its value is 25.5. • In second example, we have a variable whose name is option, its data type is character and its value is b. • The name of the variable is called as the identifier. 25.5 radius b option 26
  • 27. • The data type of the variable defines that what type of the data will be stored in a variable. • Once the data type of variable is defined, it cannot hold any value of other data type. • The value of the variable is changeable but its data type is not. 27
  • 28. • In programming, a constant is a variable whose value remains fixed through out the program. • In certain programs some sort of data remains unchangeable through out the program, hence we use constants to stored that data so that it can not be altered. 28
  • 29. • Consider three of the examples. • In first example, we have a constant whose name is PI, its data types is floating and its value is 3.141. • In second example, we have a constant whose name is E (Euler’s number), its data type is floating and its value is 2.718. 3.141 PI 2.718 E 29
  • 30. • In third example, we have a constant whose name is SPEEDOFLIGHT, its data types is floating and its value is 3 x 108. 3E8 SPEEDOFLIGHT 30
  • 31. • The name of any variable for constant is called as identifier. • There are certain rules to follow when setting the identifier. • Rule 1: May contain letters (A-Z, a-z), digits (0-9) or an underscore sign. • Rule 2: It must start with letter or underscore sign. • Rule 3: Should not contain any space in between. • Rule 4: Should not be like any keyword of language like, int, cout, float. • Rule 5: It is case sensitive i.e. radius is not same as Radius or RADIUS. 31
  • 32. • Rule 6: Must be unique i.e. no any two variables have same identifier. • Rule 7: Must be relevant i.e. var1 is inappropriate identifier to store the area of circle, use area of area_circle instead. • Rule 8: The identifier for constant is written with all capital letters. i.e. PI, SPEEDOFLIGHT, E etc. 32
  • 33. Identifier Valid/Invalid Remarks first_number Valid first number Invalid Must not contain space in between number_1 Valid 1st_number Invalid Must start with a letter or underscore sign first# Invalid Must not contain invalid character $ int Invalid Must not be like keyword firstNumber Valid int_first_number Valid first_number_$ Invalid Must not contain invalid character # 1st_# Invalid Must start with a letter or underscore sign Must not contain invalid character # 33
  • 34. Rules for naming Variables and Constants Identifier Valid/Invalid Remarks number of items #_of_items price/item number_items itemCount item#Price itemPrice_1 5_itemPrice ITEM_PRICE $_per_item 34
  • 35. • Computer performs several operations on the data. The operations are represented by symbols known as operators. • Operands are the data on which the operation is performed. • Operand may be constant or stored in one of the variable. 35
  • 36. • Example 1: a + b • + is the operator • a and b are the operands • Both a and b are variables • Example 1: 2 * length • * is the operator • 2 and length are the operands • 2 is constant and length is avariable 36
  • 37. Operator Symbol Example Operation Resultant Addition + 10 + 26 36 Subtraction - 10 - 8 2 Multiplication * 4 * 20 80 Division / 25/5 5 Remainder/Modulus % 13 % 5 3 Power ^ 2^4 16 37
  • 38. Operator Symbol Example Operation Resultant Greater Than > 5 > 6 false Less Than < 10 < 15 true Greater Than or Equals To >= 41 >= 90 true Less Than or Equals To <= 16 <=16 true Equals To == 15 == 19 false Not Equals To != 14 != 80 true 38
  • 39. Operator Symbol Example Operation Resultant AND & true & true true true & false false false & true false false & false false OR ¦ true ¦ true true true ¦ false true false ¦ true true false ¦ false false NOT ! ! true false ! false true 39
  • 40. A B A & B True True True True False False False True False False False False 40
  • 41. A B A ¦ B True True True True False True False True True False False False 41
  • 42. A ! A True False False True 42