Transcript
Page 1: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

1

ENG236: Introduction (1) ENG236: Introduction (1)

Rocky K. C. ChangRocky K. C. Chang

THE HONG KONG

POLYTECHNIC UNIVERSITY

Page 2: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

2

References:References:

1. J. Liberty, Teach Yourself C++ in 24 hours. SAMS, 2005/2009 (electronic book in the library).

2. H. M. Deitel and P. J. Deitel, C++ How To Program, 6th Ed. Prentice Hall, 2008.

3. S. Prata, C++ Primer Plus. Fifth Edition, SAMS, 2005.

Computer Programming and Basic Software Engineering

Page 3: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

3

Contents

Computer Programming and Basic Software Engineering

1. Introduction (week 1)2. A Taste of C++ (week 1)3. The Nuts and Bolts (weeks 2-5)4. Basic Software Engineering (weeks 6-7)5. Objects and Classes in C++ (weeks 8-9)6. Pointers and Arrays (weeks 10-13)

7. Stream I/O8. Elementary Data Structure9. Building Graphical User Interface.

Second semester

First semester

Page 4: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

4

Getting Started

1. What is Computer Programming?

Page 5: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

5

Computer Programming:

A systematic approach to instruct a computer doing something for us.

Computer Programming and Basic Software Engineering1. What is Computer Programming?

Hardware

CPU

Memory

I/O devices

Page 6: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

6

Process of Computer Programming

Computing Problems

Algorithmsand Data Structures

High-levelLanguage

Hardware

Operating System

Application Software

Coding

Binding(Compile, link and load)

Mapping

Computer Programming and Basic Software Engineering1. What is Computer Programming?

Details in the following slides

Way of thinkingComputer

Page 7: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

7

Computing Problems

Algorithmsand Data Structures

High-levelLanguage

Hardware

Operating System

Application Software

Coding

Binding(Compile, link and load)

Mapping

Page 8: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

8

Identify the Problem• Before writing a program, ask yourselves two questions:

1. What is the problem I want to solve?

2. Do I really need to write a program to solve it?

• A problem can often be so large that requires the co-operation of a few programs to solve it.

• E.g. To design a computer game

- Design the story

- Design the graphics

- Design the motion

:

Computer Programming and Basic Software Engineering1. What is Computer Programming?

Page 9: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

9

• Do we need to write a program for the following problems?• Calculate the result of 1 + 1?

• Play a piece of MP3 music using the computer?

• Develop a Web page?

No. Just use your fingers!

No. Use application software such as Media Player.

Yes or no, depending on how complicated your Web page is.

• Usually we need to write a program if the problem is too complicated and specific to our needs.

Computer Programming and Basic Software Engineering1. What is Computer Programming?

Page 10: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

10

Computing Problems

Algorithmsand Data Structures

High-levelLanguage

Hardware

Operating System

Application Software

Coding

Binding(Compile, link and load)

Mapping

Page 11: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

11

Find the Best Algorithm• A problem can be solved by different approaches

• Using a clever approach can save you a lot of time in getting the result

• E.g.

Calculate 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12

• Solution?Use algorithm: 12 x (1 + 12) / 2 = 781 addition, 1 multiplication, 1 division

Computer Programming and Basic Software Engineering1. What is Computer Programming?

11 additions

Seems better, BUT ...

Page 12: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

12

• Consider the following situation:

• For a particular computer, it may take 10 s to compute an addition but uses 100 s to do a multiplication or division.

Calculate 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12

• Do you still want to use algorithm?

Direct addition: 110 sec Direct addition: 110 sec Use algorithm: 210 sec Use algorithm: 210 sec

Algorithm needs to match with the hardware architecture Algorithm needs to match with the hardware architecture

Computer Programming and Basic Software Engineering1. What is Computer Programming?

Page 13: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

13

Computing Problems

Algorithmsand Data Structures

High-levelLanguage

Hardware

Operating System

Application Software

Coding

Binding(Compile, link and load)

Mapping

Page 14: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

14

Coding• Computer can only understand 0 and 1.

• The most direct way to communicate with the computer is to use 0 and 1.

Machine Language Programming• 0110001111000010

0001000111100011

:

:

0011000100001000

1000001001010101

MachineLanguageProgram

Very tedious and can make error easilyVery tedious and can make error easily

Computer Programming and Basic Software Engineering1. What is Computer Programming?

Page 15: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

15

Coding - Assembly Language• Assembly Language is created to help human instruct CPU

to work.

• By using a software tool called Assembler, assembly language programs can be converted into machine language programs.

Assembler

01100011110000100001000111100011

::

00110001000010001000001001010101

LD R0, #05ADD R0, $1234

::

SUB R0, #22LD $2345, R0

Assembly Language Machine Language

Computer Programming and Basic Software Engineering1. What is Computer Programming?

Page 16: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

16

Coding - High Level Language

• Assembly language programming is still too complicated for general users.

• They are very different from human languages.

e.g. “Set W equal to W plus X minus Y divided by Z.”

“Repeat the next sequence of instructions until X is less than 0 or Y equals Z.”

• A high level language is needed to reduce the gap between human and computers.

Computer Programming and Basic Software Engineering1. What is Computer Programming?

Page 17: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

17

Give me the result of adding 1 to 10

Compiler

Linker10110101010101010101 :

High Level Program

ExecutableMachine Language Program

Object codeLibrary

Computer Programming and Basic Software Engineering1. What is Computer Programming?

.exe

.cpp

Details in the following slides

Page 18: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

18

• Compiler: Generate the object code.

• Object code Similar to the machine language code but cannot be executed because of the missing of some information.

• Linker: Resolve the missing information from the library or other programs.

For a program, it is very common that some of the information in the program needs to be obtained from the Library provided by the programming tool. It is the job of linker to obtain these missing information.

For a program, it is very common that some of the information in the program needs to be obtained from the Library provided by the programming tool. It is the job of linker to obtain these missing information.

Computer Programming and Basic Software Engineering1. What is Computer Programming?

Page 19: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

19

Coding - High Level Languages• From time to time, high level languages (HLL) are designed for

different purposes.

• Earlier examples: BASIC : for simple and general computing (obsolete for long) COBOL : for data processing (is still using in local banks) FORTRAN : for scientific computation (has been replaced by C or C++)

• Recent examples:

Pascal: a sophisticated but complicated HLL (replaced by C or C++)

C : a simple structural HLL for general computing (still in use)

• Current examples:C++ : the most well-known object-oriented (OO) language

Java : an OO language designed with the concept of networking.

Computer Programming and Basic Software Engineering1. What is Computer Programming?

Page 20: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

20

Programming - C++

• Object-Oriented programming concept is overwhelming.

• OO Programming has the advantage of achieving reuse of software components.

• The C++ programming language is created to implement the concept of OO programming.

• C++ is an extension of the C language.

• C++ has become the predominant language for the commercial software development.

• Standardized by the American National Standards Institute (ANSI), C++ program is portable to different machines.

Computer Programming and Basic Software Engineering1. What is a Computer?

Page 21: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

21

“Homework”

Install Visual Studio 2008 in your PC/notebook. Locate the electronic book “Teach Yourself C+

+ in 24 hours.”

Page 22: 1 ENG236: Introduction (1) Rocky K. C. Chang THE HONG KONG POLYTECHNIC UNIVERSITY

22

Acknowledgments

The slides are based on the set developed by Dr. Frank Leung (EIE).


Top Related