0% found this document useful (0 votes)
5 views88 pages

CS110 - Computer Programming

The document outlines a Computer Programming course (CS110) focused on teaching C language concepts and problem-solving methodologies, along with a lab component (CS111) for practical coding experience in a UNIX environment. It includes course objectives, coverage of topics such as data types, decision making, functions, and file management, as well as evaluation plans for both theoretical and practical components. Additionally, it provides an overview of computer fundamentals, hardware, software, and algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views88 pages

CS110 - Computer Programming

The document outlines a Computer Programming course (CS110) focused on teaching C language concepts and problem-solving methodologies, along with a lab component (CS111) for practical coding experience in a UNIX environment. It includes course objectives, coverage of topics such as data types, decision making, functions, and file management, as well as evaluation plans for both theoretical and practical components. Additionally, it provides an overview of computer fundamentals, hardware, software, and algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 88

Computer Programming

Course code: CS110


Course Title: Computer Programming
L-T-P: (3-1-0)
Credits: 4

[email protected]
Objective of the Course:

The aim of this course is to impart knowledge to analyse,


solve, design and code real-life problems using C language
by:
• Learning the basic concepts of computing and problem
solving methodologies.
• Analysing and applying the concepts of programming
using „C‟ language.
Course Coverage
●Introduction to computer: Characteristics block diagram, parts of the computer and
different kinds of memory, hardware and software, algorithm and flowchart. 2 hrs

●Introduction to C Programming language: Types of programming languages,


Features of C, Structure of a C program, executing a C program, Characteristics and
applications. 1 hr

●C fundamentals: Constants, Variables, identifiers, keywords and Data types, Storage


classes. 2 hrs

●C input/output functions-unformatted and formatted Input Output functions. 2 hrs

●Operators and Expressions in C: Arithmetic, Relational, Logical, assignment,


conditional, increment or decrement, bitwise, special operators, associativity and
precedence of operators. 2 hrs
Course Coverage
●Decision making and branching: Different forms of if statements, switch case,
continue, goto, break. 5 hrs

●Decision making and Looping: for, while, do-while, nested loop, jumps in loops. 5hrs

●Arrays: Single and Multi-dimensional array. 5 hrs

●Strings: String handling functions and operations. 3 hrs

●Functions in C: Categories, arrays within functions, nesting of functions, Recursion,


Parameter passing methods. 5 hrs

●Structures and Unions: Introduction, structure and array, structure and function,
nesting of structures, Bitfields and Unions. 4 hrs
Course Coverage
●Pointers in C: Introduction, operations. 3 hrs

●File management in C-types of files, file modes and file functions, command line
arguments. 3 hrs

●Object oriented programming : Introduction, Object oriented features, Comparison of


Object Oriented Language with C. 3 hrs

●Cyber Security 1 hrs


Course Evaluation Plan:
●Mid semester exam 20%

●End semester exam 40%

●Surprise tests 30%

●Instructor‟s Discretion 10%


Computer Programming Lab

Course code: CS111


Course Title: Computer Programming Lab
L-T-P: (0-0-2)
Credits: 1
Objective of the Course:

• Learning to code and debug C programs in a UNIX


environment.
• Implement programming strategies to understand various
C language concepts.
Course Coverage
Topics Lab Hours

● UNIX shell commands 3

● Basic Input-Output functions 3

● Operators and Expressions 3

● Decision making and Branching constructs 3

● Decision making and looping constructs 3

● Arrays 3

● Strings 3

● Functions, Recursions and Graphics 6

● Structures and Union 3

● Pointers 3

● Files and file operations 3


Course Evaluation Plan:
● Lab Assignment Execution, Record etc. 15%

● Surprise test 20%

● Mid semester exam 25%

● End semester exam 40%


Reference Books:
[1] Balagurusamy, “C Programming” 3rd edition

[2] Yashwanth Kanetker, “Let Us C”

[3] Byron S Gottfried “Programming with C”

[4] Brian Kernighan and Dennis Ritchie “The C Programming Language”

