Vous êtes sur la page 1sur 44

Computer System

1
Outline
• Computer System
• Problem Solving and Flow Chart
• Linux Command
– ls, mkdir, cp, mv, rm, cat, ..
– Editor: vi, pico, gedit, kwrite, emacs
• How to program
– Write, Compile and Execute
– Explanation of C program
• Demonstration: if possible
2
What Is A Computer?
• An electronic device
• Operates under control of instructions
(software)
• Stored in its own memory unit
• It can
– Accept data (input),
– Manipulate data (process),
– Produce output from the processing.
• A collection of devices that function together
as a system. 3
Computer System

I/P Processing O/P

• Keyboard, Mouse : Input


• Speaker, Monitor/Display : Output
• CPU Box : Processing 4
Computer System: Von Newman
Memory

I/P Processing O/P


• Input and Output
• Processing
• Memory : Where it store
– Instruction, Data, Intermediate compute
5
Inside PC : Motherboard

6
Inside PC: Memory Card

7
Inside PC : Hard Disk

8
Inside PC : Processor

9
Computer System:
When you Switch on
• Operating System boots from Hard disk
• OS : Give you an environment where you
work
• Different OS
– Window XP/Vista/7
– Linux: Fedora, Ubuntu, Debian
• Application can be invoked by clicking some
icon
• Application: Word, Excel, Internet Explorer,
Mozilla, Media Player
10
Screen shot : Window & Linux

• Both are equally Good and Powerful


• Window: User friendly, prone to Virus,
Commercial (Not Free: you have to Pay Money)
• Linux : Robust and Freely available 11
Application Software
• Application Software consists of programs
• That tell a computer how to produce
information.
• Some of the more commonly used packages
are:
– Word processing, Spreadsheet
– Database
– Presentation graphics

12
Word Processing

• Used to create and print documents.


• A key advantage of word processing software
• Users easily can make changes in documents.
13
Electronic Spreadsheets

• Allows the user can do on rows and columns of numbers


– Add, Subtract, user-defined calculations
• These numbers can be changed
• Spreadsheet quickly recalculates the new results 14
Database Software
• Allows the user to
enter, retrieve, and
update data
• In an organized and
efficient manner
• With flexible inquiry
and reporting
capabilities.

15
Presentation Graphics

• Allows the user to create documents slides to be used in


making the presentations.
• Using special projection devices to Project
• Slides display as they appear on the computer screen 16
Internet Browsing

• Allows the user to browse website


• View HTML pages
• Play internet video, games, do many things 17
How to create your own Application?
• Operating System : Linux, Window
• Applications: Word/Excel, Media Player,
Mozilla, Explorer, etc
– We use it to do some tasks, but don’t know inside
contents
• Programming helps us to create our own
application
– Already solution approach is known
– Draw the flow chart, write Pseudocode
– Write code, compile, run and test 18
Programming: Purpose?
• Programming
– Purpose : to create a program that performs
specific operations or exhibits a certain desired
behavior.
– Computer Language (C , C++, Java, Fortran, Cobol)
– Design our own application
– Almost from the beginning
– Understanding how software/application works

19
How to do programming
• Problem: Specification
– Example: Compute sum of first N natural number
– Define Input {N}, Output {SUM}
– How to do : Flow chart
– Write the C/C++/{*} Code in Note/Paper
• Program
– Sequence of Instructions and Data
– Can be run by
• Compiling and running
• Interpreting
20
How to do programming
• OS, Shell, IDE, Editor:
– Linux, Bash Shell, gedit/VI/Pico
– Word Processor is not used to write program
– Integrated Development Environment: GUI Based
• TurboC/VisualC++/Kdevelop/Dev GUI
• Use the Program (Method 1)
– Compiling: GCC, TCC, VCC
– Running: ./a.out
• Use the Program (Method 2)
– Interpret the program and run
21
Interpreter Vs Compiler
• Interpreter
– Examples: Shell/Command Prompts, ML, Perl,
Python, Matlab
– Read code line by line and execute, sequential
– Basic syntax Errors occur at run time
• Compiler
– Example: C, C++, Java
– Read whole code together, make an executable and
run the executable
– Basic syntax Errors don’t occur at run time, only
logical and runtime error occurs

22
Interpreter Example
• Interpreter
– Examples: basic command line calculator of Linux
– $bc
3*4
12
6+ (3+2)^2
31
• Doing small computation easier
• Interpreter can read from file and execute line
by line, example shell script
23
Writing and Compiling C Program
under Linux
Header file:
Standard
#include <stdio.h> Input/Output

int main(){
Starting of program
printf(“Hello world”);

return 0; Printing message


}
End of program

