計算機程式
第一單元 Introduction to Computers, the Internet and the WWW
授課教師:廖婉君教授
【 本 著 作 除 另 有 註 明 外 , 採 取 創用 CC
「姓名標示-非商業性-相同方式分享」台灣 3.0
本課程指定教材
書名: C++ How to Program, 7/e
作者: Harvey M. Deitel and Paul J. Deitel 出版社: Deitel & Associates
出版日期: 2010
Computer:At A Glance (1/3)
• Hardware
o Central Procesing Unit (CPU) o Arithmetic and Logic Unit (ALU) o Main Memory
o Secondary Storage Unit o Input unit
o Output unit
o Network Interface
Computer:At A Glance (2/3)
• Software
o System software
• e.g.,Operating System (OS) o Application software
• e.g.,Powerpoint,MS Word,Sky pe
o Programming language
• Machine language
• Assembly language
• High-level language
Computer:At A Glance (3/3)
• Evolution of Computing/computer
o Main frame
o Personal computer o Networked computer
o Thin client and clout computing o Personal computing
o Distributed computing o Client/Server computing o Peer-to-peer computing
Basics of a Typical C++ Environment
• C++ system
o Program development environment o Language itself
o C++ standard libraray:
• Classes and functions
• Software IC
• Six phases
o Edit,preprocess,compile,link,load,execute o .cpp,.cxx,.cc,.c
o xx.cpp,#something,CC xx.cpp,a.out
Six Phases in Program Execution
C++ Program Structure
• Single-line comment line: //
• Preprocessor directives: # something
o e.g., #include
• Main body
o Classes and functions
o Must come/start with a function called main(),which is delimited by {}.
o Mostly come with I/O
A skeleton Outline of a Simple C++ Program
• //
• #include <iostream>
• int main (){
o return 0;
• }
preprocessor directive
program goes here!
Examples (1/2)
p.40
Examples (2/2)
p.44-45
Escape Characters
escape
sequence description
\n Newline. Position the screen cursor to the beginning of the next line.
\t Horizontal tab. Move the screen cursor to the next tab stop.
\r Carriage return. Position the screen cursor to the beginning of the current line; do not advance to the next line.
\a Alert. Sound the system bell.
\\ Backslash. Used to print a backslash character
\’ Single quote. Use to print a single quote character.
\” Double quote. Used to print a double quote character.
Another Example
p. 45
Another Example (cont.)
p. 46-49
C++ Keywords
C++ Keywords
Keywords common to the C and C++ programming languages
auto break case char const continue dafault
do double else enum extern float for
goto if int long register return short
signed sizeof static struct switch typedef union
unsigned void volatile while
C++ only keywords
and and_eq asm bitand bitor bool catch
class compl const_cast delete dynamic_cast explicit
export false friend inline mutable namespace
new not not_eq operator or or_eq private
protected public reinterpret_cast static_cast template this
Built–in Data Types
• bool
• char
• short int
• unsigned short int
• int
• unsigned int
• long int
• unsigned long int
• float
• double
• long double
bool
char
short int vs . unsigned short int
int vs. unsigned int
long int vs. unsigned long int
float
double
long double
Variables
• Memory concept
• Declaration
o date type variable name o e.g., int a;
• Variables have characteristics
o name,type,size ,and vale
o case sensitive: e.g.,CAT,Cat,cat o declared before used (anywhere) o legal identifier
• I/O: destructive vs. non-destr uctive
More on Operators
Operators Associativity Type
() left to right parentheses
* / % left to right multiplicative
+ - left to right additive
<< >> left to right stream insertion/extraction
< <= > >= left to right relational
== != left to right equality
= right to left assignment
associability
One More Example
p. 55-56
版權聲明
頁碼 作品 版權圖示 來源 / 作者
1-21 本作品轉載自 Microsoft Office 2007 多媒體藝廊,依據 Microsoft 服務合約及著作權法第
46、 52 、 65 條合理使用。
2
C++ How to Program, 7/e,作者: Harvey M. Deitel and Paul J. Deitel , 出版社: Deitel & Associates ,出版日期: 2010 。
本作品轉載自:
http://www.deitel.com/Books/C/CHowtoProgram7e/tabid/3472/Default.aspx,
依據著作權法第 46 、 52 、 65 條合理使用。
3
Open Clip Art Library,作者: kattekrab ,本作品轉載自:
http://openclipart.org/detail/20928/computer-workstation-by-kattekrab,
瀏覽日期: 2013/1/10 。
4 Open Clip Art Library,作者: sheikh_tuhin ,本作品轉載自:
http://openclipart.org/detail/78217/it-word-icon-by-sheikh_tuhin,瀏覽日期: 2013/1/10 。 4
Wikipedia,作者: Microsoft Corporation ,本作品轉載自:
http://en.wikipedia.org/wiki/File:Skype_logo.svg,瀏覽日期: 2013/1/10 。 依據著作權法第 46 、 52 、 65 條合理使用。
5 Open Clip Art Library,作者: lmproulx ,本作品轉載自:
http://openclipart.org/detail/3982/computer-by-lmproulx,瀏覽日期: 2013/1/10 。
版權聲明
頁碼 作品 版權圖示 來源 / 作者
7
Faculty Web Sites, Typical Java Development Environment(
http://faculty.inverhills.mnscu.edu/speng/cs1126/Notes/Chapter01/JavaDE.htm),瀏 覽日期: 2012/9/14 。依據著作權法第 46 、 52 、 65 條合理使用。
10、 11 、 13、 14 、
19
Open Clip Art Library,作者: aritztg ,本作品轉載自:
http://openclipart.org/detail/3422/mouse-by-aritztg,瀏覽日期: 2013/1/10 。
12
C++ How to Program, 7/e,作者: Harvey M. Deitel and Paul J. Deitel , 出版社: Deitel & Associates ,出版日期: 2010 , P.41 。
依據著作權法第 46 、 52 、 65 條合理使用。
15 臺灣大學電機系 廖婉君教授
18
C++ How to Program, 7/e,作者: Harvey M. Deitel and Paul J. Deitel , 出版社: Deitel & Associates ,出版日期: 2010 , P.49 。
依據著作權法第 46 、 52 、 65 條合理使用。