lecture 1 introduction to computing · lecture 1 introduction to computing a. sahu and s. v. rao...
TRANSCRIPT
Lecture 1 Introduction to ComputingIntroduction to Computing
A. Sahu and S. V. RaoDept of Comp. Sc. & Engg.Dept of Comp. Sc. & Engg.
Indian Institute of Technology Guwahati
1
OutlineOutline• Computer System P bl S l i d Fl Ch• 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 Executee, o p e a d ecu e–Explanation of C program
• Demonstration: if possibleDemonstration: if possible2
What Is A Computer?What Is A Computer?• An electronic device
d l f• Operates under control of instructions(software)
• Stored in its own memory unit• It can
– Accept data (input),– Manipulate data (process),Manipulate data (process),– Produce output from the processing.
• A collection of devices that function together• A collection of devices that function togetheras a system. 3
Computer Systemp y
Processing O/PI/P
• Keyboard, Mouse : Input• Speaker, Monitor/Display : Output• CPU Box : Processing
4
Computer System: Von Newman Memory
I/P Processing O/PI/P
• Input and Output• ProcessingProcessing• Memory : Where it store
Instruction Data Intermediate compute– Instruction, Data, Intermediate compute
5
Computer System: h hWhen 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 iicon
• Application: Word, Excel, Internet Explorer, Mozilla Media PlayerMozilla, Media Player
10
Screen shot : Window & LinuxScreen shot : Window & Linux
• Both are equally Good and PowerfulBoth are equally Good and Powerful• Window: User friendly, prone to Virus, Commercial (Not Free: you have to Pay Money)Commercial (Not Free: you have to Pay Money)
• Linux : Robust and Freely available11
Application SoftwareApplication Software• Application Software consists of programs• That tell a computer how to produceinformation.
• Some of the more commonly used packagesare:– Word processing, SpreadsheetDatabase–Database
–Presentation graphics
12
Word Processingg
• 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 SoftwareDatabase Software
• Allows the user toAllows the user to enter, retrieve, and update dataupdate data
• In an organized and efficient mannerefficient manner
• With flexible inquiry d iand 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 BrowsingInternet Browsing
• Allows the user to browse website• View HTML pages• View HTML pages• Play internet video, games, do many things
17
How to create your own Application?How to create your own Application?• Operating System : Linux, Window• Applications: Word/Excel, Media Player, Mozilla, Explorer, etcp– We use it to do some tasks, but don’t know inside contents
• Programming helps us to create our own applicationpp– Already solution approach is known– Draw the flow chart write PseudocodeDraw the flow chart, write Pseudocode– Write code, compile, run and test
18
Programming: Purpose?Programming: Purpose? • Programming
– Purpose : to create a program that performs specific operations or exhibits a certain desired b hbehavior.
– 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 numberExample: Compute sum of first N natural number– Define Input {N}, Output {SUM}How to do : Flow chart– How to do : Flow chart
– Write the C/C++/{*} Code in Note/Paper
P• Program – Sequence of Instructions and Data– Can be run by
• Compiling and running I i• Interpreting
20
How to do programming • OS, Shell, IDE, Editor:
– Linux Bash Shell gedit/VI/PicoLinux, Bash Shell, gedit/VI/Pico– Word Processor is not used to write programIntegrated Development Environment: GUI Based– Integrated Development Environment: GUI Based
• TurboC/VisualC++/Kdevelop/Dev GUI
• Use the Program (Method 1)• Use the Program (Method 1)– Compiling: GCC, TCC, VCCR i / t– Running: ./a.out
• Use the Program (Method 2)– Interpret the program and run
21
Interpreter Vs CompilerInterpreter Vs Compiler• Interpreter
Examples: Shell/Command Prompts ML Perl– Examples: Shell/Command Prompts, ML, Perl, Python, Matlab
– Read code line by line and execute, sequential y , q– Basic syntax Errors occur at run time
• Compiler– Example: C, C++, Java– Read whole code together, make an executable and
th t blrun the executable– Basic syntax Errors don’t occur at run time, only logical and runtime error occursg
22
Interpreter ExampleInterpreter Example • Interpreter
E l b i d li l l t f Li– Examples: basic command line calculator of Linux– $bc
3*43*4126+ (3+2)^26+ (3+2)^231
• Doing small computation easier• Doing small computation easier• Interpreter can read from file and execute line by line example shell scriptby line, example shell script
23
Writing and Compiling C Program dunder Linux
Header file: Standard#include <stdio.h>
i i
Standard Input/Output
int main(){
printf(“Hello world”);Starting of program
printf( Hello world );
return 0; Printing message;}
End of program
24
End of program
Compiling program: test.cCompiling program: test.c• Compiling : $gcc test.c• Listing : $ls
test c a outtest.c a.out• Execute the program : $./a.out
Hello world
25
Example 1: Adding two number
START
Flowchart
• Step 1: Input A and B Input A and B• Step 2: S ← A + B • Step 3: Print S
S← A BS ← A + B
Print SPrint S
STOP
Sum A+B : Input and output#include <stdio.h>
i t i (){Header file: int main(){
int A,B, S;printf(“Enter two
Standard Input/Output
printf( Enter two numbers ”);
scanf(“%d %d”,&A,&B);
Printing message
S=A+B;Asking for inputs
printf(“Res=%d”, B);return 0;
Compute
Output Result
27
return 0; }
logical mistake, should be S
Compiling program: test.c• Compiling : $gcc ‐Wall test.c
I i d i bl W ll i i llIt is advisable to use –Wall option to raise all warnings of the code
• Listing using $lstest c a outtest.c a.out
• Executing : $./a.outInput two numbers 5 7Res=12Res=12
28
C Programming in Liunx EnvironmentC Programming in Liunx Environment • We will be using Linux environment in CS110 Lab
• Editor : vim and gedit• Editor : vim and gedit• Compiler: GCC (Gnu Compiler Collection)Y h ld k bit f Li d• 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• Available as sets of DVDs and IIT internal site• Installation is very simple
f ll l f• After installation you can create logins for different users
Linux Basics• Each user may login by his/her own login and passwd – own login areapasswd own login area
• Upon login, default directory is home directory of the userdirectory of the user
• In Computer center, We will provide machine with Linux installedwith Linux installed.
Screen shot : Window & LinuxScreen shot : Window & Linux
• Both are equally Good and PowerfulBoth are equally Good and Powerful• Window: User friendly, prone to Virus, Commercial (Not Free: you have to Pay Money)Commercial (Not Free: you have to Pay Money)
• Linux : Robust and Freely available32
Linux basics: Command, Shell Basic• Whatever you can do by clicking using GUI
– Same can be done by textual commandSame can be done by textual command
• Doing using GUI and mouse click – Is easy and convenient for layman users
• Internally : Mouse click convert get y gconverted to textual command and executeexecute
• Textual commands are –Faster and easy to understand
Linux basics: Shell BasicLinux basics: Shell Basic• Command PromptLi /U i i iti i WHO i t• 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 tasksp g g
Linux commandsLinux commands
• Usually short and cryptic like• Usually short and cryptic like–vi or rm
• Commands may also have modifiers for advance options like:for advance options like:–“ls –l” and “mv –R” are different that “ls” or “mv” respectively
Important commandsImportant commands• ls: listing of the current directory
• cp: Copy file from source to d ti tidestination
• mv: Move file from source to• mv: Move file from source to destination
• vi, Edit a file. vi is one of the most powerful text editors
Important Linux CommandsImportant Linux Commands• chmod, Change file permissions
•mkdir, rmdir Make/Remove a di tdirectory
•cd Change directory•cd, Change directory
•rm Remove a file Can also remove•rm, Remove a file. Can also remove directory tree
• man ls, Get help for ls.
Command: lsCommand: ls• Command to list files and directory ls• [user1@localhost] $ ls
• Command : ls *.c list all file with extension .clist all file with extension .c List all C file in the current dirctory
• Command: ls a*• Command: ls a* list all the file/directory started with a
WildcardsWildcards• You can substitute the * as a wildcard symbol for any number of characters in anyfor 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”
Th “?” ild d t d f i l h t• The “?” wildcard stands for any single character:ls draft?.doc will list draft1.doc, draft2.doc,
draftb.doc, etc.f ,
Control charactersControl characters• You type Control characters by holding down the ‘control’ key while also pressing thethe control key while also pressing the specified character. Whil t i d• While you are typing a command:
• ctrl‐W erases the previous word • ctrl‐U erases the whole command line• ctrl‐U erases the whole command line
• Control commands that work (almost) any time• ctrl S suspends (halts) output scrolling up on your• 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. d b l bl– Guaranteed to be available on any system.
– Requires knowledge of arcane keystroke commands. Distinctly unfriendly to novices– Distinctly unfriendly to novices.
• emacs, gedit, kwrite, pico– Window‐based editorWindow 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 otherInstalled on all Linux distributions and on most other Unix systems.
File Type and permissionFile Type and permission
• $ls –l• $ls –llist all file in detail
• $file test.cexecutable text media libraryexecutable, text, media, library
• Attribute of file and directory–User, group and others
43
Help on command line: Manual pageHelp on command line: Manual page• Best local resources in the Linux System
– man : Type man and the name of a command to readthe manual page for that command. e.g. “man ls”
– man mv
• You can find many web resources on Linuxycommand– Basic Linux Command References @– Basic Linux Command References @http://jatinga.iitg.ernet.in/~cs110/pdf/linux_cmd_reference pdfence.pdf