[5] Herbert Schildt, “C: The Complete Reference”

[6] Balagurusamy, “Object oriented programming using C++”


Introduction to Computer
What is a Computer?

Computer is an electronic device that -

● Takes input (number ,text, sound etc.) from the user.

● Processes and perform calculations and operations based on instructions provided by a


software or hardware program.

● Presents the results as output to the user.


Characteristics of a Computer
1. Speed
2. Accuracy
3. Diligence
4. Versatility
5. Storage Capacity
6. Automation
Continued…..

Speed

● computers can perform 100 million computations in one second. Carry out calculations
that take a lot of time in seconds.

● The speed of computers are measured in terms of microseconds, Nano seconds and
even in Pico seconds.

Accuracy

● The computer is 100% accurate and capable to perform arithmetical calculation and
logic operations with same accuracy.

● The accuracy of a computer is Illustrated well by the term GIGO; i.e. Garbage In
Garbage Out.
Continued…..

Diligence:

● Unlike human beings, computers are highly consistent.


● They do not suffer from human traits of boredom and tiredness resulting in lack of
concentration.
● Computers, therefore, are better than human beings in performing voluminous and
repetitive jobs.

Versatility:

● Computers are versatile machines - capable of performing any task as long as it can
be broken down into a series of logical steps.
● The presence of computers can be seen in almost every sphere – Railway/Air
Continued…..

Storage Capacity/Memory:

● Every piece of information stored within computer memory is encoded as a unique


combination of zero’s and one’s called bits (Binary Digits).
● Collection of 8 bits - 1 byte

Automation:

● Computers are automatic in operation.


● The computers manipulate the data according to the instructions and continue doing
so till the last instruction is executed.
Computer Advertisement
Types of Computers
The von Neumann architecture

CPU
Input Device ALU CU Output Device

Main memory Secondary


(RAM) storage
The von Neumann architecture
● Input Device-used to input data to computer (keyboard,mouse etc.)

● Output Device- Processed result displayed on o/p device (eg-Monitor,


printer).

●Central Processing Unit (CPU): the “brain” of the machine.

CU: Control Unit

ALU: Arithmetic and Logic Unit


o ALU: Arithmetic-Logic Unit- performs arithmetic operation and conducts
comparison of information for logical decisions
o CU:Control Unit-Sending/receiving control signals to and from all
components
o Under CU’s control, data comes from i/p device to memory, gets
processed by ALU and finally result is stored in memory.

■Examples of basic operation: adding two numbers, testing to see if two numbers are
equal.
The von Neumann architecture
●Main memory (called RAM for Random Access Memory): stores
programs and data.

○Fast but volatile

●Secondary memory: provides permanent storage.

●Human-computer interaction: through input and output devices.

○keyboard, mouse, monitor


How it works
●How does a computer execute a program ? (example
programs: a computer game, a word processor, etc)
●theinstructions that comprise the program are copied from
the permanent secondary memory into the main memory
●After the instructions are loaded, the CPU starts executing
the program.
●Foreach instruction, the instruction is retrieved from
memory, decoded to figure out what it represents, and the
appropriate action carried out. (the fetch- execute cycle)
●Then the next instruction is fetched, decoded and executed.
Input Devices
●You use an input device, such as a keyboard or a mouse, to input data and issue commands
○Keyboard

■Mouse

■Trackball

■Touchpad

■Joystick

■ Touch Pen or Stylus

○Touchscreen

○Scanner

○Mic

○Camera
Output Devices
●Output devices show you the results of
processing data

●Monitor
■Printer

■Plotter

■Speaker

Speaker

Plotter
Processing Hardware
●The motherboard is the main
electronic component of the computer
●The microprocessor/processor is
one of the most important pieces of
processing hardware on the
motherboard.
Memory
Primary Memory

●Random access memory (RAM)


○Volatile memory

●Cache memory (RAM cache or CPU cache)

●Virtual memory
Continued….

RAM (Random Access Memory)


DRAM (Dynamic RAM)

