Senem Kumova Metin Spring2009 STACKS AND QUEUES Chapter 10 in A Book on C.
Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I :...
-
Upload
tylor-holcomb -
Category
Documents
-
view
212 -
download
0
Transcript of Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I :...
![Page 1: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/1.jpg)
Senem Kumova Metin 2010-2011
Introduction to Programming CS 115
Introduction to Computing
PART I : Computer BasicsPART II: Introduction to Computing/Programming
![Page 2: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/2.jpg)
Senem Kumova Metin 2010-2011
PART I : Computer Basics
Contents
• Computer basics
• Hardware & software
• Hardware components
![Page 3: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/3.jpg)
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)
![Page 4: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/4.jpg)
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
![Page 5: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/5.jpg)
Senem Kumova Metin 2010-2011
Key components of a Computer
![Page 6: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/6.jpg)
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..
![Page 7: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/7.jpg)
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
![Page 8: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/8.jpg)
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...
![Page 9: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/9.jpg)
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
![Page 10: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/10.jpg)
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
![Page 11: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/11.jpg)
Senem Kumova Metin 2010-2011
PART II : Introduction to Computing/Programming
Contents
• Computer programming
• Flow of Control
• Programming languages
• Programming in C
![Page 12: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/12.jpg)
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
![Page 13: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/13.jpg)
Senem Kumova Metin 2010-2011
WHAT is a PROGRAMMING LANGUAGE ?
• A set of rules, symbols, and special words used to construct a computer program
![Page 14: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/14.jpg)
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 )
![Page 15: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/15.jpg)
Senem Kumova Metin 2010-2011
Programming Languages
• Machine Languages
• Assembly Languages
• High Level Languages
![Page 16: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/16.jpg)
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??
![Page 17: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/17.jpg)
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.
![Page 18: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/18.jpg)
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
![Page 19: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/19.jpg)
Senem Kumova Metin 2010-2011
• Machine Language
+1300042774+1400593419+1200274027
• Assembly Language
Load basePayAdd overTimePayStore grossPay
• High level Language
grossPay= basePay+overTimePay
![Page 20: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/20.jpg)
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
![Page 21: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/21.jpg)
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.
![Page 22: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/22.jpg)
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
![Page 23: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/23.jpg)
Senem Kumova Metin 2010-2011
Compilation Process
![Page 24: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/24.jpg)
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
![Page 25: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/25.jpg)
Senem Kumova Metin 2010-2011
Flow of Control
The execution sequence of a group of machine instructions is known as the flow of control.
![Page 26: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/26.jpg)
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
![Page 27: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/27.jpg)
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
![Page 28: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/28.jpg)
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++…..
![Page 29: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/29.jpg)
Senem Kumova Metin 2010-2011
First C program
– Basic I/O functions : printf / scanf– Including libraries– Writing comments– Defining variables ….
![Page 30: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/30.jpg)
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
![Page 31: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/31.jpg)
Senem Kumova Metin 2010-2011
Basic I/O Functions: printf
#include <stdio.h>
void main(void)
{
printf("from sea ”);
printf(“to shining C\n");
}
![Page 32: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/32.jpg)
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
}
![Page 33: Senem Kumova Metin 2010-2011 Introduction to Programming CS 115 Introduction to Computing PART I : Computer Basics PART II: Introduction to Computing/Programming.](https://reader030.fdocuments.us/reader030/viewer/2022032516/56649c735503460f949253fd/html5/thumbnails/33.jpg)
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
}