Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C Intro 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

Introduction

• To computers
HARDWARE
• Hardware refers to the physical elements of a computer. This is also sometime called
the machinery or the equipment of the computer. Examples of hardware in a computer
are the keyboard, the monitor, the mouse and the central processing unit. However,
most of a computer's hardware cannot be seen; in other words, it is not an external
element of the computer, but rather an internal one, surrounded by the computer's casing
(tower). A computer's hardware is comprised of many different parts, but perhaps the
most important of these is the motherboard. The motherboard is made up of even more
parts that power and control the computer.
• In contrast to software, hardware is a physical entity. Hardware and software are
interconnected, without software, the hardware of a computer would have no function.
However, without the creation of hardware to perform tasks directed by software via the
central processing unit, software would be useless.
• Hardware is limited to specifically designed tasks that are, taken independently, very
simple.
Computer -- Hardware

Input Output
Key board Storage Program Storage Area
Storage Monitor
Area Area
Mouse Working Storage Area Printer
Input Devices Output Devices

Primary or Main Memory (RAM)

Register 1
Register 2
……
Arithmetic
……
Register N and
Logic Unit

Secondary
MicroStorage Devices
Processor
Software ?

• Software implements algorithms (problem


solutions) that allow the computer to
complete much more complex tasks.
• Computer Instructions or data, anything that can be stored
electronically is Software.
• For example: There is a problem in the Software implies –
Problem with program or data
Types of Software
System Software
Application Software
Open source Software and
Proprietary Software
System Software:
System Software includes the Operating System and all the
utilities that enable the computer to function.

System software is a term referring to any computer software


which manages and controls the hardware so that application
software can perform a task.

Example:
Operating Systems, Compiler, Loader, Linker, Interpreter.
Application Software:

Application Software includes programs that do real work


for user.

Example:

Payroll systems, Inventory Control, Manage student


database, Word Processor, Spreadsheet and Database
Management System etc.,
Open Source Software:
• Open source software (OSS) is computer software
whose source code is available under a license that permits
users to use, change, and improve the software, and to
redistribute it in modified or unmodified form.

• It is often developed in a public, collaborative manner.


Well-known OSS products are Linux, Netscape, Apache,
etc.,
Proprietary Software:
• Proprietary software (also called non-free software) is
software with restrictions on using, copying and modifying
as enforced by the proprietor. Restrictions on use,
modification and copying is achieved by either legal or
technical means and sometimes both.

• Proponents of proprietary software are Microsoft.

• Ex: CAD, Nortan Antivirus etc.,


System Software:
Operating System:
• Operating System is a software, which makes a computer to
actually work.

• It is the software the enables all the programs we use.

• The OS organizes and controls the hardware.

• OS acts as an interface between the application programs and


the machine hardware.

• Examples: Windows, Linux, Unix and Mac OS, etc.,


System Software (contd):
Compiler: A compiler is a program that reads a program
in one language – the source language and translates into
an equivalent program in another language – the target
language.

Source Target Languages


Languages
‘C’ language ‘C’ language
‘Pascal’ language Machine language
FORTRAN language
C++ language
ADA language
System Software (contd):
Loader: A loader is the part of an operating system that is
responsible for loading programs into memory, preparing
them for execution and then executing them.

The loader is usually a part of the operating system's kernel


and usually is loaded at system boot time and stays in
memory until the system is rebooted, shut down, or
powered off.

In Unix, the loader is the handler for the system call


execve().
System Software (contd):
Linker: A linker or link editor is a program that takes one
or more objects generated by compilers and assembles
them into a single executable program.

Linkers can take objects from a collection called a library.


The objects are program modules containing machine code
and information for the linker.

The linker takes care of arranging the objects in a


program's address space.
System Software (contd):
Interpreter: An interpreter is a computer
program that translates and executes instructions
written in a computer programming language line-by-
line, unit by unit etc.,

An interpreter needs to be able to analyze, or parse,


instructions written in the source language.

Example: Lisp systems, etc.,


Application
Word Processors: Software:
Word processing is a tool that helps user in creating, editing,
and printing documents. Word processors will normally have
the following capabilities built into them:
» Spell checking
» Standard layouts for normal documents
» Have some characters appear in bold print,
italics, or underlined
» Center lines, make text line up on the left side of
the paper, or the right side of the paper
» Save the document so it can be used again
» print the document.

