Beruflich Dokumente
Kultur Dokumente
Computing
(IT 101)
Dr. Manish Kumar Bajpai
Course Structure
IT101
100 marks
Theory
Lab
(Dr. M. K. Bajpai)
Quize1
Quiz2
Mid Sem
End Sem
Weekly lab
End Sem
(10 marks)
(10 marks)
(20 marks)
(30 marks)
(total 20 marks)
(10 marks)
Suggested reading
E Balaguruswamy, Programming in ANSI C, 6th edition.
(Available in Library)
Y Kanitkar, Let Us C, (Available in Library)
Kelley, Pohl, A Book on C, (Available in Library)
Important points
75% attendance is compulsory.
Have to score more than 30% not to get F Grade
Maintain the discipline in the class
Computer
A computer is an electronic machine that takes input from the
user, processes the given input and generates output in the
form of useful information.
The unique capabilities and characteristics of a computer:
Speed
Storage capacity
Accuracy
Reliability
Versatility
Diligence
Parts of computer
Computer
Input Devices
Output Devices
Central Processing
Unit
Storage Devices
Communication
Interface
Input Devices
Input devices are electromechanical devices that are used to
provide data to a computer for storing and further processing,
if necessary.
We can provide the input to a computer in two ways: (1)
Manually through devices such as keyboard and mouse; (2)
Directly from documents using devices such as scanners
Input Devices
Depending upon the type or method of input, the input device
may belong to one of the following categories:
(1) Keyboard
(2) Pointing devices
(3) Scanning devices
(4) Optical recognition devices
(5) Digital camera
(6) Voice recognition devices
(7) Media input devices
Registers
Arithmetic
Unit
Logic Unit
Control
Unit
Control Unit is an important
component of CPU that
controls the flow of data
and information. It
maintains the sequence of
operations being performed
by the CPU.
Output Devices
Output devices receive the processed data (information) from
the CPU and present it to the user in a desired form. They act
as an interface between the computer and the user. The main
task of an output device is to convert the machine readable
information into human-readable from which may be in the
form of text, graphics, audio or video. Depending upon the
form of output required, the output device may belong to one
of the following categories:
Display monitors
Printers
Plotters
Voice output systems
Projectors
Storage
Cache memory
(registers
memory)
Primary memory
(RAM)
Secondary memory
(HDD)
Magnetic tape
(VCR tape, CD, DVD)
Communication Interface
The internal communication of a processor in the computer
system can be divided into two major categories:
(1) Processor to memory communication
(2) Processor to I/O devices communication
Problem Solving
Problem
Statement
Algorithm
Code
Testing
Feedback
Problem statement
Algorithm
Pseudo code: it is a language made for human only.
Neither a programming language
Nor a speaking language
Algorithm: step by step procedure to solve a problem
E.g.: making a cup of tea
Pseudo code
READ: used when algorithm is to receive i/p from a file or record
GET: used when algorithm is to receive i/p from i/p devices
(keyboard)
PRINT: used when o/p is to be sent to the printer
WRITE: used when o/p is to be written to a file
PUT, OUTPUT, DISPLAY: used when o/p is to be written to the screen
PROMPT: required before an i/p instruction GET. Causes the
message to be sent to the screen which requires user response
COMPUTE: used when have to perform a computation
CALCULATE: used for performing calculations based on a formulae
You can call a function and also return a value from a function
Definition of function must be provided at start of an algorithm
Conditional statement
relational Operators: >, <, >=, <=, !=
Logical operator: !, &&, ||
IF
IF (amount < 1000)
Interest = 8
END IF
IF ELSE
IF (amount < 1000)
Interest = 8
ELSE
Interest = 6
END IF ELSE
Exercise
Problem Statement: Write an algorithm to find the tallest
person among three.
Analysis:
Input required: height of three person
Output : person identity who is tallest
Logic: ???????
Solution
Tallest(a, b, c, tallest_person)
INPUT: Height a, b, c
OUTPUT: tallest_person
BEGIN
GET a, b, c
IF (a > b)
IF (a > c)
Tallest_person = a
ELSE
tallest_person = c
END IF ELSE
ELSE
IF (b> c)
Tallest_person = b
ELSE
tallest_person = c
END IF ELSE
END IF ELSE
PUT tallest_person
END
C programming---basic
1 Introduction to C
2 C Fundamentals
3 Formatted Input/Output
4 Expression
5 Selection Statement
6 Loops
7 Basic Types
8 Arrays
9 Functions
10 Pointers
11 String Arrays
12 Structure & Union
13 File Management
14 Header File
Introduction to C
Intended use and underlying philosophy
1 C is a low-level language
---suitable language for systems programming
2 C is a small language
---relies on a library of standard functions
3 C is a permissive language
---it assumes that you know what youre doing, so it allows
you a wider degree of latitude than many languages. It
doesnt mandate the detailed error-checking found in
other language
Introduction to C
Strengths:
+ Efficiency: intended for applications where assembly
language had traditionally been used.
+ Portability: hasnt splintered into incompatible dialects;
small and easily written
+ Power: large collection of data types and operators
+ Flexibility: not only for system but also for embedded system
commercial data processing
+ Standard library
+ Integration with UNIX
Introduction to C
Weaknesses:
+ error-prone
+ difficult to understand
+ difficult to modify
Similarities of C to java
/* Comments */
Variable declarations
if / else statements
for loops
while loops
function definitions (like methods)
Main function starts program
C Fundamentals
First program
Pre-processor
Directive
Header File
Main
functi
on
#include <stdio.h>
Incursion
main()
operator
{
printf(To C, or not to C: that is the question);
}
Semi
colon
Curly braces
In-build function
C Fundamentals
#include<stdio.h>
#define period 10
#define principal 5000.00
void main()
{
int year;
Float amount, value, inrate;
amount=principal;
inrate=0.11;
year=0;
while(year<=period)
{
}
}
C Fundamentals
Compiling and Linking
Preprocessing: the program is given to a preprocessor,
which obeys commands that begin with #(directives)
add things to the program and make modifications
Compiling: modified program compiler object
code
Linking: add library functions to yield a complete
executable program
C Fundamentals
Compilation
cc o nameofoutputfile program.c
gcc o nameofoutputfile program.c
Execution
./nameofoutputfile
C tokens
keywords
Identifiers
strings
constants
Special
symbols
operators
C Fundamentals
Keywords
auto
break
case
char
const
continue
default
do
double
else
enum
extern
float
for
goto
if
int
struct
long
switch
register typedef
return
union
short
unsigned
signed
void
sizeof
volatile
static
while
Variables or identifiers
It is the identity of a memory location where you want to store
something.
Its not memory address
Variable name must have any combination of following
Alphabets a, b, c,.,z
A,B, C, Z,
Underscore _
Numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
It must have some meaning
Some relation to its value
First character must be alphabet
Only 31 characters are significant
Keywords can not be used
Should not contain white spaces
Variable Type
Data type: provides the information about the values
stored in a particular variable
C has the following simple data types:
Data Type
Minimum
Size (bytes)
Lower bound
Upper bound
char
unsigned char 1
255
(short) int
-32768
+32767
(unsigned
short int)
65536
(long) int
-2
+2 -1
float
-3.2 10
+3.2 10
double
-1.7 10
+1.7 10
Constants
integer
Numeric
constants
real
Constants
Character
constants
Single character
constants
String constants
Strings
Collection of characters
Enclosed in
Special Symbols
[]
{}
()
;
#
Operators precedence
Expression Evaluation
a = b += c++ - d + --e / -f
a = b += (c++) - d + --e / -f
a = b += (c++) - d + (--e) / -f
a = b += (c++) - d + (--e) / (-f)
a = b += (c++) - d + ((--e) / (-f))
a = b += ((c++) d) + ((--e) / (-f))
a = b += (((c++) d) + ((--e) / (-f)))
a = (b += (((c++) d) + ((--e) / (-f))))
(a = (b += (((c++) d) + ((--e) / (-f)))))
Comments
// used for single line comments
/* .. */ used for multi line comments
Input / Output
45
/* reads u in base 10 */
/* writes u in base 10 */
/* reads u in base 8 */
/* writes u in base 8 */
/* reads u in base 16 */
/* writes u in base 16*/
Examples
#include <stdio.h>
int main()
{
/* this program adds
two numbers */
int a = 4; //first number
int b = 5; //second number
int res = 0; //result
res = a + b;
return 0;
}
#include <stdio.h>
int main()
{
int first, second, add;
float divide;
printf("Enter two integers\n");
scanf("%d%d", &first, &second);
add = first + second;
divide = first / (float)second;
printf("Sum = %d\n",add);
printf("Division = %.2f\n",divide);
return 0;
}