Problem-Solving Process with Computers

 
Problem Solving
with Computer
 
1
 
 
Intro
 
Number of problems in our daily life.
Suppose we have to calculate Simple
Interest.
Suppose we have to prepare a mark
sheet.
 
A computer is a 
DUMB
 machine.
A computer cannot do anything alone
without software i.e. 
Program
 
2
 
 
A software is a set of programs written to solve a
particular problem
 
Software is a set of instructions on the basis of which
computer gives output/result.
 
If the instructions are not correct, the computer
gives wrong result.
 
3
 
 
Never Ever Forget
 
Just writing code is not sufficient to solve a problem.
 
Program must be planned before coding in any
computer language available.
 
There are many activities to be done before and
after writing code.
 
4
 
 
Stages while solving a
problem using computer
 
1.
Problem Analysis
2.
Algorithm Development
3.
Flowcharting
4.
Coding
5.
Compilation and Execution
6.
Debugging and Testing
7.
Documentation
 
5
 
 
Fig. Steps in problem solving
 
6
Algorithm Development
Flowcharting
Documentation
Debugging and Testing
Compilation and Execution
Program Coding
Problem Analysis
 
 
Problem Analysis
 
Process of becoming familiar with the problem.
 
We need to analyze and understand it well before
solving.
 
The user’s requirements cannot be fulfilled without
clear understanding of his/her problem in depth.
 
Inadequate identification 
of problem may cause
program less useful and insufficient.
 
Example: Banking Solution, Hospital Medical Study
 
7
 
 
Algorithm Development
 
Step By Step description of the method
to solve a problem.
 
Effective procedure for solving a
problem in finite number of steps.
 
Developing an algorithm is a step of
program design.
 
8
 
 
An algorithm to find sum of two numbers:
 
Step 1
: Start
 
Step 2
: Assume two numbers 
x
 and 
y
 and a variable 
sum=0
 
Step 3
: Add two numbers x and y; store the value in
variable sum
 
Step 4
: If you want to try again with different numbers
  
then goto step 2
 
else
  
goto step 5
Step 5
: END
 
9
 
 
An algorithm to find sum of two numbers:
 
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the
result to sum. 
 
sum←num1+num2
Step 5: Display sum Step 6: Stop
 
10
 
 
An algorithm to find largest of three
different numbers:
 
11
 
 
Three features of Algorithm
 
Sequence
Each step in the algorithm in executed in specified order. If
not algorithm will fail.
Decision
We have to make decision to do something.
If the outcome of the decision is true, one thing is done
otherwise other.
If
 condition 
then
 process1
 
OR
If
 condition
then
 process1
    Else
 process2
Repetition
For example
 
Repeat
 
Fill Water in the kettle
 
Until
 Kettle is full
 
12
 
 
Flowcharting
 
Graphical representation of an algorithm using
standard symbols.
 
Includes a set of various standard shaped boxes
that are interconnected by flow lines.
 
Flow lines 
have arrows(direction of flow).
 
Activities are written within boxes in English.
 
Communicates between programmers and
business persons.
 
13
 
 
Advantages of Flowcharts
 
Communication
Quickly provide logic, ideas and descriptions of algorithms.
Effective Analysis
Clear overview of the entire problem.
Proper Documentation
Documents the steps followed in an algorithm.
Helps us understand its logic in future.
Efficient Coding
More ease with comprehensive flowchart as a guide
Easy in debugging and program maintenance
Debugging and maintenance of operating program
 
14
 
Flowchart Symbols
 
15
 
Things to consider
 
There should be 
start
 
and 
stop
 
to the flowchart.
 
Only 
one
 flow line should emerge from a process
symbol.
 
Only one flow line should enter a decision symbol
, 
but
two or three flow lines can leave the decision symbol.
 
 
16
 
Write an algorithm and draw flowchart for
finding the sum of any two numbers.
 
Algorithm
-------------
Step1: Start
Step2: Display “Enter two numbers”.
Step3: Read A and B
Step4: C= A+B
Step5: Display “C as sum of two numbers”
Step6: Stop
 
 
17
 
Flowchart
 
 
18
START
END
Read two
Numbers, 
A
 and
B
Display C as Sum of A
and B
C = A + B
 
Input
 
Start
 
Output
 
End
 
Processing
 
Some questions for Assignment
 
Write an algorithm and draw flowchart
to determine a number whether it is
positive or negative.
 
Write an algorithm and draw flowchart
to test a number for even or odd.
 
Write an algorithm and draw flowchart
to find the largest number among three
numbers.
 
 
19
 
