Sie sind auf Seite 1von 41

TCP1231 Computer Programming I

FIST / FIT
Multimedia University

1
Computer Programming I
Notes and Tips
 Attendance… 75% no compromise
 Read slides… before come to the class
 Plagiarism… I know all your code
 Exercise… you have to do a LOT
» TCP1231 is not a reading or memorizing subject – it’s
like Maths -> lots of practice and discussion
» You will realize as you go along that the main task in
this subject is PROBLEM SOLVING

 Problem… come to see the tutors and/or


lecturers
2
Computer Programming I
Objectives
 To help students achieve a reasonable
level of competence in both problem
solving and writing computer programs
using C++ programming language.
 To encourage students to appreciate the
value of adopting good programming style
and taking a structured modular approach
to the design of programs.

3
Computer Programming I
Skills expected to be acquired
 Problem solving and software development
using C++ language
 The use of a range of software tools and
packages (compiler, development
environment, debugger, word processor)
 Practical skills in an operating system
environment (Windows) and the use of the
internet and online resources

4
Computer Programming I
Course Outline
 Lec1 – Introduction to programming and computing
 Lec2 – Algorithms and Problem Solving
 Lec3 – C++ Basics Part-1
 Lec4 – C++ Basics Part-2
 Lec5 – More Flow of Control
 Lec6 – Procedural Abstraction and Functions Part-1
 Lec7 – Functions Part-2, Modular Design, Namespaces and Separate
Compilation
 Lec8 – Arrays
 Lec9 – Introduction to Classes & Structures
 Lec10 – Arrays, Strings & Vectors
 Lec11 – Pointers
 Lec12 – Pointers & Dynamic Arrays
 Lec13 – I/O Stream and Files
 Lec14 – C Programming Features (extra)
5
Computer Programming I
Coursework and Examinations
 Final Exam (40%)
 Coursework (60%)
 10% Lab Test
 10% Mid-term
 30% Assignments (10%+20%)
 10% Quizzes (5 Quizzes)
• During lab session starting from week 3.

6
Computer Programming I
Lecture Plan

7
Computer Programming I
Resources
 Textbook
 Walter Savitch, Problem Solving with
C++, Addison Wesley
 Reference
 C++ Primer Plus by Stephen Prata
 The C++ Programming Language: Special
Edition by Bjarne Stroustrup
 Starting Out with C++ by Graddis, Krupnow

8
Computer Programming I
Lecture 1
Introduction
to
Computers & Programming

9
Computer Programming I
Overview
 Computer systems
 Programming languages
 Compiler
 Linker

10
Computer Programming I
Computer System
 A computer program is…
 A set of instructions for a computer to follow

 Computer software is …
 The collection of programs used by a computer
• Includes:
» Editors
» Translators
» System Managers

11
Computer Programming I
Hardware
 Three main classes of computers

 PCs (Personal Computer)


• Relatively small used by one person at a time

 Workstation
• Larger and more powerful than a PC

 Mainframe
• Still larger
• Requires support staff
• Shared by multiple users

12
Computer Programming I
Networks
 A number of computers connected to
share resources
 Share printers and other devices
 Share information

13
Computer Programming I
Computer Organization

14
Computer Programming I
Computer Organization
 Five main components
1) Input devices
– Allows communication to the computer
2) Output devices
– Allows communication to the user
3) Processor (CPU)
4) Main memory
– Memory locations containing the running program
5) Secondary memory
– Permanent record of data often on a disk

15
Computer Programming I
Computer Memory
 Main Memory
 Long list of memory locations
• Each contains zeros and ones
• Can change during program execution
 Binary Digit or Bit
• A digit that can only be zero or one
 Byte
• Each memory location has eight bits
 Address
• Number that identifies a memory location
16
Computer Programming I
Larger Data Items
 Some data is too large for a single byte
 Most integers and real numbers are too large

 Address refers to the first byte

 Next few consecutive bytes can store the


additional bits for larger data

17
Computer Programming I
18
Computer Programming I
Data or Code?
 ‘A’ may look like 01000001
 65 may look like 01000001
 An instruction may look like 01000001

 How does the computer know the meaning


of 01000001?
 Interpretation depends on the current instruction

 Programmers rarely need to be concerned with


this problem.
 Reason as if memory locations contain letters and
numbers rather than zeroes and ones

19
Computer Programming I
Secondary Memory
 Main memory stores instructions and
data while a program is running.
 Secondary memory
 Stores instructions and data between sessions
 A file stores data or instructions in secondary
memory

20
Computer Programming I
Secondary Memory Media
 A computer might have any of these
types of secondary memory
 Hard disk
• Fast
• Fixed in the computer and not normally removed
 Floppy disk
