2. CSEG 1003
Programming for
Problem Solving
Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
CSEG1003 Programming for Problem
Solving
3. Road Map
• Generations of Computers and Languages
• Organization of Computers
• Number Systems Conversion
• Logical Analysis and Thinking
Introduction
• Structure of C Program & Compilation and Linking Process
• Variables and Datatypes
• Managing Input and Output statements
• Decision and Looping Statements
C Programming
Basics
• Creation and Usages
• 1D and 2 D arrys
• String Functions
• Matrix operations
Arrays and
Strings
• Declaration and Definitions of Functions
• Passing Arguments
• Recursion
• Pointers & Pointer Arithmetic
Functions and
Pointers
• Need of Structure and Unions
• Declaration and Definition
• Storage classes
• Preprocessor Directives
Structures and
Unions
CSEG1003 Programming for Problem Solving
4. LECTURE #1
EVOLUTION ,GENERATION OF COMPUTERS &
CLASSIFICATION OF COMPUTERS
Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
CSEG1003 Programming for Problem
Solving
5. History
• Abacus
• Sliding Beads on a rack
• Counting purpose
• Operators on addition and subtraction
• 300 B.C.
• Napier Bones
• Logarithmic value carved on ivory sticks
• Scotsman ->John Napier
• 1617
CSEG1003 Programming for Problem Solving
6. Abacus – Addition and Subtraction
CSEG1003 Programming for Problem Solving
7. Napier’s Bones - Multiplication
CSEG1003 Programming for Problem Solving
8. Steps……..Inventions
• Pascaline Machine
• Functional Automatic Calculator
• French Mathematician
• Blaise Pascal
• 1642
• gear-driven calculating machine
• Eight movable dials
CSEG1003 Programming for Problem Solving
17. • Differential Engine
• Charles Babbage – Father of Computers
• English Mathematician
• 1822
• First Computer
• Basic calc+ Log + Differential equation
• Steam Driven machine
• Single Stored program in Memory
• Memory + Central Processing Unit
• Punch Cards as memory
Steps……..Inventions
CSEG1003 Programming for Problem Solving
18. Steps……..Inventions
• Analytical Engine
• Charles Babbage
• 1833
• Fully functional
• differential engine
• Contains
• Input device as cards
• Control unit
• Output device
CSEG1003 Programming for Problem Solving
20. Steps…Inventions
• Hollerith Tabulator
• Herman Hollerith
• 1889
• U.S Census Bureau
• Official Purpose
• Punch cards
• store data
• Used Electricity
• Later IBM
• Mainframe+OS
• OS/2 -> OS with
windows
CSEG1003 Programming for Problem Solving
23. Steps……..Inventions
• Mark 1
• 1944
• IBM + Harvard Aiken
• Replaces the mechanical component
• Relays
• Electro magnetic component
• ENIAC
• 1946
• John Eckert and John Mauchly
• Electronic Numerical Integrator And Calculator
• Electronic Vaccum Tubes
CSEG1003 Programming for Problem Solving
24. Steps……..Inventions
• EDVAC
• Electronic Discrete Variable Automatic Computer
• John Eckert and John Mauchly
• Capability to stop and resume
• EDSAC
• Electronic Delay Storage Automatic Calculator
• 1949
• Maurice Wilkes
• Mercury delay lines – memory
• Vacuum tubes --- logic
CSEG1003 Programming for Problem Solving
25. Steps……..Inventions
• UNIVAC
• Universal Automatic Compute
• 1951
• Beginning of computer era
• John Eckert and John Mauchly
• 1970
• Integrated Circuits
• Replaces vaccum tubes
• 1980
• Very Large Scale Integration (VLSI)
CSEG1003 Programming for Problem Solving
33. Second Generation
• 1956 - 1963
• Transistor
• used to relay and switch electronic signals
• Assembly language
• Specification
• punched cards for input
• printouts for output
• Transistor for circuits
• magnetic core technology for memory
• Computers smaller, faster, cheaper, portable and
more energy-efficient and need air conditioning.
CSEG1003 Programming for Problem Solving
35. Third Generations
• 1964 – 1970
• Integrated Circuits
• Transistors were miniaturized and placed on silicon chips called
semiconductors
• High Level Language
• Specifications
• Keyboard as input
• Monitor as output
• Operating System
• Central program that controls the devices
• Advantages
• Speed
• Efficiency
• Portable
• Cheap
• Less power
CSEG1003 Programming for Problem Solving
37. Fourth Generation
• 1970 – Present
• Data Communication
• Microprocessors
• thousands of integrated circuits were built onto a single silicon chip
• Properties
• Instruction set
• Bandwidth
• Clock Speed
• Example
• Intel 4004 chip – minuscule chip(cpu+ memory+ i/p+ o/p unit)
• 1984 Apple introduced the Macintosh
• Specification
• Microprocessor
• Mouse and other handheld devices
• CPU and ALU
• RAID – Redundant array of Independent Disk for memory
CSEG1003 Programming for Problem Solving
39. Fifth Generation
• Present and Beyond
• Artificial Intelligence
• Game Playing
• Expert System
• Robotics
• Mega chips
• Parallel processing
• Voice Recognition
• Example
• No fully AI computers
• 1997, an IBM super-computer called Deep Blue defeated world
chess champion Gary Kasparov in a chess
CSEG1003 Programming for Problem Solving
42. Classification of Computers
Types of Computers
On the basis of
Purpose
Special
Purpose
General
Purpose
On the basis of Technology
Analog
Digital
Hybrid
On the basis of Size &
Capacity
Super
Main Frame
Mini
Micro
CSEG1003 Programming for Problem Solving
48. Next Lecture #2…….Online Lecture
•Organization of Computers
• Hardware
• Input Unit
• Output Unit
• Storage Unit
• Processing Unit
• Software
• System Software
• Application Software
CSEG1003 Programming for Problem Solving
50. LECTURE #3
NUMBER SYSTEM CONVERSION PROBLEMS
Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
CSEG1003 Programming for Problem
Solving
51. Why number system conversion problems
• For digital hardware, the natural numbering system is
binary (base 2).
• Expressing anything in binary causes way too many bits
to be used
• hexadecimal allows us to use 4x fewer bits, so, it is very
useful.
CSEG1003 Programming for Problem Solving
52. Two Major classifications
• Non positional Number System
• Roman Numbering (………I,II,III,IV……..)
• Collection of symbols
• Counting the figures
• Difficult with large numbers
• Positional Number System
• Uses digits instead of symbols
• Digits positions are accounted
• 3 terminology
• Digit (set of symbols)
• Position of digit (LSB, MSB, unit, tens, hundred…)
• Base or radix(total no of digits)
CSEG1003 Programming for Problem Solving
53. Decimal Number System
• Base 10
• Valid digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
• Position
• unit
• ten
• hundred
• thousand
CSEG1003 Programming for Problem Solving
54. Binary Number System
• Base 2
• Valid digits - 0, 1
• Position
• least significant bit(LSB)
• most significant bit(MSB)
CSEG1003 Programming for Problem Solving
55. Octal Number System
• Base 8
• Valid digits - 0, 1, 2, 3, 4, 5, 6, 7
• Position
• least significant bit(LSB)
• most significant bit(MSB)
CSEG1003 Programming for Problem Solving
56. HexaDecimal Number System
• Base 16
• valid digits - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
• A refers to decimal 10, B refers to decimal 11, etc.
• Fig. The list of digits in each Number System
CSEG1003 Programming for Problem Solving
57. Decimal to < Binary|Octal|HexaDecimal >
CSEG1003 Programming for Problem Solving
62. Activity
Binary Decimal Octal HexaDecimal
6E7
92
12A
1010100101
745
679
1010101000
320
CSEG1003 Programming for Problem Solving
63. Pseudocode
• Writing the Pseudocode
• Pseudocode means an imitation computer code.
• It is used in place of symbols or a flowchart to describe
the logic of a program. Thus, it is a set of instructions
(descriptive form) to describe the logic of a program.
• Pseudocode is close to the actual programming
language.
• Using the Pseudocode, the programmer can start to
write the actual code.
CSEG1003 Programming for Problem Solving
64. Lecture #4 Online Lecture
• Problem Solving Techniques
• Need for Logical Thinking and Design
• Algorithm
• Flowchart
• Psedocode
CSEG1003 Programming for Problem Solving
66. LECTURE #5
PROBLEM SOLVING TECHNIQUES &
LOGICALANALYSISAND THINKING
Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
CSEG1003 Programming for Problem
Solving
67. How to solve a problem?
• Programming is a problem-solving activity.
• Problem-solving methods are covered in many subject
areas:
• Business students learn to solve problems with a systems approach
• Engineering and Science students use the engineering and science
methods
• Programmers use the Software Development Method
68. Software Development Method
Execute & Test
Finally, the program is tested to verify that it behaves as intended.
Coding -------Write Program with some Programming Language
C C++ Java ….
Modify the solution if necessary
Check it
Analysis & Design Plan It
algorithm flowchart pseudocode
PreProgrammingSteps
CSEG1003 Programming for Problem Solving
69. Introduction to Algorithms
• The algorithm is the abstract idea of solving a problem.
• The algorithm is written in user language
CSEG1003 Programming for Problem Solving
70. Algorithms vs. programs
• When an algorithm is coded using any programming
language (e.g. C++), then it is called a program.
• The program is a set of instructions that can run by the
computer.
CSEG1003 Programming for Problem Solving
71. • The algorithm would consist of at least the
following tasks:
1- Input (Read the data)
2- Processing (Perform the computation)
3- Output (Display the results)
CSEG1003 Programming for Problem Solving
72. Example 1
• Write a algorithm to find an area of a circle where area = pi
* radius * radius
Data Processing Output
radius area = 3.14 x radius x radius area
CSEG1003 Programming for Problem Solving
74. Flowchart
• It is another way to display the algorithm.
• Diagram representation –
• special geometric symbols connected by lines and contain
the instructions.
CSEG1003 Programming for Problem Solving
75. Flowchart Symbols
Symbol Function
Show the direction of data flow or logical
solution.
Indicate the beginning and ending of a set of
actions or instructions (logical flow) of a module
or program.
Indicate a process, such as calculations,
opening and closing files.
CSEG1003 Programming for Problem Solving
76. Indicate input to the program and output from the
program.
Use for making decision. Either True or False based
on certain condition.
Use for doing a repetition or looping of certain steps.
Connection of flowchart on the same page.
Connection of flowchart from page to page.
CSEG1003 Programming for Problem Solving
78. Structuring a Program
• Develop efficient computer solution to problems:
1. Use Modules
2. Use four logic structures
a. Sequential structure
• Executes instructions one after another in a sequence.
b. Decision structure
• Branches to execute one of two possible sets of instructions.
c. Loop structure
• Executes set of instruction many times.
d. Case structure
• Executes one set of instructions out of several sets.
3. Eliminate rewriting of identical process by using modules.
4. Use techniques to improve readability including four logic
structure, proper naming of variables, internal documentation
and proper indentation.
CSEG1003 Programming for Problem Solving
80. The Decision Logic Structure
• Implements using the IF/THEN/ELSE instruction.
• Tells the computer that IF a condition is true, THEN
execute a set of instructions, or ELSE execute another set
of instructions
• ELSE part is optional, as there is not always a set of
instructions if the conditions are false.
• Algorithm:
IF <condition(s)> THEN
<TRUE instruction(s)>
ELSE
<FALSE instruction(s)
CSEG1003 Programming for Problem Solving
84. The Loop Logic Structure
• Repeat structure
• To solve the problem that doing the same task over and
over for different sets of data
• Types of loop:
• WHILE loop
• Do..WHILE loop
• Automatic-Counter Loop
CSEG1003 Programming for Problem Solving
87. The Case Logic Structure
• Made up of several or many sets of instructions, only one
of which will be selected by the user and executed by the
computer
• Algorithm:
CASE OF VARIABLE
= constant1:
actions for VARIABLE = constant1
= constants2:
actions for VARIABLE = constant2
…
OTHERWISE:
Actions for VARIABLE = anything else
END-OF-CASE
CSEG1003 Programming for Problem Solving
90. Pseudocode
• Pseudocode means an imitation computer code.
• Pseudocode is close to the actual programming
language.
• Using the Pseudocode, the programmer can start
to write the actual code.
• Psedocode Programming Constructs includes
• READ, PRINT, SET , INITIALIZE
• INCREMENT,DECREMENT,
• IF…THEN….ENDIF,IF….THEN….ELSE….ENDIF,
• REPEAT ….UNTILL, DO…WHILE
CSEG1003 Programming for Problem Solving