Examples: WordPerfect and Microsoft Word


Application Software
(contd…):
Spreadsheets: The spreadsheet packages are
designed to use numbers and formulas to do calculations
with ease. Examples of spreadsheets include:
» Budgets
» Payrolls
» Grade Calculations
» Address Lists
The most commonly used spreadsheet programs are
Microsoft Excel and Lotus 123.
Application Software
(contd…):
Graphic Presentations: The presentation
programs can make giving presentations and using
overheads easier. Other uses include:
» Slide Shows
» Repeating Computer Presentations on a
computer monitor
» Using Sound and animation in slide shows

The most recognized graphic presentation programs are


Microsoft PowerPoint and Harvard Graphics.
Computer - Software
• Software, commonly known as programs or apps, consists of all the instructions that tell the
hardware how to perform a task. These instructions come from a software developer in the form that
will be accepted by the platform (operating system + CPU) that they are based on. For example, a
program that is designed for the Windows operating system will only work for that specific operating
system. Compatibility of software will vary as the design of the software and the operating system
differ. Software that is designed for Windows XP may experience a compatibility issue when running
under Windows 2000 or NT.
• Software is capable of performing many tasks, as opposed to hardware which can only perform
mechanical tasks that they are designed for. Software provides the means for accomplishing many
different tasks with the same basic hardware. Practical computer systems divide software systems
into two major classes:
• System software: Helps run the computer hardware and computer system itself. System software
includes operating systems, device drivers, diagnostic tools and more. System software is almost
always pre-installed on your computer.
• Application software: Allows users to accomplish one or more tasks. It includes word processing,
web browsing and almost any other task for which you might install software. (Some application
software is pre-installed on most computer systems.)
• Software is generally created (written) in a high-level programming language, one that is (more or
less) readable by people. These high-level instructions are converted into "machine language"
instructions, represented in binary code, before the hardware can "run the code". When you install
software, it is generally already in this machine language, binary, form.
Programming Languages:
• Machine Language
• Assembly Language
• High level Language

Chapter 2- Visual Basic Schneider 20


Machine Language
• The fundamental language of the computer’s
processor, also called Low Level Language.
• All programs are converted into machine language
before they can be executed.
• Consists of combination of 0’s and 1’s that
represent high and low electrical voltage.

Chapter 2- Visual Basic Schneider 21


Assembly Language
• A low level language that is similar to
machine language.

• Uses symbolic operation code to represent


the machine operation code.

Chapter 2- Visual Basic Schneider 22


High Level Language
• Computer (programming) languages that
are easier to learn.
• Uses English like statements.
• Examples are C ++, Visual Basic, Pascal,
Fortran and …....

Chapter 2- Visual Basic Schneider 23


Machine Language – Assembly Language – High-Level Language

1 00000000 00000100 0000000000000000 1 entry main,^m<r2>


2 01011110 00001100 11000010 0000000000000010 2 sub12 #12,sp
3 11101111 00010110 0000000000000101 3 jsb C$MAIN_ARGS
4 11101111 10111110 0000000000001011 4 moveb $CHAR_STRING_CON
5 11111000 10101101 11011111 0000000000010010 5
6 01100010 11011111 0000000000010101 6 pusha1 -8(fp)
7 11101111 00000010 11111011 0000000000010111 7 pusha1 (r2)
8 11110100 10101101 11011111 0000000000011110 8 calls #2,SCANF
9 00000011 10100010 11011111 0000000000100001 9 pusha1 -12(fp)
10 11101111 00000010 11011111 0000000000100100 10 pusha1 3(r2)
11 01111110 11110100 10101101 11 calls #2,SCANF
12 11111000 10101110 11000101 0000000000101011 12 mull3 -8(fp),-12(fp),-
13 00000110 10100010 11111011 0000000000110001 13 pusha 6(fp)
14 11101111 00000010 11111011 0000000000110100 14 calls #2,PRINTF
15 01010000 11010100 0000000000111011 15 clrl r0
16 00000100 0000000000111101 16 ret

