0% found this document useful (0 votes)
2 views

Unit I LectureNotes

The document outlines the curriculum for a Programming for Problem Solving (PPS) course, covering key topics such as computer system components, algorithms, program development cycles, and high-quality programming practices. It includes course objectives, outcomes, and prerequisites, as well as detailed content for each unit, ranging from basic programming concepts to system design and integration. Textbooks and references for further reading are also provided.

Uploaded by

Vrinda Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Unit I LectureNotes

The document outlines the curriculum for a Programming for Problem Solving (PPS) course, covering key topics such as computer system components, algorithms, program development cycles, and high-quality programming practices. It includes course objectives, outcomes, and prerequisites, as well as detailed content for each unit, ranging from basic programming concepts to system design and integration. Textbooks and references for further reading are also provided.

Uploaded by

Vrinda Patil
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 79

Programming for Problem Solving (PPS)

17BEC104: Programming for Problem Solving (PPS)


▶ Continuous Assessment : 40 Marks Final Exam : 60 Marks No. of Total Lectures :

Unit I Introduction to Programming


Introduction to components of a computer system (disks, memory, processor, where a program is stored and executed, operating system,
compilers etc.).
Idea of Algorithm: steps to solve logical and numerical problems. Representation of Algorithm: Flowchart/Pseudocode with examples.
From algorithms to programs; source code, variables (with data types) variables and memory locations, How a Program Works, Input-
Processing –Output.

Unit II Program Development Cycle


Understanding the Problem, Planning the Logic, Coding the Program, Translate into Machine Language (difference between compiler and
interpreter)- Syntax and Logical Errors in compilation, object and executable code, Test the Program, Publishing & Maintaining the Program,

Unit III Elements of High-Quality Programs


Datatypes and Variables, Operators, Features of Good Program, Using Comments, Choosing Identifiers, Writing Prompts & Echoing Inputs,
Design Clear Statements, Good Housekeeping and EndOfTask, Using Proper Indentation, decision and repetition structures

Unit IV Modules
An Overview of Modules, Benefits of Modularisation, Modules in Flowchart, Modules in Pseudocode, Arrays, Structures, Introduction to
pointers, Advanced Modularisation: Passing Data to Modules, Module Returning a Value, Variable Types & Scopes, Passing Arrays to
Modules, Module Overloading, In-built or Pre-written Modules, Recursion

Unit V System- Design and Integration


Introduction to file handling, Use Case Modelling, User Interface Design, Event handling, integrating front end and back end.
17BEC104: Programming for Problem Solving (PPS)

Text Books:
1. Brian W. Kernighan, Dennis M. Ritchie, “The C Programming Language”, Prentice Hall, ISBN
0131103628, Second Edition.
2. E. Balguruswamy, “Programming in ANSI C”, Tata Mc-Graw Hill

References:
1. Joyce Farell, “Programming Logic and Design- Comprehensive”, Sixth Edition, Cengage Learning.

2. Tony Gaddis, “Programming Logic & Design”, Third Edition, Pearson Education.
3. Herbert Schildt, “C – The Complete Reference”, Tata McGraw Hill Publishing Company,Fourth Edition,New
Delhi, 2010.
4. Deitel and Deitel, “C How to Program”, Pearson Education, sixth Edition, New Delhi, 2011.
Course Objectives

▶ To develop abilities to understand computer system and algorithmic requirements.


▶ To learn the fundamental programming concepts and methodologies which are essential to build good
programs.
▶ To develop an ability to write a computer program with reusable modules for solving specific
problems.
▶ To learn the good practices to build a robust program.
Course Outcomes

▶ Students will be able to understand the programming tasks using concepts learned and write pseudo-code.

▶ Students will be able to use pseudo-code and visual modeling to prepare clear and accurate program

documentation and models.

▶ Students will be able to identify concepts applicability and apply them to write optimized programs, and hence

use computers effectively to solve the task.

▶ Students will be able to use common developer tools effectively and implement best practices to write

professional-quality code.
Prerequisites of the course

▶ Basic knowledge of computer, software and programming language.


Unit I Introduction to Programming

Introduction to components of a computer system (disks, memory, processor, where a program is stored and
executed, operating system, compilers etc.). Idea of Algorithm: steps to solve logical and numerical problems.
Representation of Algorithm: Flowchart/Pseudocode with examples. From algorithms to programs; source code,
variables (with data types) variables and memory locations, How a Program Works, Input- Processing –Output.
Contents
▶ Introduction to Components of Computer System
◦ disks, memory, processor, operating system, compiler

