0% found this document useful (0 votes)
17 views

程式設計C++ Introduction to Programming 20240916

Uploaded by

vanness670trash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

程式設計C++ Introduction to Programming 20240916

Uploaded by

vanness670trash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

張孟洲

8339
[email protected]

1
 本課程教授C/C++程式語言與程式設計之觀念。

物件導向程式設計
Object-Oriented Programming (OOP): C++
Classes 類別 and Objects 物件;
C

 大二下 進階程式設計 Python


 Verilog 硬體描述語言Hardware Description Language

2
 (1) Introduction to C/C++ Basics;
 (2) Flow of Control; C++
 (3) Functions;
 (4) Arrays; C
 (5) Pointers;
 (6) File Processing;
 (7) Object-Oriented Programming: Classes
and Objects;
 (8) Operator Overloading;
 (9) Inheritance;
 (10) Polymorphism;

3
 Paul J. Deitel , Harvey Deitel
 C++ How to Program : Late Objects Version,
Seventh Edition
 Prentice Hall, 2010
 ISBN:0132484587

 國內代理商 開發圖書
 甘興邦 0916-709655
 Tel:02-82423988
 email: [email protected]

4
5
6
 機械語言machine language
▪ 0110 1001 1010 1011
▪ 1001 0101 1100 0110
▪ 不同的CPU有不同的機械語言
▪ 程式不具可攜性portability

 組合語言assembly language
▪ ADD R1, R2, R3
▪ SUB R4, R1, R5
▪ 透過Assembler轉成機械碼
▪ 不同的CPU有不同的組合語言
▪ 程式不具可攜性portability
7
8
9
 高階語言high-level language
▪ z=x+y
▪ Resemble human languages
▪ Are designed to be easy to read and write
▪ Must be translated to machine codes for the CPU to
execute a program
▪ Better Portability
▪ 如Basic, Fortran, Pascal, C, C++,C# (C sharp), Java,
Python….

10
 C was implemented in 1972 by Dennis Ritchie at Bell
Laboratories.
◦ Initially became widely known as the UNIX operating system’s
development language.
◦ Today, most of the code for general-purpose operating systems is
written in C or C++.
 C++ evolved from C, which is available for most
computers and is hardware independent.
1972 Dennis Ritchie 發展C語言
用它來寫Unix OS
可攜性 C++
Early 1980s Bjarne Stroustrap 加上支援 C
OOP (Object-Oriented Programming物件導
向程式設計)的功能➔ C++ © Copyright 2017 by Pearson Education, Ltd.
All Rights Reserved.
 The widespread use of C with various kinds of
computers (sometimes called hardware platforms) led
to many variations.
 American National Standards Institute (ANSI)
cooperated with the International Organization for
Standardization (ISO) to standardize C worldwide.
 Joint standard document was published in 1990.

1983 ANSI C

1998 ANSI C++

© Copyright 2017 by Pearson Education, Ltd.


All Rights Reserved.
 C++, an extension of C, was developed by Bjarne Stroustrup
in 1979 at Bell Laboratories.
 C++ provides a number of features that “spruce up” the C
language.
 C++ also provides capabilities for object-oriented
programming that were inspired by the Simula simulation
programming language.

© Copyright 2017 by Pearson Education, Ltd.


All Rights Reserved.
 C++ Standard Library
◦ C++ programs consist of pieces called classes and functions.
◦ Most C++ programmers take advantage of the rich
collections of classes and functions in the C++ Standard
Library.
◦ Two parts to learning the C++ “world.”
 The C++ language itself (the core language), and
 How to use the classes and functions in the C++ Standard
Library.
◦ Many special-purpose class libraries are supplied by
independent software vendors.

© Copyright 2017 by Pearson Education, Ltd.


All Rights Reserved.
15
16
17
18
19
#include <iostream>
using namespace std;

int main()
{

cout << "Hello"<< endl;


return 0; //此行可省略不寫

20
 C語言程式是由許多函式(function)所組成,
 一定包含一個主函式main( )。
 程式是從main( )開始執行。

 int main( )
◦ 傳回值的型態,main()做完後會傳回一個整數

 return 0;
 //函式結束並傳回一個值0

21
 cout 標準輸出,monitor

 把字串印到螢幕
◦ cout << 字串常數;

 字串常數前後用 ”括起來

22
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to C++!" << endl;
cout << "C++ is" << "very easy.";
cout << "I love C++!" <<endl;
cout << "3+6*8=" << 3+6*8 << endl;
}

23
1
https://visualstudio.microsoft.com/zh-hant/vs/

24
選擇Community 2022
免費版本

25
26
27
28
29
30
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to C++!" << endl;
cout << "C++ is" << "very easy.";
cout << "I love C++!" <<endl;
cout << "3+6*8=" << 3+6*8 << endl;
}

31
32
33
2
https://www.embarcadero.com/free-tools/dev-cpp?aldSet=en-GB

34
 https://www.embarcadero.com/free-
tools/dev-cpp?aldSet=en-GB

選擇FREE DOWNLOAD

35
填完個人資料後 按
DOWNLOAD NOW 36
37
38
File->New->Project

選Console Application

填Project Name
(如Project_10)

按OK

39
新增一個新資料夾
避免檔案太亂

給新資料夾取一個名字
如Project_10_dir

按開啟
40
按存檔

#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to C++!" << endl;
cout << "C++ is" << "very easy.";
cout << "I love C++!" <<endl;
cout << "3+6*8=" << 3+6*8 << endl;
}

41
#include <iostream>
using namespace std;
int main()
{
cout << "Welcome to C++!" << endl;
cout << "C++ is" << "very easy.";
cout << "I love C++!" <<endl;
cout << "3+6*8=" << 3+6*8 << endl;
}

42
Execute->Compile 若***.cpp尚未存檔, Dec-C++會要求你先
存檔. 選擇先前建立的資料夾 本機>文件
>Project_10_dir, main.cpp的檔名可修改
, 然後按存檔

Compilation results...
--------
- Errors: 0
- Warnings: 0
- Output Filename:
C:\Users\user\Documents\Project_10_dir\Project_10.exe
- Output Size: 2.98873424530029 MiB
- Compilation Time: 1.39s

注意!! 若Source Code有修改過


一定要重新Compile!!
再執行Run
43
Execute->Run

注意!! 若Source Code有修改過 一定要重新Compile!! 再執行Run

先前建立的資料夾 本機>文件>Project_10_dir

44
3
https://www.programiz.com/cpp-programming/online-compiler/

45
46
47
4
https://www.onlinegdb.com/online_c++_compiler

48
49
 平常表現 作業 點名 30% 點名不到扣分
 期中考35%
 期末考35%

 期中考 期末考 筆試 Closed book

 密碼 xxxxx

 電腦教室 開關門 同學4人

50

You might also like