2. OUTLINE
● Problem solving techniques and strategies,
● Understanding problem solving steps such as
○ Problem analysis,
○ design, implement, and
○ code test.
● Simple Input/ Output statements
● Escape codes,
● Programming Errors: syntax, runtime, and logical.
● Describing syntax and semantics
4. Problem solving techniques and strategies
● A computer cannot solve a problem on its own.
● One has to provide step by step solutions of the problem to the computer.
● In fact, the task of problem solving is not that of the computer.
● It is the programmer who has to write down the solution to the problem in terms
of simple operations which the computer can understand and execute.
5. Problem solving techniques and strategies….
● Procedures (Steps Involved in Problem Solving)
● In order to solve a problem by the computer, one has to pass though certain
stages or steps.
1. Understanding the problem
2. Analyzing the problem
3. Developing the solution (Design)
4. Coding and implementation.
6. Problem solving techniques and strategies….
1. Understanding the problem:
● Here we try to understand the problem to be solved in totally.
● Before with the next stage or step, we should be absolutely sure about the
objectives of the given problem.
2. Analyzing the problem:
● After understanding thoroughly the problem to be solved, we look different ways
of solving the problem and evaluate each of these methods.
● The idea here is to search an appropriate solution to the problem under
consideration.
● The end result of this stage is a broad overview of the sequence of operations
that are to be carried out to solve the given problem.
7. Problem solving techniques and strategies….
3. Developing the solution:
● Here the overview of the sequence of operations that was the result of analysis
stage is expanded to form a detailed step by step solution to the problem under
consideration.
4. Coding and implementation:
● The last stage of the problem solving is the conversion of the detailed sequence
of operations in to a language that the computer can understand.
● Here each step is converted to its equivalent instruction or instructions in the
computer language that has been chosen for the implantation.
8. Problem solving techniques and strategies….
What is Algorithm?
Definition
● A set of sequential steps usually written in Ordinary Language to solve a given
problem.
It may be possible to solve to problem in more than one ways, resulting in more
than one algorithm.
● The choice of various algorithms depends on the factors like reliability,
accuracy and easy to modify.
● The most important factor in the choice of algorithm is the time requirement to
execute it
9.
10.
11.
12. Simple Input/ Output statements
● cin and cout are two predefined C++ objects which represent standard input
and output stream.
● The standard output stream represents the screen, while the standard input
stream represents the keyboard.
● These objects are members of iostream class.
● Hence the header file <iostream.h> should be included in the beginning of all
C++ programs.
13.
14. Escape code
Escape codes
● Escape codes are used to represent characters that are difficult to express
otherwise in the source code.
For instance a tab (t).
● Escape codes all start with a backslash ().
● Escape codes can also be used to express octal (base-8) or hexadecimal (base-
16) numbers. An octal number can be used like this: 10 (backslash followed by
a number.)
● A hexadecimal number can be used like this: xF0 (a backslash followed by an x
and the number.)
16. Programming Errors
Error is an illegal operation performed by the user which results in abnormal
working of the program.
● Programming errors often remain undetected until the program is compiled or
executed.
● Some of the errors inhibit the program from getting compiled or executed.
● Thus errors should be removed before compiling and executing.
17. Programming Errors
Types of program errors
● We distinguish between the following types of errors:
1. Syntax errors: errors due to the fact that the syntax of the language is not
respected.
2. Semantic errors: errors due to an improper use of program statements.
3. Logical errors: errors due to the fact that the specification is not respected.
From the point of view of when errors are detected,
● We distinguish:
1. Compile time errors: syntax errors and static semantic errors indicated by the
compiler.
2. Runtime errors: dynamic semantic errors, and logical errors, that cannot be
detected by the compiler (debugging).
18.
19. Syntax, semantics, and pragmatics
● Every programming language has syntax, semantics, and pragmatics.
● We have seen that natural languages also have syntax and semantics, but
pragmatics is unique to programming languages.
20. Syntax, semantics, and pragmatics
● A programming language’s syntax is concerned with the form of programs
○ how expressions, commands, declarations, and other constructs must be arranged
to make a well-formed program.
● A programming language’s semantics is concerned with the meaning of
programs:
○ how a well-formed program may be expected to behave when executed on a
computer.
● A programming language’s pragmatics is concerned with the way in which the
language is intended to be used in practice.
21. Syntax, semantics, and pragmatics
Pragmatics is the third general area of language description, referring to practical aspects of how
constructs and features of a language may be used to achieve various objectives.
● Consider, for example, the syntax, semantics and pragmatics of an assignment statement.
As a syntactic construct, an assignment statement may consist of a variable and an expression
(themselves syntactic constructs), separated by the token = as an assignment operator. Semantically,
the variable denotes a location in computer memory, while the expression denotes computation of a
value based on the contents of memory.
● Overall, the semantics of assignment is to perform the expression evaluation based on current
memory contents and then update the value stored in the particular location corresponding to the
variable. But what is often most interesting to programmers is really the pragmatics, that is, what
assignment statements are useful for.
● There are many possibilities: to set up a temporary variable for the value of an expression that is
needed more than once, to communicate values from one part of a program to another, to modify
part of a data structure, or to set successive values of a variable used in some iterative
computation.
27. An important note about compilers:
● Modern compilers typically are very accurate in identifying syntax errors and
will help you enormously in correcting your code.
● However, compilers often present two difficult problems for new programmers:
a) They frequently can miss reporting an actual error on one line but get “thrown off
track,” then report errors on subsequent lines that are not truly errors; the compiler
may then also display error messages which are incorrect; and
b) After encountering one true syntax error, compilers often generate many incorrect
syntax error messages; again, the compiler has been “thrown off track” by a
particular error. Why does this occur? Basically, because a compiler is a very
complex and sophisticated language-processing program, and no computer
program can analyze any language as well as a human being can at this point in
time.
32. What is debugging ?
Debugging:
● Is the process of identifying and removing errors from computer hardware or
software.
or
● is the process of detecting and removing of existing and potential errors (also
called as 'bugs') in a software code that can cause it to behave unexpectedly or
crash.
● To prevent incorrect operation of a software or system, debugging is used to
find and resolve bugs or defects
33. What is debugging ?....
● Debugger: is a computer program that assists in the detection and correction of
errors in other computer programs.
● A debugger is a computer program used by programmers to test and debug a
target program.
● Debuggers may use instruction-set simulators, rather than running a program
directly on the processor to achieve a higher level of control over its execution.
34. Techniques for detecting errors (debugging)
• If the testing phase signals the presence of logical errors, or if we are not able to detect the cause for a
runtime error, it is necessary to debug the program.
• There are two ways in which we can obtain information that is helpful for debugging a program:
1. By inserting output statements in the code;
2. By executing the program by means of a debugger.