▶ Idea of Algorithm
◦ steps to solve logical and numerical problems
◦ Representation of Algorithm: Flowchart/Pseudocode with examples

▶ From algorithms to programs


◦ source code, variables (with data types) variables and memory locations
◦ How a Program Works, Input- Processing –Output.
Computers

Ø A computer is an electronic machine, devised for performing calculations and


controlling operations that can be expressed either in logical or numerical terms.

Ø In simple words, a computer is an electronic device that performs diverse


operations with the help of instructions to process the data in order to achieve
desired results.
GENERATIONS OF COMPUTERS
1. FIRST GENERATION (1940–56): VACUUM TUBES
➢ machine language (language of 0s and 1s)
➢ i/p: punched cards and paper tape
➢ o/p: printouts

Examples: ENIAC, EDVAC, and UNIVAC.

1. SECOND GENERATION (1956–63): TRANSISTORS


➢ Assembly language used mnemonics
➢ transistor is a small device, the physical size of computers was greatly reduced
➢ magnetic cores were used as primary memory and magnetic disks as secondary storage devices.
➢ i/p: punched cards and paper tape
➢ o/p: printouts

Examples: PDP-8, IBM 1401 and IBM 7090.


GENERATIONS OF COMPUTERS
3. THIRD GENERATION (1964–EARLY 1970S): INTEGRATED CIRCUITS

➢ High-level languages
➢ smaller in size, reliable, and efficient
➢ keyboards and monitors and interfaced with operating system

Examples: NCR 395 and B6500.

4. FOURTH GENERATION (EARLY 1970S–TILL DATE): MICROPROCESSORS

➢ powerful, compact, reliable, and affordable


➢ personal computer (PC) revolution
➢ magnetic core memories were substituted by semiconductor memories (RAM)
➢ secondary memories such as hard disks

Examples: Apple II, Altair 8800, and CRAY-1.


GENERATIONS OF COMPUTERS

5. FIFTH GENERATION (PRESENT AND BEYOND): ARTIFICIAL INTELLIGENCE

➢ The dream of creating a human-like computer that would be capable of reasoning and reaching a decision
through a series of “what-if-then” analyses
➢ The starting point for the fifth generation of computers has been set in the early 1990s still in the
development stage
➢ Three characteristics:
○ Mega Chips
○ Parallel Processing
○ Artificial Intelligence
CLASSIFICATION OF COMPUTERS
CLASSIFICATION ACCORDING TO FUNCTIONALITY
1. Micro Computers
➢ a small, low cost digital computer, consists of a microprocessor, a storage unit, an input channel, and
an output channel, all of which may be on one chip inserted into one or several PC boards.

➢ include desktop, laptop, and hand-held computers(Personal Digital Assistant (PDA))


CLASSIFICATION ACCORDING TO FUNCTIONALITY

2. Mini Computers

➢ sometimes called a mid-range computer


➢ supporting from 4 to about 200 simultaneous users
➢ interactive applications in industries, research organisations, colleges, and universities

Examples: PDP 11, IBM (8000 series), and VAX 7500

3. Mainframe Computers

➢ ultra-high performance computer


➢ supporting large volumes of data processing, high performance on-line transaction processing systems, and
extensive data storage and retrieval
➢ second largest of the computer family

Examples: IBM's ES000, VAX 8000, and CDC 6600


CLASSIFICATION ACCORDING TO FUNCTIONALITY

4. Super Computers

➢ highest processing speed at a given time for solving scientific and engineering problems
➢ contains a number of CPUs that operate in parallel to make it faster
➢ processing speed lies in the range of 400–10,000 MFLOPS (Millions of Floating Point Operation Per
Second)
➢ fastest, costliest and most powerful computers
➢ Largest commercial uses is in entertainment/advertising industry

Examples of super computers are CRAY–3, Cyber 205, and PARAM.


Supercomputers
Look inside the computer

SOFTWARE User

Softwar
e
HARDWARE

Hardware

A User interacts with Software which interacts


with hardware to get the actual work done.
Hardware
▶ Hardware represents the physical and tangible components of a computer, i.e. the components that can
be seen and touched.

▶ Examples of Hardware are the following −


▶ Input devices − keyboard, mouse, etc.
▶ Output devices − printer, monitor, etc.
▶ Secondary storage devices − Hard disk, CD, DVD, etc.
▶ Internal components − CPU, motherboard, RAM, etc.
▶ The basic parts of a desktop computer:
- Computer case
- Monitor
- Keyboard
- Mouse