Read N numbers from user and display
sum of all entered numbers.
For finding the sum of the series
1+2+3+4+… up to N terms
For calculating the factorial of a given
number N.
 
 
20
 
Coding
 
The process of transforming the program logic
design into computer language format.
 
An act of transforming operations in each box
of the flowchart in terms of the statement of
the program.
 
The code written using programming language
is also known as 
source code
.
Coding isn’t the only task to be done to solve a
problem using computer.
Anyone can code. TRUST ME!!
 
21
 
Compilation
 
Process of changing high level language into
machine level language.
 
It is done by special software, 
COMPILER
 
The compilation process tests the program
whether it contains syntax errors or not.
 
If syntax errors are present, compiler can not
compile the code.
 
 
 
 
22
 
Execution
 
Once the compilation is completed then 
the
program is linked with other object programs
needed for execution
, 
there by resulting in a binary
program
 and 
then the program is loaded in the
memory
 for the purpose of execution and 
finally it is
executed
.
 
The program may ask user for inputs and generates
outputs after processing the inputs.
 
 
23
 
Debugging and Testing
 
Debugging is the discovery and correction of
programming errors.
 
Some errors may remain in the program because
the designer/programmer might have never
thought about a particular case.
 
When error appears debugging is necessary.
 
 
24
 
Debugging and Testing
 
Testing ensures that program performs correctly the
required task.
 
Verification ensures that program does what the
programmer intends to do.
 
Validation ensures that the program produces the
correct results for a set of test data.
 
Test data are supplied to the program and output is
observed.
Expected output = Error free
 
25
 
Program
 Documentation
 
Helps to those who 
use
, 
maintain
 and 
extend
 the
program in future.
 
A program may be difficult to understand even to
programmer who wrote the code after some days.
 
Properly documented program is necessary which
will be 
useful and efficient in debugging
, 
testing
,
maintenance
 
and 
redesign process
.
 
 
26
 
Two types of documentations
 
1.
Programmer’s Documentation (Technical
Documentation)
Maintain, redesign and upgrade
Logic, DFD, E-R, algorithm and flowchart
2.
User Documentation (User Manual)
Support to the user of the program
Instructions for installation of the program
 
27
 
Computer Program
and
Programming Language
 
 
28
 
Computer Program
 
Set of instructions that causes to behave in
predetermined manner.
 
To instruct a computer to perform a certain job, we
need languages, but not English or Nepali(!!!
FOR
NOW
!!!).
 
We need languages understood by the computer.
 
 
29
 
Types or levels of
Programming Languages
 
High Level
 
 
Low-level
Machine Level
Assembly Level
 
 
 
30
 
 
Low Level Language
 
Statement or instruction is directly translated into a
single machine code.
 
It is machine dependent, i.e. A particular low-level
language works only for a certain machine.
 
 
31
 
Machine-level Language
 
Language that a computer actually
understands.
1’s and 0’s.
Is a sequence of instructions written in the
form of binary numbers consisting of 1’s and
0’s
It executes fast as computer don’t need any
translation.
 
 
32
 
To add two number in machine language:
 
    11
   
10111001
   
110
     3
 
 
 
   
machine code for addition (say)
  
  
6
 
 
It is difficult to remember different
instructions for programming.
 
 
33
 
Machine Level Language
 
 
34
 
Assembly Language
 
Symbolic representation(
mnemonics
) of machine
code.
 
Close to machine code but the computer cannot
understand
 
Must be translated into machine code by a
separate program called an assembler.
 
11
  
ADD
  
110
Suppose ADD is mnemonic for addition
 
 
 
35
 
Some examples of instructions for
assembly languages are as follows:
 
 
36
 
It is relatively easy for writing programs in
assembly languages, but is slow in execution
as it has to be converted into machine
language before execution.
 
Assembly language
 
 
37
 
High Level Language
 
User friendly, Similar to natural languages
Platform independent
Easy to write or remember
Easy to learn and work
While execution: translated into assembly language
then to machine language.
Slow in execution but is efficient for developing
programs.
Ex: C, C++, Python, Java etc.
 
 
38
 
High Level Language
 
 
39
 
Compiler
 
A high level source program must be translated into a
form machine can understand. 
This done by software
called the 
compiler
.
 
Source code => Machine language code(Object code)
 
During the process of translation, the compiler reads the
source programs
 
statement-wise
 
and checks for syntax
errors.
 
In case of any error, the computer generates message
about the error.
 
Ex: C, C++, Java, FORTRAN, pascal etc.
 
 
 
40
 
Interpreter
 
Like compiler, it is also a translator which translates
high level to machine level language.
 
Translates and executes the program line by line.
 
