Upload
tylor-holcomb
View
213
Download
0
Tags:
Embed Size (px)
Citation preview
Senem Kumova Metin 2010-2011
Introduction to Programming CS 115
Introduction to Computing
PART I : Computer BasicsPART II: Introduction to Computing/Programming
Senem Kumova Metin 2010-2011
PART I : Computer Basics
Contents
• Computer basics
• Hardware & software
• Hardware components
Senem Kumova Metin 2010-2011
What is a Computer?
• A computer is a machine that manipulates data according to a list of instructions
• Simply a computer
1. takes information (or inputs)2. processes it according to a set of instructions
(a program) 3. gives back a result (or output)
Senem Kumova Metin 2010-2011
Computing• Activity of using and developing computer
technology, computer hardware and software.
• Hardware – a general term that refers to the physical artifacts of
a technology • Software
– a general term used to describe a collection of computer programs, procedures and documentation that perform some tasks on a computer system
Senem Kumova Metin 2010-2011
Key components of a Computer
Senem Kumova Metin 2010-2011
Key components of a Computer
• Input Devices
– Receiving sections of computer– Allow the user to control the machine– Examples :
• Keyboard • Mouse • Microphone • Scanner• Etc..
Senem Kumova Metin 2010-2011
Key components of a Computer
• Output Devices
– Return the results of computer actions back to the user
– Examples :• Monitor • Speakers • Printer
Senem Kumova Metin 2010-2011
Key components of a Computer
• CPU ( Central Processing Unit)
– ‘brain’ of the computer
– Follows the instructions provided by both the user (via input devices) and the program that is running in order to perform a task
– Involves a control unit, ALU (Arithmetic Logic Unit), registers...
Senem Kumova Metin 2010-2011
Key components of a Computer• Memory
– Internal storage areas in the computer
– Retains information that has been entered through the input unit so that the information may be made available for processing when needed.
– RAM and ROM
• RAM - Random access memory: whose contents can be accessed (read, write and remove) in any order
• ROM - Read-only memory: On ROM, data is prerecorded for read only which can not be removed
Senem Kumova Metin 2010-2011
Key components of a Computer• Secondary Storage
– Long term high capacity warehousing part of the computer
– Store both the programs that run on the system as well as the work that is created
– The most common storage device is a fixed
magnetic disk that sits inside the machine and this is called the hard drive
– Examples: hard disk, CD,DVD and flash drives
Senem Kumova Metin 2010-2011
PART II : Introduction to Computing/Programming
Contents
• Computer programming
• Flow of Control
• Programming languages
• Programming in C
Senem Kumova Metin 2010-2011
WHAT is PROGRAMMING??scheduling or performing a task or / and event
WHAT is COMPUTER PROGRAMMING??creating a sequence of steps for a computer to follow in performing a task
Senem Kumova Metin 2010-2011
WHAT is a PROGRAMMING LANGUAGE ?
• A set of rules, symbols, and special words used to construct a computer program
Senem Kumova Metin 2010-2011
Programming language rules consist of
– Rules of Syntax which specify how valid instructions are written in the language
( natural language rule subject + verb +object )
– Rules of Semantics which determine the meaning of the instructions (what the computer will do)( A book has bitten a car )
Senem Kumova Metin 2010-2011
Programming Languages
• Machine Languages
• Assembly Languages
• High Level Languages
Senem Kumova Metin 2010-2011
Machine Language
• Machine dependent
• Machine code is a set of instructions that a computer's central processing unit (CPU) can understand and obey directly, without any translation.
• Machine-code programs consist entirely of binary digits (bits).
• BIT ?? BYTE??
Senem Kumova Metin 2010-2011
Assembly Language
• First attempt at producing a mechanism for writing programs that was more palatable to ourselves
• A program written in assembly code, in order to “run”, must first be translated (assembled) into machine code.
Senem Kumova Metin 2010-2011
High Level Languages
• A more problem-oriented (rather than machine-oriented) mechanism for creating computer programs would also be desirable
• Hence the advent of high(er) level languages starts with the introduction of “Autocodes”, and going on to Algol, Fortran, Pascal, Basic, Ada, C, etc
• Interpreted or compiled
Senem Kumova Metin 2010-2011
• Machine Language
+1300042774+1400593419+1200274027
• Assembly Language
Load basePayAdd overTimePayStore grossPay
• High level Language
grossPay= basePay+overTimePay
Classification of High level Programming languages
• Programming paradigm : Alternative approaches to the programming process
– Functional (Lisp, ML)– Object-Oriented (C++, Java)– Imperative (Procedural) (Fortran, Algol, Pascal,
Basic, C)– Declarative (Prolog,GPSS)
Senem Kumova Metin 2010-2011
Senem Kumova Metin 2010-2011
High Level Languages• Interpreted
– Interpreted Languages are read and then executed directly, with no compilation stage.
• Compiled
– Compiled Languages are transformed into an executable form before running.
Senem Kumova Metin 2010-2011
ASSEMBLY versus HIGH LEVEL LANGUAGE
HelloWorld.asm
Source Code
HelloWorld.c
Source Code
Machine Code (binary) Machine Code (binary)
Object Codeassembled
compiled
Library
(stdio.h)linked
Senem Kumova Metin 2010-2011
Compilation Process
Senem Kumova Metin 2010-2011
High Level Languages: Libraries
• Libraries (in computer programming terms) contain chunks of precompiled (object) code for various functions and procedures that come with a programming language that requires compilation
• For example functions and procedures to facilitate I/O
Senem Kumova Metin 2010-2011
Flow of Control
The execution sequence of a group of machine instructions is known as the flow of control.
Senem Kumova Metin 2010-2011
EXAMPLE 1: Flow of Control
SCENARIO :
we have 2 integers : x, y
multiply x with y
store the result in x
print the value of x
int x and int y
x = x*y
print x
Senem Kumova Metin 2010-2011
EXAMPLE 2: Flow of Control
SCENARIO :
we have 2 integers : x,y
if x is greater than 0 then
do x= y+1;
else
do x= y-1;
print the value of x
int x and int y
x > 0
YES NO
x = y+1 x = y-1
print x
Senem Kumova Metin 2010-2011
Why C?
• Native language of UNIX (a famous operating system)
• Standard development language for personal computers
• Portable (can be moved to other machine !)
• Powerful set of operators and powerful libraries (some operators: ++,--….)
• Basis for Java, C++…..
Senem Kumova Metin 2010-2011
First C program
– Basic I/O functions : printf / scanf– Including libraries– Writing comments– Defining variables ….
Senem Kumova Metin 2010-2011
Basic I/O Functions: printf
#include <stdio.h> // library file
void main(void)
{
printf("from sea to shining C\n");
}
// Print a string of characters to the screen
Senem Kumova Metin 2010-2011
Basic I/O Functions: printf
#include <stdio.h>
void main(void)
{
printf("from sea ”);
printf(“to shining C\n");
}
Senem Kumova Metin 2010-2011
Basic I/O Functions && Defining a variable
#include <stdio.h> // library file
void main(void)
{ int x=0;
// an integer variable is defined and it is
// initialized to 0
printf(“%d“, x);
// print current value of variable x as a decimal value
}
Senem Kumova Metin 2010-2011
Basic I/O Functions : scanf
#include <stdio.h>
void main(void)
{ int x=0;
printf(“%d\n”, x); // print x as a decimal value
scanf(“%d”,&x); // read a decimal value from keyboard, store it in x
printf(“%d\n”, x); // print x as a decimal value
}