Each part plays an important role whenever you use a computer.

https://www.youtube.com/watch?v=X5wAfklIW24
Computer = Human Body?

How is a computer similar to the human body?


➢ Parts of a Computer
- Motherboard
- central processing unit (CPU)
- power
- random access memory (RAM)
- hard drive
- expansion slots
Software
▶ Software is a set of programs, which is designed to perform a well-defined function. A program is a
sequence of instructions written to solve a particular problem.

▶ There are two types of software −


▶ System Software
▶ Application Software
The image cannot be displayed. Your computer may not have enough memory to open the image, or the image may have been corrupted. Restart your computer, and then open the file again. If the red x still appears, you may have to delete the image and then insert it again.
Computer System Architecture
Computer System Architecture

▶ 1. Input unit.
▶ 2. Output unit.

▶ 3. Memory unit.

▶ 4. Arithmetic and logic unit (ALU).

▶ 5. Control Unit.
System and Application Software:
Introduction to System Software

▶ A program, such as the operating system, that control the operation of a computer
and its devices, as well as enable application software to run on the computer.
▶ A type of software that performs a specific task, usually related to managing or
maintaining a computer system.
Basics of Operating System:

▶ Definition

An operating system is a program that acts as an interface between the user and the computer hardware
and controls the execution of all kinds of programs.

Operating System (OS) is :

-A software.

-It performs all the basic tasks like file management, memory management, process management,
handling input and output, and controlling peripheral devices such as disk drives and printers.
E.g. UNIX, Windows etc
Group Discussion
▶ Windows Vs Linux : Discuss pros and cons of both operating systems.
Q&A
▶ Which software is more closer to hardware and which software is more closer to the user?

1. Application s/w is closer hardware and System s/w is closer to user.

2. Both are close to user.

3. Application s/w is closer user and System s/w is closer to hardware.


4. None of above.
Contents
▶ Introduction to Components of Computer System
◦ disks, memory, processor, operating system, compilers

▶ Idea of Algorithm

◦ steps to solve logical and numerical problems

◦ Representation of Algorithm: Flowchart/Pseudocode with examples

▶ From algorithms to programs

◦ source code, variables (with data types) variables and memory locations

◦ How a Program Works, Input- Processing –Output.


Program Planning Tools

➢ Algorithm

➢ Flow Chart
➢ Pseudo Code
Algorithm

Definition:
An algorithm is a procedure or formula for solving a problem, based
on conducting a sequence of specified actions.

A procedure for solving a problem in terms of


1. the actions to be executed
2. the order in which these actions are to be executed
is called an algorithm
Characteristics of an Algorithm
Ø should be precise and unambiguous
Ø should be executed in a finite time (definiteness)
Ø should not be repeated infinitely, algorithm will ultimately terminate.
Ø desired results are obtained (effectiveness)
Ø must have start and stop steps (finiteness)
Algorithm
Example:
— Algorithm to add two given numbers:
step 1: START
step 2: Read two numbers A and B
step 3: Add numbers A and B and store result in C
step 4: Display C
step 5: STOP

This routine gets the executive to work well prepared to make critical decisions.
Specifying the order in which statements are to be executed in a computer program is
called algorithm.
Algorithm for Weekly Pay
1.Start
2.Declare two variables hourly_rate and no_of_hours.
3.Enter values for hourly_rate and no_of_hours.
4.If no_of_hours is less than or equal to 50 then perform multiplication of two
variables.
Else multiply 50 and hourly_rate.
5. Display result.
6.Stop
Different Ways to Represent an Algorithm
Ø as a flowchart
Ø as a pseudocode
Ø as a program
Flow Chart
Definition:
Flowchart is a graphical tool that diagrammatically depicts the steps
and structure of an algorithm or program.

▶ It is a graphical representation of an algorithm.


▶ They are drawn using certain special-purpose symbols .

▶ They are useful for developing and representing algorithms

▶ It is preferred by most programmers.

▶ Flowcharts clearly show how control structures operate.


Flow Chart
Role Play/ Brainstorming
▶ We require
◦ 2 people for start and end box
◦ 3 people for statement box
◦ 1 people for condition box
◦ 2 people for input and output box
Flow chart of weekly pay
Start

Declare Two variables hourly_pay and


no_of_hours

Enter values for two


variables

YES NO
If no_of_hours
<=50

Multiply hourly_pay and


Multiply 50 and no_of_hours
no_of_hours

Display Result

End
Question