Each line is checked for syntax error and then
converted to the equivalent machine code.
 
Ex. QBASIC, PERL, PHP, ASP, PYTHON, RUBY
 
 
41
 
Difference between compiler and
interpreter
 
 
42
 
Overview to C Programming
 
 
43
 
We can assume 
C
 as middle level language
 
This doesn’t mean 
C
 is less power full or harder to use or less
developed.
 
Instead 
C
 combines the advantages of high level language
with the functionalism of assembly language.
 
Like high level, C provides block structures, stand-alone
functions and small amount of data typing.
 
Like assembly language, it allows manipulations of bits, bytes,
pointers and it is mostly used in system programming.
 
Combination of two aspects.
 
 
 
44
 
History of C programming language
 
C is a programming language which was born at “AT & T’s Bell
Laboratory” of USA in 1972.
 
C was written by 
Dennis Ritchie
, that’s why he is also called as father
of C programming language.
 
C language was created for a specific purpose i.e. designing the
UNIX operating system (which is currently base of many UNIX based
OS).
 
From the beginning, C was intended to be useful to allow busy
programmers to get things done because C is such a powerful,
dominant and supple language.
 
It’s use quickly spread beyond Bell Labs in the late 70’s
 
 
45
 
Further Details
 
 
46
 
Why use C?
 
Robust Language
Efficient and fast
Highly portable
Structured Language
Extendibility
Middle level language
Rich system library
 
 
47
 
Executing a C Program
 
 
 
48
 
Basic Structure of C Program
 
 
 
49
 
1. Documentation Section
 
Sets of comment line giving the 
name of program
, 
the author
,
algorithms
, 
methods used
 and 
other details
.
Acts as a communication between members of the development
team.
Acts as 
user manual.
Ex
/* This program adds two numbers */
/*…. */ denotes comments in C
 
 
50
 
2. Link Section
-
Provides Instructions to the compiler to link functions with program from
the system library.
 
#include<stdio.h>
-
Links input/output functions like 
printf() 
and 
scanf() 
with the program
 
 
51
 
3. Definition Section
-
In this section all symbolic constants are defined.
-
Ex.
-
#define 
PI
 3.1416
-
#define 
FORMULA
 3*x*x*x+2*x*x
 
 
52
 
4. Global Declaration Section
-
The variables which are used in more than
one functions or blocks are called 
global
variables.
 
-
This section also declares all the user-
defined functions.
 
 
 
 
53
 
5. 
main
() Function Section
-
Every C program starts with a main() function.
-
Declaration 
part and 
executable
 part
 
-
Declaration part declares all the variables used in
the execution part.
-
int n1;
-
int n2=5;
 
-
Execution part has executable operations like:
-
n1= n1 +1;
-
n2=n1*5
 
54
 
6. Subprogram Section
-
This section contains all the user-defined functions
that are called in the main function.
 
-
All the sections except the main function section
may be absent when they are not required.
 
 
55
 
Note
 
For Assignments And Lecture Slides
https://github.com/ashim888/csit-c
http://www.ashimlamichhane.com.np/
 
 
 
56
Slide Note
Embed
Share

Utilizing computers to solve problems involves various stages such as problem analysis, algorithm development, flowcharting, programming, compilation, debugging, and documentation. It is crucial to plan and understand the problem thoroughly before coding to ensure accurate results. Each step in the problem-solving process plays a vital role in efficiently addressing the issue at hand.

  • Problem-solving
  • Computers
  • Algorithm
  • Programming
  • Software

