Sei sulla pagina 1di 96

CSEG1003 Programming for Problem Solving

CSEG1003 Programming for Problem


Solving

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

Road Map
• Generations of Computers and Languages

Introduction •

Organization of Computers
Number Systems Conversion
Logical Analysis and Thinking

• Structure of C Program & Compilation and Linking Process


C Programming • Variables and Datatypes
• Managing Input and Output statements
Basics • Decision and Looping Statements

• Creation and Usages


Arrays and • 1D and 2 D arrys
• String Functions
Strings • Matrix operations

• Declaration and Definitions of Functions


Functions and • Passing Arguments
• Recursion
Pointers • Pointers & Pointer Arithmetic

• Need of Structure and Unions


Structures and • Declaration and Definition
• Storage classes
Unions • Preprocessor Directives
CSEG1003 Programming for Problem
Solving

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

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

Abacus – Addition and Subtraction


CSEG1003 Programming for Problem Solving

Napier’s Bones - Multiplication


CSEG1003 Programming for Problem Solving

Steps……..Inventions

• Pascaline Machine
• Functional Automatic Calculator
• French Mathematician
• Blaise Pascal
• 1642
• gear-driven calculating machine
• Eight movable dials
CSEG1003 Programming for Problem Solving

Gear Engine
CSEG1003 Programming for Problem Solving
CSEG1003 Programming for Problem Solving

Steps……..Inventions

• Leibniz's Stepped Reckoner


• 1694
• German Mathemacian
• addition, subtraction, multiplication, and division

• Jacquard Powerloom
• 1801
• weave automatically
• read from punched wooden cards
CSEG1003 Programming for Problem Solving

Leibniz's Stepped Reckoned


CSEG1003 Programming for Problem Solving

Steps……..Inventions

• Jacquard Powerloom
• 1801
• weave automatically
• Programs punched in cards
• read from punched wooden cards
CSEG1003 Programming for Problem Solving

Jacquards Loom
CSEG1003 Programming for Problem Solving

Practical Jacquards Loom


CSEG1003 Programming for Problem Solving

Sample Punch card


CSEG1003 Programming for Problem Solving

Steps……..Inventions
• 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
CSEG1003 Programming for Problem Solving

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
CSEG1003 Programming for Problem Solving

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

Memory Tapes
CSEG1003 Programming for Problem Solving

MainFrame Computers – 1955 - US


CSEG1003 Programming for Problem Solving

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

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

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

Mini Comp. ---Apple1 -- $600 ---1976


CSEG1003 Programming for Problem Solving

IBM PC ---- 1990


CSEG1003 Programming for Problem Solving

Apple II
CSEG1003 Programming for Problem
Solving

GENERATION OF
COMPUTERS
CSEG1003 Programming for Problem Solving
CSEG1003 Programming for Problem Solving

First Generation
• 1940 – 1956
• Vaccum Tubes
• Machine Language
• Specification
• Vacuum tubes -> circuitry
• Magnetic drums -> memory
• Input ->punched cards and paper tape
• Output ->printouts
• Examples
• UNIVAC -U.S. Census Bureau in 1951
• ENIAC computers
• Disadvantage
• Expensive
• Huge conception of electricity
• Big & Clumsy
• Air conditioning Necessary
• Non portable
CSEG1003 Programming for Problem Solving
CSEG1003 Programming for Problem Solving

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
CSEG1003 Programming for Problem Solving

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
CSEG1003 Programming for Problem Solving

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
CSEG1003 Programming for Problem Solving

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
CSEG1003 Programming for Problem
Solving

CLASSIFICATION OF
COMPUTERS
CSEG1003 Programming for Problem Solving

Classification of Computers
Types of Computers

On the basis of On the basis of Size &


On the basis of Technology
Purpose Capacity

Special
Purpose Analog Super

General
Purpose Digital Main Frame

Hybrid Mini

Micro
CSEG1003 Programming for Problem Solving

Super Computers
CSEG1003 Programming for Problem Solving

Main Frame Computer


CSEG1003 Programming for Problem Solving

Mini Computers
CSEG1003 Programming for Problem Solving

