Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
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
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
12
Word Processing
15
Presentation Graphics
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”);
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
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
• 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.
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