Uploaded on Oct 05, 2024 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Problem Solving with Computer 1

  2. Intro 2 Number of problems in our daily life. Suppose we have to calculate Simple Interest. Suppose we have to prepare a mark sheet. A computer is a DUMB machine. A computer cannot do anything alone without software i.e. Program

  3. 3 A software is a set of programs written to solve a particular problem Software is a set of instructions on the basis of which computer gives output/result. If the instructions are not correct, the computer gives wrong result.

  4. Never Ever Forget 4 Just writing code is not sufficient to solve a problem. Program must be planned before coding in any computer language available. There are many activities to be done before and after writing code.

  5. Stages while solving a problem using computer 5 1. Problem Analysis 2. Algorithm Development 3. Flowcharting 4. Coding 5. Compilation and Execution 6. Debugging and Testing 7. Documentation

  6. Problem Analysis 6 Algorithm Development Flowcharting Program Coding Compilation and Execution Debugging and Testing Documentation Fig. Steps in problem solving

  7. Problem Analysis 7 Process of becoming familiar with the problem. We need to analyze and understand it well before solving. The user s requirements cannot be fulfilled without clear understanding of his/her problem in depth. Inadequate identification of problem may cause program less useful and insufficient. Example: Banking Solution, Hospital Medical Study

  8. Algorithm Development 8 Step By Step description of the method to solve a problem. Effective procedure for solving a problem in finite number of steps. Developing an algorithm is a step of program design.

  9. An algorithm to find sum of two numbers: 9 Step 1: Start Step 2: Assume two numbers x and y and a variable sum=0 Step 3: Add two numbers x and y; store the value in variable sum Step 4: If you want to try again with different numbers then goto step 2 else goto step 5 Step 5: END

  10. An algorithm to find sum of two numbers: 10 Step 1: Start Step 2: Declare variables num1, num2 and sum. Step 3: Read values num1 and num2. Step 4: Add num1 and num2 and assign the result to sum. sum num1+num2 Step 5: Display sum Step 6: Stop

  11. An algorithm to find largest of three different numbers: 11

  12. Three features of Algorithm Sequence Each step in the algorithm in executed in specified order. If not algorithm will fail. Decision We have to make decision to do something. If the outcome of the decision is true, one thing is done otherwise other. If condition then process1 OR If condition 12 then process1 Else process2 Repetition For example Repeat Fill Water in the kettle Until Kettle is full

  13. Flowcharting 13 Graphical representation of an algorithm using standard symbols. Includes a set of various standard shaped boxes that are interconnected by flow lines. Flow lines have arrows(direction of flow). Activities are written within boxes in English. Communicates between programmers and business persons.

  14. Advantages of Flowcharts 14 Communication Quickly provide logic, ideas and descriptions of algorithms. Effective Analysis Clear overview of the entire problem. Proper Documentation Documents the steps followed in an algorithm. Helps us understand its logic in future. Efficient Coding More ease with comprehensive flowchart as a guide Easy in debugging and program maintenance Debugging and maintenance of operating program

  15. Flowchart Symbols 15

  16. Things to consider 16 There should be start and stop to the flowchart. Only one flow line should emerge from a process symbol. Only one flow line should enter a decision symbol, but two or three flow lines can leave the decision symbol.

  17. Write an algorithm and draw flowchart for finding the sum of any two numbers. 17 Algorithm ------------- Step1: Start Step2: Display Enter two numbers . Step3: Read A and B Step4: C= A+B Step5: Display C as sum of two numbers Step6: Stop

  18. Flowchart 18 Start START Read two Numbers, A and B Input Processing C = A + B Output Display C as Sum of A and B End END

  19. Some questions for Assignment 19 Write an algorithm and draw flowchart to determine a number whether it is positive or negative. Write an algorithm and draw flowchart to test a number for even or odd. Write an algorithm and draw flowchart to find the largest number among three numbers.

  20. 20 Read N numbers from user and display sum of all entered numbers. For finding the sum of the series 1+2+3+4+ up to N terms For calculating the factorial of a given number N.

  21. Coding 21 The process of transforming the program logic design into computer language format. An act of transforming operations in each box of the flowchart in terms of the statement of the program. The code written using programming language is also known as source code. Coding isn t the only task to be done to solve a problem using computer. Anyone can code. TRUST ME!!

  22. Compilation 22 Process of changing high level language into machine level language. It is done by special software, COMPILER The compilation process tests the program whether it contains syntax errors or not. If syntax errors are present, compiler can not compile the code.

  23. Execution 23 Once the compilation is completed then the program is linked with other object programs needed for execution, there by resulting in a binary program and then the program is loaded in the memory for the purpose of execution and finally it is executed. The program may ask user for inputs and generates outputs after processing the inputs.

  24. Debugging and Testing 24 Debugging is the discovery and correction of programming errors. Some errors may remain in the program because the designer/programmer might have never thought about a particular case. When error appears debugging is necessary.

  25. Debugging and Testing 25 Testing ensures that program performs correctly the required task. Verification ensures that program does what the programmer intends to do. Validation ensures that the program produces the correct results for a set of test data. Test data are supplied to the program and output is observed. Expected output = Error free

  26. Program Documentation 26 Helps to those who use, maintain and extend the program in future. A program may be difficult to understand even to programmer who wrote the code after some days. Properly documented program is necessary which will be useful and efficient in debugging, testing, maintenance and redesign process.

  27. Two types of documentations 27 1. Programmer s Documentation (Technical Documentation) Maintain, redesign and upgrade Logic, DFD, E-R, algorithm and flowchart 2. User Documentation (User Manual) Support to the user of the program Instructions for installation of the program

  28. 28 Computer Program and Programming Language

  29. Computer Program 29 Set of instructions that causes to behave in predetermined manner. To instruct a computer to perform a certain job, we need languages, but not English or Nepali(!!!FOR NOW!!!). We need languages understood by the computer.

  30. Types or levels of Programming Languages 30 High Level Low-level Machine Level Assembly Level

  31. Low Level Language 31 Statement or instruction is directly translated into a single machine code. It is machine dependent, i.e. A particular low-level language works only for a certain machine.

  32. Machine-level Language 32 Language that a computer actually understands. 1 s and 0 s. Is a sequence of instructions written in the form of binary numbers consisting of 1 s and 0 s It executes fast as computer don t need any translation.

  33. To add two number in machine language: 33 11 10111001 110 3 machine code for addition (say) 6 It is difficult to remember different instructions for programming.

  34. Machine Level Language 34 ADVANTAGE Computer directly understands machine instructions Directly starts executing Takes less execution time DISADVANTAGE Difficult to use Machine dependent Difficult to Debug and modify

  35. Assembly Language Symbolic representation(mnemonics) of machine code. 35 Close to machine code but the computer cannot understand Must be translated into machine code by a separate program called an assembler. 11 ADD 110 Suppose ADD is mnemonic for addition

  36. Some examples of instructions for assembly languages are as follows: 36 CODE ADD SUB INR DCR CMP Meaning Addition Subtraction Increase Decrease Compare It is relatively easy for writing programs in assembly languages, but is slow in execution as it has to be converted into machine language before execution.

  37. Assembly language 37 Advantage More convenient than machine language Symbolic instructions Improved readability Disadvantage Hard to remember Mnemonics Machine dependent Less efficient than machine language Need fewer codes than high level language Embedded systems and device programming

  38. High Level Language 38 User friendly, Similar to natural languages Platform independent Easy to write or remember Easy to learn and work While execution: translated into assembly language then to machine language. Slow in execution but is efficient for developing programs. Ex: C, C++, Python, Java etc.

  39. High Level Language 39 Advantages Easy to use Portability Easy Debugging Easy and Fast Development of software Disadvantages More execution time Needs own translator

  40. Compiler 40 A high level source program must be translated into a form machine can understand. This done by software called the compiler. Source code => Machine language code(Object code) During the process of translation, the compiler reads the source programsstatement-wiseand checks for syntax errors. In case of any error, the computer generates message about the error. Ex: C, C++, Java, FORTRAN, pascal etc.

  41. Interpreter 41 Like compiler, it is also a translator which translates high level to machine level language. Translates and executes the program line by line. Each line is checked for syntax error and then converted to the equivalent machine code. Ex. QBASIC, PERL, PHP, ASP, PYTHON, RUBY

  42. Difference between compiler and interpreter Compiler Compiler scans the entire program before translating it into machine code 42 Interpreter Interpreter translates and executes the program line by line Syntax errors are found only after the compilation of complete programs Syntax errors can be trapped after translations of every line It takes less amount of time to analyze the source code but the overall execution time is slower. It takes large amount of time to analyze the source code but the overall execution time is comparatively faster. No intermediate object code is generated, hence are memory efficient. Generates intermediate object code which further requires linking, hence requires more memory.

  43. 43 Overview to C Programming

  44. We can assume C as middle level language 44 This doesn t mean C is less power full or harder to use or less developed. Instead C combines the advantages of high level language with the functionalism of assembly language. Like high level, C provides block structures, stand-alone functions and small amount of data typing. Like assembly language, it allows manipulations of bits, bytes, pointers and it is mostly used in system programming. Combination of two aspects.

  45. History of C programming language 45 C is a programming language which was born at AT & T s Bell Laboratory of USA in 1972. C was written by Dennis Ritchie, that s why he is also called as father of C programming language. C language was created for a specific purpose i.e. designing the UNIX operating system (which is currently base of many UNIX based OS). From the beginning, C was intended to be useful to allow busy programmers to get things done because C is such a powerful, dominant and supple language. It s use quickly spread beyond Bell Labs in the late 70 s

  46. Why use C? 47 Robust Language Efficient and fast Highly portable Structured Language Extendibility Middle level language Rich system library

  47. Executing a C Program 48

  48. Basic Structure of C Program 49

  49. 1. Documentation Section 50 Sets of comment line giving the name of program, the author, algorithms, methods used and other details. Acts as a communication between members of the development team. Acts as user manual. Ex /* This program adds two numbers */ /* . */ denotes comments in C

  50. 2. Link Section 51 - Provides Instructions to the compiler to link functions with program from the system library. #include<stdio.h> - Links input/output functions like printf() and scanf() with the program

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#