● Most common type of main memory


● Storage cells refreshed every few milliseconds for the memory to be maintained

SRAM-Static RAM

● Retains contents by having a constant source of power applied


● Faster and expensive than DRAM
● Used for CPU Cache
Continued….

ROM(Read Only Memory): ROM used to store system BIOS-(Booting-BIOS in ROM


chip wakes up -invokes boot loader and loads OS)
● PROM- Programmable ROM-programmed by using a special device called a PROM
programmer. Generally, a PROM can only be changed/updated once.

● EPROM-Erasable Programmable ROM-This type of ROM can have its contents


erased by ultraviolet light

● EEPROM-Electrically Erasable PROM-used to store a computer system's BIOS


Storage Media
Secondary Memory

●A computer file is a named collection of stored data

●An executable file contains the instructions that tell a computer how to
perform a specific task

●A data file is created by a user


Storage Media

●Magnetic storage media

●Hard Disks

○A hard disk contains several magnetic oxide-


covered metal platters that are usually sealed in a
case inside the computer
Storage Media
●Optical storage device
○CD

○DVD

○CD-RW

○CD-ROM

○DVD-R

○DVD-RW

○BD
Storage Media

●Flash memory
○Solid state storage

○Flash memory cards

○USB flash storage device

■ USB flash drive


Continued….

● Storage/Memory

Fig: Types of memory


Continued….

PRIMARY MEMORY
Primary Memory vs Secondary Memory

● Fast ● Slow
● Expensive ● Cheap
● Low capacity ● Large capacity
● Works directly with the processor ● Not connected directly to the
processor
Memory Hierarchy
Continued….

1. Internal register:

● Internal register in a CPU is used for holding variables and temporary results.
● Internal registers have a very small storage and they can be accessed instantly

2) Cache:

● Cache is used by the CPU for memory which is being accessed over and over again.
● Instead of pulling it every time from the main memory, it is put in cache for fast access.
● It is also a smaller memory, however, larger than internal register.

3) RAM (Random Access Memory)

4) Secondary Storage
Cache memory
Parts of A Computer System
The major components of a computer system are:

● Hardware

● Software

● User

● Data
Data:
o Input given by user called data. That may contain a number ,text ,video ,audio etc.
o To process data, computer must be given an appropriate set of instructions called program.
o The processed data called information.
o These instructions are entered into computer and stored in a portion of the computer’s memory.
Continued…

Hardware:
● Computer hardware is any physical device used in or with your machine. Eg-mouse , keyboard
● The processor, main memory, secondary memory, power supply, and supporting hardware are
housed in a metal case.
● CPU contains motherboard which is the main circuitry to the system.
43
Classification of Hardware
1. Keyboard
●Keyboard is a primary input device of he computer.

●It is used to enter text and commands as input to computer.

●Keyboards on computer are similar to typewriters.

●Present day keyboards have more than 101 keys.


Types of Keyboard
●AT Keyboard

●PS/2 Keyboard

●USB Key Board


48
49
50
2. Mouse
●Douglas Engelbart invented the computer mouse in 1963.

●Mouse enables user to move the cursor/pointer to a specific position or to select


specific items on screen.

●Mouse is important input device in Graphical User Interface applications.


2. Types of Mouse
53
54
55
56
57
58
HD

track

sector

head
60
61
Hard Disk Connectors
Parallel Connector
for
ATA

Serial-ATA (SATA)
Connector

62
63
4. Optical Media

64
Optical Discs:
Compact Disk (CD) can store 650MB to 800MB of
information and data. CD-ROM (CD-R) (Read Only
Memory) can only read data from a CD-ROM.

DVD (Digital Versatile Disk) is the size of a regular CD.


DVD can store 4.8GB to 8.0GB of information and data.
DVD-ROM (DVD-R) is readable only.

Both CD/DVD can be played in a regular in a DVD movie


player.

DVD-RW/CD-RW can be used to rewrite the data.


5.Motherboard
●A motherboard is a central circuit board of a computer.