1 #include<stdio.h>
2 int main(void)
The only language the computer can understand is machine
3 { language (binary language).
4 int n1, n2,product;
5 printf(“Enter two numbers : “); A high level language is an English like language where one
6 scanf(“%d %d”,&n1,&n2); instruction typically translates into a series of machine-
7 product = n1 * n2;
language instructions.
8 printf(“%d”,product);
9 return 0;
1 } A low level language corresponds closely to machine code
0 so that a single low-level language instruction translates to a
single machine language instruction.
Program Development Cycle:
1. Analyze: Define the problem
2. Design: Plan the solution to the problem
3. Code: Translate the algorithm into a
programming language.
4. Debug and Test: Locate and remove any
errors in the program.
5. Complete the Documentation: Organize all
the materials that describe the program.
Chapter 2- Visual Basic Schneider 25
Program Development Steps
Statement of Problem 3.a)Compilation
a) Working with existing system and using proper Translate the program into machine code. This
questionnaire, the problem should be explained process is called as Compilation. Syntactic errors are
clearly. found quickly at the time of compiling the program.
b) What inputs are available, outputs are required These errors occur due to the usage of wrong syntaxes
and what is needed for creating workable solution for the statements.
should be understood clearly. Eg: x=a*y+b
1)Analysis There is a syntax error in this statement, since, each
a) The method of solutions to solve the problem can and every statement in C language ends with a
be identified. semicolon (;).
b) We also judge that which method gives best
results among different methods of solution. 3.b)Execution
2)Designing The next step is Program execution. In this phase, we
a) Algorithms and flow charts will be prepared. may encounter two types of errors.
b) Keep focus on data, architecture, user interfaces Runtime Errors: these errors occur during the
and program components. execution of the program and terminates the program
abnormally.
3)Implementation
Logical Errors: these errors occur due to incorrect
The algorithms and flow charts developed in the
usage of the instructions in the program. These errors
previous steps are converted into actual programs in
are neither detected during compilation or execution
the high level languages like C.
nor cause any stoppage to the program execution but
produces incorrect ouz
Programming Tools:
• Algorithm
• Flowchart
• Pseudocode

Chapter 2- Visual Basic Schneider 27


Algorithm: Step by step procedure of solving a particular problem.
Pseudo code: Artificial informal language used to develop algorithms.
Flow chart: Graphical representation of an algorithm.
Algorithm to find whether a number even or odd:
Step1: Begin Step1: START
Step2: Take a number Step2: Read num
Step3: if the number is divisible by2 then Step3: if(num%2=0) then
print that number is even print num is even
otherwise print that number is odd otherwise
print num is odd
Step4: End Step4: STOP
(Algorithm in natural language) (Algorithm by using pseudo code)

#include<stdio.h> start
#include<conio.h> Flow chart:
main() read num
{
int num;
printf(“Enter any number”); If No
Yes
scanf(“%d”,&num); num%2=0
if(num%2==0)
printf(“%d is even”,num);
else print num print num
printf(%d is odd”,num); is odd
is even
}
(Program in C language) stop
Structure of C program
/*Program to find
Documentation Section
area and perimeter of Circle */
#include<stdio.h> Linkage Section
#define PI 3.1415 Definition Section
float radius;
float area(); Global Declaration Section
float perimeter();
int main()
{
float a, p; Main Function Section
printf(“Enter radius : “);
scanf(“%f”,&radius); Local Declaration Part
a = area(); Executable Code Part
p = perimeter();
printf(“Area of Circle : %f”,a);
printf(“Perimeter : %f”,p);
}
float area()
Sub Program Section
{
return (PI * radius * radius);
Function1()
}
Function2()
float perimeter()
……………
{
FunctionN()
return (2 * PI * radius);
}
Executing a C program
#include<stdio.h>
Text int main()
{ Translators are system software
Editor ……. prog1.c used to convert high-level
language program into
C-compiler compiles
machine-language code.
Compiler : Coverts the entire
010110 100 Syntax Yes source program at a time
……………. Errors?
01011 101 into object code file, and
No saves it in secondary storage
Object machine code permanently. The same
adds prog1.obj object machine code file will
Linker
be executed several times,
00101010
Executable whenever needed.
………….
01010101 machine code Interpreter : Each statement of
prog1.exe source program is translated
machine code of
library file into machine code and
Executes executed immediately.
C-Runtime
Translation and execution of
Feeds
Runtime
each and every statement is
Input Yes repeated till the end of the
or Logic
Errors ? program. No object code is
saved. Translation is
repeated for every execution
Output of the source program.

You might also like