24
Compiling program: test.c
• Compiling : $gcc test.c
• Listing : $ls
test.c a.out
• Execute the program : $./a.out
Hello world

25
Example 1: Adding two number
Flowchart

START

• Step 1: Input A and B Input A and B


• Step 2: S  A + B
• Step 3: Print S
SA+B

Print S

STOP
Sum A+B : Input and output
#include <stdio.h>
Header file:
int main(){ Standard Input/Output
int A,B, S;
printf(“Enter two
numbers ”); Printing message
scanf(“%d %d”,&A,&B);
Asking for inputs
S=A+B;
Compute
printf(“Res=%d”, B);
return 0; Output Result
}
logical mistake, should27be S
Compiling program: test.c
• Compiling : $gcc -Wall test.c
It is advisable to use –Wall option to raise all
warnings of the code
• Listing using $ls
test.c a.out
• Executing : $./a.out
Input two numbers 5 7
Res=12
28
C Programming in Liunx Environment
• We will be using Linux environment
in CS110 Lab
• Editor : vim and gedit
• Compiler: GCC (Gnu Compiler
Collection)
• You should know a bit of Linux and
Linux Command
29
Linux Basics
• Freely Downloadable from websites
• Available as sets of DVDs and IIT internal site
• Installation is very simple
• After installation you can create logins for
different users
Linux Basics
• Each user may login by his/her own login and
passwd – own login area
• Upon login, default directory is home
directory of the user
• In Computer center, We will provide machine
with Linux installed.
Screen shot : Window & Linux

• Both are equally Good and Powerful


• Window: User friendly, prone to Virus,
Commercial (Not Free: you have to Pay Money)
• Linux : Robust and Freely available 32
Linux basics: Command, Shell Basic
Linux basics: Command, Shell Basic
• Whatever you can do by clicking using GUI
– Same can be done by textual command
• Doing using GUI and mouse click
– Is easy and convenient for layman users
• Internally : Mouse click convert get
converted to textual command and
execute
• Textual commands are
–Faster and easy to understand
Linux basics: Shell Basic
• Command Prompt
• Linux/Unix is case sensitive i.e. WHO is not
same as who
• Shell is a command program to communicate
with a computer
• Shell interprets the command that you enter
on keyboards
• Shell commands can be used to automate
various programming tasks
Linux commands
• Usually short and cryptic like
–vi or rm
• Commands may also have modifiers
for advance options like:
–“ls –l” and “mv –R” are different that
“ls” or “mv” respectively
Important commands
• ls: listing of the current directory
• cp: Copy file from source to
destination
• mv: Move file from source to
destination
• vi, Edit a file. vi is one of the most
powerful text editors
Important Linux Commands
• chmod, Change file permissions
•mkdir, rmdir Make/Remove a
directory
•cd, Change directory
•rm, Remove a file. Can also remove
directory tree
• man ls, Get help for ls.
Command: ls
• Command to list files and directory ls
• [user1@localhost] $ ls

• Command : ls *.c
list all file with extension .c
List all C file in the current dirctory
• Command: ls a*
list all the file/directory started with a
Wildcards
• You can substitute the * as a wildcard symbol
for any number of characters in any
filename.

• You can mix the * with other characters to


form a search pattern:
ls a*.txt will list all files that start with “a”
and end in “.txt”
• The “?” wildcard stands for any single character:
ls draft?.doc will list draft1.doc, draft2.doc,
draftb.doc, etc.
Control characters
• You type Control characters by holding down
the ‘control’ key while also pressing the
specified character.
• While you are typing a command:
• ctrl-W erases the previous word
• ctrl-U erases the whole command line
• Control commands that work (almost) any time
• ctrl-S suspends (halts) output scrolling up on your
terminal screen
• ctrl-Q resumes the display of output on your screen
• ctrl-C will abort any program
Text Editors Available on Linux Systems
• Vi/vim
– Non-graphical (terminal-based) editor.
– Guaranteed to be available on any system.
– Requires knowledge of arcane keystroke commands.
– Distinctly unfriendly to novices.
• emacs, gedit, kwrite, pico
– Window-based editor
– Primitive menus make it slightly more friendly to
novices.
– Emacs: Still need to know keystroke commands to
use.
– Installed on all Linux distributions and on most other
Unix systems.
File Type and permission
• $ls –l
list all file in detail
• $file test.c
executable, text, media, library
• Attribute of file and directory
– User, group and others

43
Help on command line: Manual page
• Best local resources in the Linux System
– man : Type man and the name of a command to read
the manual page for that command. e.g. “man ls”
– man mv
• You can find many web resources on Linux
command
– Basic Linux Command References @
http://jatinga.iitg.ernet.in/~cs110/pdf/linux_cmd_refer
ence.pdf

Vous aimerez peut-être aussi