RAM Slots

CPU Slot

66
67
6. Microprocessor/Processor
●Processor accepts inputs from user as a format of data/information and
processes using instructions, finally produces output to the user.

●Choice of processor affects computer speed. Processor speed is measured in


Mega Hertz (MHZ)
71
7. Memory
●Physical Memory

○ Random Access Memory

a) Static RAM b) Dynamic RAM

○ Read Only Memory

a) PROM b) EPROM c)EEPROM

Static RAM Dynamic RAM


ROM
73
8. Switch Mode Power Supply (SMPS)
What is Software?

• Software is a set of electronic instructions that tells the computer how to do


certain tasks. A set of instructions is often called a program.

• When a computer is using a particular program, it is said to be running or


executing the program.

• The two most common types of programs are system software and
application software.

75
System Software

• System software exists primarily for the computer itself, to help the
computer perform specific functions.

• One major type of system software is the operating system (OS). All
computers require an operating system.

• The OS tells the computer how to interact with the user and its own
devices.

• Common operating systems include Windows, the Macintosh OS, OS/2,


and UNIX .
Operating system software tells the computer how to perform the functions of loading, storing and
executing an application and how to transfer data.

Today, many computers use an operating system that has a graphical user interface (GUI) that
provides visual clues such as icon symbols to help the user.

• Microsoft Windows 10 is a widely used graphical operating system now.

• DOS (Disk Operating System) is an older but still widely used operating system that is text-
based.
Continued….

Other System Softwares- Programs that manage the computer- eg. Compiler,interpeter

Computer understands only machine language and needs a translator

Compiler- Compiler converts the entire high level language to machine languag and stored in
memory and executed when needed.

● Programming Lannguages like C and C++ use compilers.


● Generates an intermediate object code.

Interpreter- Converts high level language one line at a time to machine language and then executes it

● Presence of interpreter is a must while running a program


● Programming Languages like python and ruby uses interpreters
● No object code is generated
● Debugging is easier.
Application Software
• Application Software consists of programs that tell a computer how to
produce information

• Application software tells the computer how to accomplish tasks the


user requires, such as creating a document or editing a graphic
image.

• Some important kinds of application software are:

Word processing programs Spreadsheet software


Database management Presentation programs
Graphics programs Networking software
Web design tools and browsers Internet applications
Communications programs Utilities
Entertainment and education Multimedia authoring
Algorithm and flowchart
Algorithm

● Step by step procedure to solve a particular problem


● Consists of human understandable language statements (E.g. written in English)
● Each statement must be precise and well defined to perform a specific operation
● Algorithm-named after author and mathematician, Al-Khawarizmi
Algorithm: An Example

Algorithm To add 2 numbers:

Input: 2 numbers, a and b

Output: Sum of 2 numbers

Step 1: Read a and b

Step 2: Compute sum [sum=a+b]

Step 3: Print Sum


Characteristics of an Algorithm
1. Input: Takes 0 or more inputs

2. Output: Produces at least one output

3. Definiteness: Each instruction must be clear and well defined-there should be no ambiguity

4. Finiteness: Algorithms must terminate after performing required task/specified time- should not
enter into an infinite loop

5. Feasibility − Should be feasible with the available resources.

6. Independent − An algorithm should have step-by-step directions, which should be independent


of any programming code.

7. Effectiveness: All the operations to be performed in the algorithm must be sufficiently basic
that they can in principle be done exactly and in a finite length of time.
Flow Chart

● Chart showing flow of logic involved in solving a problem


● Graphical representation of an algorithm

Flow chart symbols:

Oval Start/Stop

Parallelogram Input and Output

Rectangle Processing
Continued….

Diamond Decision Making

Arrows Connections

Hexagon Looping
Flow Chart
Start

Read a and b

sum=a+b

Print sum

Stop
1. Write a algorithm to find out number is odd or
even. Draw its flowchart.

2. Write an algorithm to find the largest among three


different numbers entered by user. Draw its
flowchart.

You might also like