▶ What is Algorithm?
▶ Which is not symbol of Flow Chart?
Pseudo code
Definition:
Pseudo code is an informal way of describing a program's functions. It
consists of natural language like statements that precisely describe the steps
of an algorithm or program.
OR
Pseudo code simply means “false code” or sentences that appear to have been
written in a computer programming language but do not necessarily follow
all the syntax rules of any specific language.

▶ Itconsists only of action Statements.


▶ Definitions are not executable statements.
Pseudo code

▶ Artificial and informal language that helps you develop pseudocode.


▶ Similar to everyday English; it’s convenient.
▶ Consists purely of characters, so you may conveniently type pseudo code programs
into a computer using an editor program.
▶ A carefully prepared, pseudo code may be converted easily to a corresponding C
program.
▶ Pseudo code is fairly flexible because it is a planning tool and not a final
product.
Pseudocode for weekly pay
Prompt & get hourly pay rate & # of hours
IF hours <= 50
pay = hours * payRate;
ELSE
pay = 50 * payRate;
ENDIF
output weekly pay
Example
▶ Which is the critical component of computer system?
▶ What is the name of program that controls the computer system?
▶ What do you mean by Boot Code?
Contents

▶ Introduction to Components of Computer System


◦ disks, memory, processor, operating system, compilers

▶ Idea of Algorithm

◦ steps to solve logical and numerical problems

◦ Representation of Algorithm: Flowchart/Pseudocode with examples

▶ From algorithms to programs

◦ source code, variables (with data types) variables and memory locations

◦ How a Program Works, Input- Processing –Output.


Algorithm to Source code

Algorithm Source Code in C

Step 1: START Void main()


Step 2: Display {
“Welcome” Printf(“Welcome”);
Step 3: STOP }
Algorithm Source Code in C

Algorithm to add two given Void main()


numbers:
{
step 1: START
int num1, num2, res;
step 2: Read two numbers num1
scanf(“%d%d”,&num1,&num2);
and num2
res=num1+num2;
step 3: Add numbers num1 and
num2 and store result in res printf(“Addition=%d”,res);
step 4: Display res }
step 5: STOP
Tokens
▶ Identifiers
▶ Keywords
▶ Constants
▶ String literals
▶ Operators
▶ Separators
Keywords in C
Variables
▶ Programs use variables to store data in memory.
▶ A variable is a storage location in memory that is represented by a name.

▶ For example, a program that calculates the


sales tax on a purchase might use a variable
named tax to hold that value in memory.
▶ And a program that calculates the distance
from Earth to a distant star might use a
variable named distance to hold that value
in memory.
Variables
Variables
Local  and  Global  variables
Local  variables:    
Variable   whose   existence   is   known   only   to   the   main   program   or  
functions  are  called  local  variables.  Local  variables  are  declared  with  in  
the  main  program  or  a  function.  Default  value  is  garbage.  
 
Global  variables:    
Variables   whose   existence   is   known   to   the   both   main()   as   well   as  
other   functions   are   called   global   variables.   Global   variables   are  
declared  outside  the  main()  and  other  functions.  Default  value  is  zero.  
How to make a variable value constant?
1. const data type <<name>>=value;
OR
2. Use # define preprocessor directive
#define <<name>> value
Data Types
Basic data types in C  
▶ Integer  data  type  allows  a  variable     to  store  numeric  values.  
▶ “int”  keyword  is  used  to  refer  integer  data  type.  
▶ The  storage  size  of  int  data  type  is  2  or  4  or  8  byte.  
▶ It  varies  depend  upon  the  processor  in  the  CPU  that  we  use.    If  we  are  
using  16  bit  processor,  2  byte    (16  bit)  of  memory  will  be  allocated  for  
int  data  type.  
▶ Like  wise,  4  byte  (32  bit)  of  memory  for  32  bit  processor  and  8  byte  (64  
bit)  of  memory  for  64  bit  processor  is  allocated  for  int  datatype.  
▶ int  (2  byte)  can  store  values  from  -­‐32,768  to  +32,767  
▶ int  (4  byte)  can  store  values  from  -­‐2,147,483,648  to  +2,147,483,647.  
▶ If  you  want  to  use  the  integer  value  that  crosses  the  above  limit,  you  can  
go  for  “long  int”  and  “long  long  int”  for  which  the  limits  are  very  high.  
Character data type:  
 
