Title: CSCI6370: Topics in Computer Science Advanced Topics in Algorithms and Applications Fall Semester, 2002
1Lecture 1 Introduction to Computers
2OBJECTIVES
- In this lecture you will learn
- Basic computer concepts.
- The different types of programming languages.
- The influential programming languages.
- The purpose of the C Standard Library.
- The elements of a typical C program development
environment. - To write simple computer programs in C.
3What is a Computer?
- Computer
- Device capable of performing
- computations and making logical
- decisions.
- Processing data under the control
- of sets of instructions called computer
programs. - Hardware
- Various devices comprising a computer.
- Keyboard, screen, mouse, disks, memory, CD-ROM,
and processing units. - Software
- Programs that run on a computer.
4Computer Organization
- Six logical units
- Input unit Obtains information from input
devices (keyboard, mouse) - Output unit Outputs information (to screen,
printer, other devices) - Memory unit Rapid access, low capacity,
temporarily storing information - Arithmetic and logic unit (ALU) Performs
arithmetic calculations and logic decisions - Central processing unit (CPU) Supervises and
coordinates the whole computer - Secondary storage unit
- Cheap, long-term, high-capacity storage
- Stores inactive programs
- Monitor
- Motherboard
- CPU
- Main memory
- Expansion cards
- Power supply unit
- Optical disc drive
- Hard disk drive
- Keyborad
- mouse
5Motherboard and CPU
6Operating Systems
- What is the OS?
- Resource allocator
- allows the proper use of resources
- (hardware, software,data)
- provides an environment in which
- other programs can do useful work
- Control program
- controls the execution of user programs to
prevent errors and improper use of the computer - controls the operation of I/O devices
- What is the purpose?
- Manage transitions between jobs
- Increasing throughput (amount of work processed)
7Operating Systems - A Short History
- Simple batch systems
- Do only one job or task at a time. The programs
and data were submitted in batches with punch
cards. - IBSYS (1950s)
- Multi-programming (multi-tasking) batch systems
- Computer resources are shared by multiple jobs or
tasks - IBMs OS/360 (early 1960s)
- Time-sharing systems
- Computer runs a small portion of one users job
then moves on to service the next user - MITs CTSS (1962), Multics (1968), UNIX (1969)
- Personal computer systems
- Microprocessor technology evolved to the point
that it become possible to build desktop
computers as powerful as the mainframes of the
1970s. - DOS (1980), Windows 3.0 (1990), Linux (1991)
8Programming Languages
Three types of programming languages.
- Machine languages
- Strings of numbers giving machine
- specific instructions
- Example 1300042774
- 1400593419
- 1200274027
- Assembly languages
- English-like abbreviations representing
- elementary computer operations
- (translated via assemblers)
- Example LOAD BASEPAY
- ADD OVERPAY
- STORE GROSSPAY
9Programming Languages
Three types of programming languages (cont.)
- High-level languages
- Codes similar to everyday English
- Use mathematical notations
- Example
- grossPay basePay overTimePay
- Execution of high-level language programs
- Complier to convert high-level language programs
into machine language. - Interpreter to execute high-level language
programs directly without compiling into machine
language. - Compiling takes a considerable amount of computer
time. - Compiled programs execute much faster than
interpreted programs.
10Influential Programming Languages
- Fortran (IBM 1950s)
- Used for scientific and engineering applications
require complex mathematical computations - COBOL (1959)
- Used for commercial applications that require
precise and efficient manipulation of large
amounts of data - Pascal (Prof. Niklaus Wirth, 1971)
- Designed for teaching structured programming
- Ada (DOD, 1970s and early 1980s)
- Able to perform multitasking
- C (late 1970s)
- Evolved from B (BCPL) by Dennis Ritchie at Bell
Lab, 1972 - Development language of UNIX
- Widely used to develop modern operating systems.
- Hardware independent (portable)
11Influential Programming Languages
- C (Bjarne Stroustrup at Bell Labs, 1983-1985)
- Superset of C, providing object-oriented
capabilities - Objects reusable software components that model
- items in the real world.
- Object-oriented programming technique can make
- software development much more effective
- Dominant language in industry and academia
- JAVA (Sun Microsystems, 1995)
- Create Web pages with dynamic and interactive
content - Develop large-scale enterprise applications
- Enhance the functionality of Web servers
- Provide applications for intelligent consumer
devices (such as cell phones, pagers, and
personal digital assistants)
12C Standard Library
- C programs consist of pieces/modules called
functions - A programmer can create his/her own functions
- Pros the programmer knows exactly how it works
- Cons time consuming
- Programmers often use the C library functions to
avoid re-inventing the wheel - If a pre-made function exists, generally best to
use it rather than write your own - Library functions carefully written, efficient,
and portable - C standardization
- Many variation that were similar existed, and
were incompatible across hardware platforms - A standard version of C was needed
- ANSI/ISO C created in 1989 and updated in 1999
13Typical C Program Development Environment
- Phases of C
- programming
- Edit
- Preprocess
- Compile
- Link
- Load
- Execute
openSUSE gedit gcc
14A Simple C Program
/ and / indicate comments ignored by compiler
include directive tells C to load a particular
file
Every C program begins executing at the function
main.
Left brace declares beginning of main function
Statement tells C to perform an action
return statement ends the function
Right brace declares end of main function
- Print a line of text
- Illustrate several important features of the C
language
15A Simple C Program
- Comments
- Text surrounded by / and / is ignored by
compiler - Used to describe program
16A Simple C Program
- include ltstdio.hgt
- Preprocessor directive
- Tells computer to load contents of a certain file
- ltstdio.hgt allows standard input/output operations
17A Simple C Program
- int main()
- C programs contain one or more functions, exactly
one of which must be main - Parenthesis used to indicate a function
- int means that main "returns" an integer value
- Braces ( and ) indicate a block
- The bodies of all functions must be contained in
braces
18A Simple C Program
- printf( "Welcome to C!\n" )
- Entire line called a statement
- All statements must end with a semicolon ()
- Instructs computer to perform an action
- prints the string of characters within quotes ("
") - Escape character (\)
- \n is the newline character
19Some Common Escape Sequences
20A Simple C Program
- return 0
- A way to exit a function
- return 0, in this case, means that the program
terminated normally
21A Simple C Program
- Right brace
- Indicates end of main has been reached
22Good Programming Practice
- Every function should be preceded by a comment
describing the purpose of the function. - Add a comment to the line containing the right
brace that closes every function, including
main. - The last character printed by a function that
displays output should be a newline (\n). - Ensures that the function will leave the screen
cursor positioned at the beginning of a new line. - Conventions of this nature encourage software
reusabilitya key goal in software development
environments. - Indent the entire body of each function one level
of indentation within the braces that define the
body of the function. - Emphasizes the functional structure of programs
- Helps make programs easier to read
- Uniformly apply a fixed size of indent.
23Example of Using \n
printf statement starts printing from where the
last statement ended, so the text is printed on
one line.
output
24Example of Using \n
Newline characters move the cursor to the next
line
output