Micro Computers
CSEG1003 Programming for Problem Solving

Generation of Programming Languages


CSEG1003 Programming for Problem Solving

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
CSEG1003 Programming for Problem
Solving

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

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

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

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

Binary Number System

• Base 2
• Valid digits - 0, 1
• Position
• least significant bit(LSB)
• most significant bit(MSB)
CSEG1003 Programming for Problem Solving

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

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

Decimal to < Binary|Octal|HexaDecimal >


CSEG1003 Programming for Problem Solving

Contd.
CSEG1003 Programming for Problem Solving

Contd.
CSEG1003 Programming for Problem Solving

< Binary|Octal|HexaDecimal > to Decimal


CSEG1003 Programming for Problem Solving

Some more conversions


CSEG1003 Programming for Problem Solving

Activity
Binary Decimal Octal HexaDecimal
6E7
92
12A
1010100101
745
679
1010101000
320
CSEG1003 Programming for Problem Solving

Lecture #4 Online Lecture


• Problem Solving Techniques
• Need for Logical Thinking and Design
• Algorithm
• Flowchart
• Psedocode
CSEG1003 Programming for Problem Solving
CSEG1003 Programming for Problem
Solving

LECTURE #5
PROBLEM SOLVING TECHNIQUES &
LOGICAL ANALYSIS AND THINKING

Instructor
Dhiviya Rose J . Asst. Prof. Senior Scale
School of Computer Science and Engineering | UPES
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


CSEG1003 Programming for Problem Solving

Software Development Method


Analysis & Design Plan It
Pre Programming Steps

algorithm flowchart pseudocode

Check it

Modify the solution if necessary

Coding -------Write Program with some Programming Language


C C++ Java ….

Execute & Test


Finally, the program is tested to verify that it behaves as intended.
CSEG1003 Programming for Problem Solving

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

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

• 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)
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


CSEG1003 Programming for Problem Solving
CSEG1003 Programming for Problem Solving

Flowchart

• It is another way to display the algorithm.

• Diagram representation –

• special geometric symbols connected by lines and contain


the instructions.
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


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


CSEG1003 Programming for Problem Solving
CSEG1003 Programming for Problem Solving

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

Sequential Logic Structure


CSEG1003 Programming for Problem Solving

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

Decision Logic Structure


CSEG1003 Programming for Problem Solving

Example:1
CSEG1003 Programming for Problem Solving
CSEG1003 Programming for Problem Solving

The Loop Logic Structure


• Repeat structure
• To solve the problem that doing the same task over and
over for different sets of data
• Important Concern – Counter Management
• Counter Initialization (eg. i=0)
• Counter Increment / Decrement (eg. i++,i--)
• Counter Condition Check (eg. i<5)
• Types of loop:
• WHILE loop
• Do..WHILE loop
• Automatic-Counter Loop
CSEG1003 Programming for Problem Solving

Types of Loop – Pre and Post Condition


Check
CSEG1003 Programming for Problem Solving

One Minute Drill

1.Find the counter


variable
2. Find the counter
increment
3. Find out the
counter condition
4.Find the loop
statement
5. Guess the output
CSEG1003 Programming for Problem Solving

Example : Print Hello 5 times

• Case 1: i=0, ?????

• Case 2: i=10 ?????


CSEG1003 Programming for Problem Solving

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

Case Logic Structure


CSEG1003 Programming for Problem Solving
CSEG1003 Programming for Problem Solving

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
CSEG1003 Programming for Problem Solving

Example 2 : Sum of 5 numbers


CSEG1003 Programming for Problem Solving

Practice Activities
• Given 2 numbers. Calculate sum, difference, multiplication
and division.
• Finding the Area of Rectangle
• Finding the biggest of 3 numbers
• Finding the simple interest for the given P, T, R values.
• To swap two numbers
• Find whether a given number is even or odd.
• Check if the given number is divisible by 2 and 3 or not.
• Check whether a given character is an alphabet, digit or
special character.
CSEG1003 Programming for Problem Solving

Example: Biggest of 3 numbers


CSEG1003 Programming for Problem Solving
CSEG1003 Programming for Problem Solving

Potrebbero piacerti anche