▶ Character  data  type  allows  a  variable  to  store  only  one  character.  
▶ Storage   size   of   character   data   type   is   1.   We   can   store   only   one  
character  using  character  data  type.  
▶ “char”  keyword  is  used  to  refer  character  data  type.  
▶ For   example,   ‘A’   can   be   stored   using   char   datatype.   You   can’t   store  
more  than  one  character  using  char  data  type.  
▶ Please   refer   C   –   Strings   topic   to   know   how   to   store   more   than   one  
characters  in  a  variable.  
Character Set
▶ A-Z
▶ a -z
▶ 0-9
▶ space . , : ; ' $ "
▶ # % & ! _ {} [] () $$$$ &&&& |
▶ +-/*=
Floating point data type:  
 
▶ Floating  point  data  type  consists  of  2  types.  They  are,  
◦ Zloat  
◦ double  
▶ 1.  @loat:  
▶ Float  data  type  allows  a  variable  to  store  decimal  values.  
▶ Storage   size   of   Zloat   data   type   is   4.   This   also   varies   depend   upon   the  
processor  in  the  CPU  as  “int”  data  type.  
▶ We  can  use  up-­‐to  6  digits  after  decimal  using  Zloat  data  type.  
▶ For  example,  10.456789  can  be  stored  in  a  variable  using  Zloat  data  type.  
▶ 2.  double:  
▶ Double  data  type  is  also  same  as  Zloat  data  type  which  allows  up-­‐to  10  digits  
after  decimal.  
▶ The  range  for  double  datatype  is  from  1E–37  to  1E+37.  
Memory Unit
Memory

Secondary (External)
Primary (Internal) Memory
Memory

ROM RAM Egs. :


Floppy Disk
Hard Disk
CD-ROM
Magnetic Tapes

Egs.:
PROM SRAM
EPROM DRAM
EEPROM
Memory
Ø Memory measures in Bits i.e. 0 or 1
Ø Computer understands only 0 and 1’s that is binary language

Ø 8 bits = 1 Byte
Ø 16 bits = 1 word = 2 Byte
Ø 32 bits = double word = 4 Byte
Ø 64 bits = Quad word = 8 Byte

Ø 8 bit = 1 character = 1 Byte


Ø 1024 Bytes = 1 Kilo Byte (KB)
Ø 1024 KB = 1 Mega Byte (MB)
Ø 1024 MB = 1 Giga Byte (GB)
Ø 1024 GB = 1 Tera Byte (TB)
How Computers Store Data
▶ All data that is
stored in a
computer is
converted to
sequences of
0s and 1s.
▶ Byte
▶ Bit stands for
binary digit
Two bytes used for a large number
Storing Characters
▶ Any piece of data that is stored in a computer’s memory must be
stored as a binary number.
▶ Includes characters, such as letters and punctuation marks.
▶ When a character is stored in memory, it is first converted to a
numeric code.
▶ The numeric code is then stored in memory as a binary number.
▶ ASCII, which stands for the American Standard Code for
Information Interchange.
How a Program Works
▶ CPU is not a brain, and it’s not smart.
▶ an electronic device that is designed to do specific things. In particular, the
CPU is designed to perform operations such as the following:
◦ Reading a piece of data from main memory
◦ Adding two numbers
◦ Subtracting one number from another number
◦ Multiplying two numbers
◦ Dividing one number by another number
◦ Moving a piece of data from one memory location to another
◦ Determining whether one value is equal to another value
◦ And so forth . . .
▶ The CPU does nothing on its own, however. It has to be told what to do,
and that’s the purpose of a program.
▶ A program is nothing more than a list of instructions that cause the CPU to
perform operations.
▶ 10110000 - Intel microprocessor (move a value into the CPU)
When a CPU executes the instructions in a program, it is engaged in a process
that is known as the fetch-decode-execute cycle.
Compiling a high-level program and executing it
Executing a high-level program with an interpreter
▶ NOTE: Programs that are compiled generally execute faster than
programs that are interpreted because a compiled program is
already translated entirely to machine language when it is executed.
A program that is interpreted must be translated at the time it is
executed.

Q. What type of programming language allows you to create powerful


and
complex programs without knowing how the CPU works?
Input- Processing –Output
Computer programs typically perform the following three-step process:
1. Input is received.
2. Some process is performed on the input.
3. Output is produced.
References
▶ Deitel and Deitel, “C How to Program”, Pearson Education, sixth
Edition, New Delhi, 2011.
▶ https://www.youtube.com/watch?v=X5wAfklIW24

▶ Joyce Farell, “Programming Logic and Design- Comprehensive”,


Sixth Edition, Cengage Learning.
▶ Tony Gaddis, “Programming Logic & Design”, Third Edition,
Pearson Education.

You might also like