• Slow
• Easily shared with other computers
 Compact disk
• Slower than hard disks
• Easily shared with other computers
• Can be read only or re-writable
21
Computer Programming I
Memory Access
 Random Access
 Usually called RAM
• Computer can directly access any memory location

 Sequential Access
 Data is generally found by searching through
other items first
• More common in secondary memory

22
Computer Programming I
The Processor
 Typically called the CPU
 Central Processing Unit
 Follows program instructions
 Typical capabilities of CPU include:
• add
• subtract
• multiply
• divide
• move data from location to location

23
Computer Programming I
Computer Software
 The operating system
 Allows us to communicate with the computer
 Is a program
 Allocates the computer’s resources
 Responds to user requests to run other
programs

 Common operating systems include…


 UNIX Linux DOS
Windows Macintosh VMS
24
Computer Programming I
Computer Input
 Computer input consists of
 A program

 Some data

25
Computer Programming I
Computer Input

26
Computer Programming I
High-level Languages
 Common programming languages include …

C C++ Java Pascal Visual Basic FORTRAN


COBOL Lisp Scheme Ada

 These high – level languages


 Resemble human languages
 Are designed to be easy to read and write
 Use more complicated instructions than
the CPU can follow
 Must be translated to zeros and ones for the CPU
to execute a program
27
Computer Programming I
Low-level Languages
 An assembly language command such as

ADD X Y Z

might mean add the values found at x and y


in memory, and store the result in location z.

 Assembly language must be translated to


machine language (zeros and ones)
0110 1001 1010 1011
 The CPU can follow machine language

28
Computer Programming I
Programming Languages
 Various programming languages enable
people to tell computers what to do
 Foundation for developing applications

29
Computer Programming I
Programming Languages
 Machine Language (first generation)
 The computer’s ‘native language’
 Composed of binary digits (0s, 1s)
 Eg. 0110 1001 1010 1011
 The only language that computers understand
 Assembly Language (second generation)
 One-to-one correspondence to machine language
 Somewhat more user-friendly than machine
language (mnemonic rather than binary digits)
 Eg. ADD X Y Z
 Assembler – program that translates an assembly
language program into machine language

30
Computer Programming I
Programming Languages
 Procedural Languages (third generation)
 One instruction translates into many machine
language instructions
 Programs describe the computer’s processing
step-by-step
 Closer to natural language; uses common words
rather than abbreviated mnemonics
 Examples: C, C++, Java, Fortran, QuickBasic
 Compiler - translates the entire program at once
 Interpreter - translates and executes one source
program statement at a time

31
Computer Programming I
Programming Languages
 Nonprocedural Languages (fourth generation)
 Allows the user to specify the desired result without
having to specify the detailed procedures needed
for achieving the result
Example: – database query language - SQL
Can be used by non technical users
 Natural Language Programming Languages
(fifth generation (intelligent) languages)
 Translates natural languages into a structured,
machine-readable form
 Are extremely complex and experimental

32
Computer Programming I
Current Programming Languages
 Object-Oriented Programming Languages (OOP)
 based on objects – packaging data and the
instructions about what to do with that data together
 Examples: Java, C++

 Visual Programming Languages


 Used within a graphical environment
 Examples : Visual Basic and Visual C++
 Popular to non technical users.

33
Computer Programming I
Current Programming Languages
 Hypertext Markup Language (HTML)
 standard language used in World Wide Web
 contains text, images, and other types of
information such as data files, audio, video, and
executable computer programs
 Extensible Markup Language (XML)
 Improved on web document functionality
 Virtual Reality Modeling Language (VRML)
 a file format for describing three-dimensional
(3D) interactive worlds and objects
 can be used with the World Wide Web
34
Computer Programming I
Compilers
 Translate high-level language to
machine language

 Source code
• The original program in a high level language
 Object code
• The translated version in machine language

35
Computer Programming I
Compilers

36
Computer Programming I
Linkers
 Some programs we use are already compiled
 Their object code is available for us to use
 For example: Input and output routines

 A Linker combines
 The object code for the programs we write
and
 The object code for the pre-compiled routines
into
 The machine language program the CPU can run

37
Computer Programming I
Linkers

38
Computer Programming I
How are Programs Understood by
the Computer?
 The Language Translation Process

Program written in Translator Program written in


programming program machine language
language  Assembler (object code)
(source code)
 Compiler
 Interpreter
Processed
By CPU

39
Computer Programming I
History Note
 First programmable computer
 Designed by Charles Babbage
 Began work in 1822
 Not completed in Babbage’s life time

 First programmer
 Ada Augusta, Countess of Lovelace
• Colleague of Babbage

40
Computer Programming I
End

41
Computer Programming I

Das könnte Ihnen auch gefallen