CH 1
CH 1
Credit hours :3
Year :II
S :-N.T
10/29/2024 Year 2017
Bridge International College
ASSESSMENT METHODS
Assignment 10%
Lab exam 20%
Test/mid semester exam 20%
Final exam 50%
10/29/2024
Bridge International College
Text book
Ravichandran,”problem solving with C++”Tata
Msc.Grew Hill Company.
References
Brian W.Kernighan,Dennis M. Ritchie, “The C
programming Language ”,Prentice Hall of India
Problem_Solving_with_C++_(9th_Savitch)
10/29/2024
Introduction
What is a Computer?
process data under the control of sets of instructions called computer programs
object-oriented programming .
10/29/2024 N.T
Some Terminology
Binary Digits (bit):- 1 and 0 .
The computer can combine the two digital states to represent letters, numbers, colors, sounds, images,
shapes, and even odors.
An “on” or “off” electronic state is represented by a bit, short for binary digit.
Encoding Systems: Bits and Bytes .
Bits are combined according to an encoding system to represent letters, numbers, and special characters,
collectively referred to as alphanumeric characters .
The combination of bits used to represent a character is called a byte (Binary Term, 8 bits/byte)
8 bits = 1byte •
Representation of a Character .
ASCII (American Standard Code for Information Interchange) is the most popular encoding system for PCs
and data communication
ASCII – 7 bits
ANSI – 8 bits/byte
UNICODE – 16 bits
Big5 – 16 bits
Storage Capacities
-
-
-
- 10/29/2024
Computer Organization
Five logical units in every computer:
1. Input Unit:-Obtains information from input devices (keyboard, mouse, scanner)
2. Output Unit :-Outputs information (to screen, to printer, to speakers, to projector, to
control other devices)
3. CPU (Central Processing Unit) .
Arithmetic and Logic Unit (ALU):- Performs arithmetic calculations and logic decisions.
Control Unit (CU) :-
o Execute programs/instructions.
o Supervises and coordinates the other sections of the computer.
o Move data from one memory location to another
4. Memory Unit :-Rapid access, low capacity, stores input and output information
5. Secondary Storage Unit • Cheap, long-term, high-capacity storage (e.g., Hard Disks,
Memory Sticks)
Stores inactive programs
10/29/2024
Machine Languages, Assembly Languages, and High-level Languages
Machine Language
10/29/2024
Problem Solving Techniques
10/29/2024
Problem Solving Techniques
10/29/2024
Algorithm, pseudo code and Flow Chart
Algorithm
A set of step-by-step instructions to accomplish a task.
In mathematics, computer science, and related subjects, an algorithm is a finite
sequence of steps expressed for solving a problem
A process that performs some sequence of operations in order to solve a given
problem
Algorithms are used for calculation, data processing, and many other fields.
In computing, algorithms are essential because they serve as the systematic
procedures that computers require.
10/29/2024
reasons for using algorithms
10/29/2024
Characteristics of algorithm
10/29/2024
Algorithm Example 1
1. Suppose you are given a set of 1. Start
mark sheets where each mark sheet 2. Take a mark sheet
bears A, B, C or F letter grades. • and read the grade.
Write an algorithm to read mark 3. Print the grade
sheet and print the grade that it 4. Stop
contains.
10/29/2024
Example 2
Suppose you are given a set of mark 1. Start
sheets where each mark sheet bears
2. Take a mark sheet and read the
A, B, C or F grades. Write an
grade.
algorithm to read a mark sheet and
3. If grade is A then Print the grade
print the grade if the grade is A only.
4. Stop
10/29/2024
Algorithm representation
A pseudo code
A flowchart
Programs statements in a programming language .
10/29/2024
Pseudo Code
Pseudo code is another program analysis tool that is used for planning program
logic.
"Pseudo" means imitation or false •
"Code" refers to the instructions written in a programming language.
Pseudo code, therefore, is an imitation of actual computer instructions.
These pseudo instructions are phrases written in ordinary natural language (e.g.,
English).
10/29/2024
Pseudo code Structure
Pseudo code is made up of the following basic logic structures that have
been proved to be sufficient for writing any computer program.
A. Sequence
10/29/2024
EX1:-Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.
10/29/2024
What is a Flowchart?
A flowchart is a diagram that depicts the “flow” of a program.
A Flowchart is a type of diagram (graphical or symbolic) that represents an
algorithm or process.
Each step in the process is represented by a different symbol and contains a
short description of the process step.
The flow chart symbols are linked together with arrows showing the
process flow direction.
A flowchart describes what operations (and in what sequence) are required
to solve a given problem.
A Flowchart
o shows logic of an algorithm
o emphasizes individual steps and their interconnections
o e.g. control flow from one action to the next
.
10/29/2024
Con’t
Flowcharts are used in:-
Analyzing,
Designing,
Documenting or managing a process or program in various fields.
Flowcharts are generally drawn in the early stages of formulating computer
solutions.
Flowcharts often facilitate communication between programmers and
business people.
These flowcharts play a vital role in the programming of a problem and are
quite helpful in understanding the logic of complicated and lengthy
problems.
Once the flowchart is drawn, it becomes easy to write the program in any
high level language.
10/29/2024
Flowchart Symbols & Guidelines:
Flowcharts are usually drawn using some standard symbols; however, some special
symbols can also be developed when required.
Some standard symbols, which are frequently required for flowcharting many
computer programs are shown.
Terminator: An oval flow chart shape indicates the start or end of the process, usually
containing the word “Start” or “End”.
10/29/2024
Con’t
Process: A rectangular flow chart shape indicates a normal/generic process flow
step.
For example, “Add 1 to X”, “M = M*F” or similar.
Decision: A diamond flow chart shape indicates a branch in the process flow.
This symbol is used when a decision needs to be made, commonly a Yes/No
question or True/False test.
10/29/2024
Con’t
Connector: A small, labelled, circular flow chart shape used to indicate a jump in the
process flow. Connectors are generally used in complex or multi-sheet diagrams.
Data: A parallelogram that indicates data input or output (I/O) for a process.
Examples: Get X from the user, Display X.
Delay: used to indicate a delay or wait in the process for input from some other process.
10/29/2024
Basic guidelines for drawing a flowchart with the symbols are that:
10/29/2024
Con’t
10/29/2024
Algorithm flowchart
1. Read A, B
2. If A is less than B
3. BIG=B
4. SMALL = A
5. Else BIG=A SMALL = B
6. Write (Display) BIG,
SMALL
Write algorithm and flowchart that display the largest number between A and B
10/29/2024
Algorithm flowchart
10/29/2024
EX1:-Draw an a flow chart to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four
marks.
Step 1: InputM1,M2,M3,M4 .
Step 2: GRADE
(M1+M2+M3+M4)/4
Step 3: if (GRADE < 50) then
Print “FAIL”
else
Print “PASS”
endif
Print
“Pass”
10/29/2024
EX2:-Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area.
.
STOP
10/29/2024
flow chart structure
.
. start
. Begin
Statement 1
Read birth date
Statement 2
Calculate
Age = current year – birth date
Statement 3
Display
age
:statement 4
End
end
10/29/2024
flow chart structure
.
. .
No Yes
Condition
else- then-
statement statement(s
(s) )
10/29/2024
flow chart structure
.
. .
ye Loop
Condition s Statement
(s)
no
10/29/2024
When to Use a Flowchart
To communicate to others how a process is done.
A flowchart is generally used when a new project begins in order to plan for the
project.
A flowchart helps to clarify how things are currently working and how they could
be improved.
It also assists in finding the key elements of a process, while drawing clear lines
between where one process ends and the next one starts.
Developing a flowchart stimulates communication among participants and
establishes a common understanding about the process. Flowcharts also uncover
steps that are redundant or misplaced.
Flowcharts are used to help team members, to identify who provides inputs or
resources to whom, to establish important areas for monitoring or data collection, to
identify areas for improvement or increased efficiency, and to generate hypotheses
about causes.
10/29/2024
Advantages of Using Flowcharts:
Communication: Flowcharts are better way of communicating the logic of a
system to all concerned.
Effective analysis: With the help of flowchart, problem can be analyzed in more
effective way.
Proper documentation: Program flowcharts serve as a good program
documentation, which is needed for various purposes.
Efficient Coding: The flowcharts act as a guide or blueprint during the systems
analysis and program development phase.
Proper Debugging: The flowchart helps in debugging process.
Efficient Program Maintenance: The maintenance of operating program becomes
easy with the help of flowchart. It helps the programmer to put efforts more
efficiently on that part.
10/29/2024
Limitations of Using Flowcharts:
Complex logic: Sometimes, the program logic is quite complicated. In that case,
flowchart becomes complex and clumsy.
Alterations and Modifications: If alterations are required the flowchart may
require re-drawing completely.
Reproduction: As the flowchart symbols cannot be typed, reproduction of
flowchart becomes a problem.
The essentials of what is done can easily be lost in the technical details of how it is
done.
10/29/2024
Exercise
1. Create an algorithm and a flowchart that will compute the sum of two numbers. If
the sum is below or equal to ten, two numbers will be entered again. If the sum is
above 10, it will display the sum.
2. Create an algorithm and a flowchart that will compute the area of a circle.
3. Create an algorithm and a flowchart that will output the factorial of a given number.
4. Create an algorithm and a flowchart that will output the Fibonacci series up to a
given number.
5. Create an algorithm and a flowchart that will output all the prime numbers less than
20.
6. Create algorithm and flow chart that display odd,even,prime number less than 50
7. write an algorithm that display the below structure using
iteration(for ,while,do..while)
x
x x
x x x
x x x x
x x x x x
10/29/2024