Hello World!

Ruby @ Sprout 2023
Ruby@Sprout

內容大綱

Hello world!

Ruby@Sprout

開發環境

Environment

基本認識

Foundations

第一支程式

First Program!

基本認識

Ruby@Sprout
Foudations

Hello world!

為什麼要寫程式?
Why program?
Ruby@Sprout

Hello world! > 基本認識

什麼是程式?
What is a program?
Ruby@Sprout

Hello world! > 基本認識

什麼是程式?What is a program?
Ruby@Sprout

Hello world! > 基本認識

Ruby@Sprout

Hello world! > 基本認識

什麼是程式?What is a program?
如何寫出一個程式?
How to write a program?
Ruby@Sprout

Hello world! > 基本認識

Ruby@Sprout

Hello world! > 基本認識

如何寫出一個程式?How to write a program?

1. 確定要解決的問題

Ruby@Sprout

Hello world! > 基本認識

如何寫出一個程式?How to write a program?

1. 確定要解決的問題

2. 設計程式架構

Ruby@Sprout

Hello world! > 基本認識

如何寫出一個程式?How to write a program?

1. 確定要解決的問題

2. 設計程式架構

3. 編寫程式

Ruby@Sprout

Hello world! > 基本認識

如何寫出一個程式?How to write a program?

1. 確定要解決的問題

2. 設計程式架構

3. 編寫程式

4. 編譯程式

程式語言?程式碼?
Programming Language? Code?
Ruby@Sprout

Hello world! > 基本認識

Ruby@Sprout

Hello world! > 基本認識

程式語言?程式碼? Programming Language? Code?
這你
外ㄍㄡˊ人
@#$!@%!!^!@#^!%!$!@$!
Ruby@Sprout

Hello world! > 基本認識

程式語言?程式碼? Programming Language? Code?
這你
外ㄍㄡˊ人

:Hi, where r u from?

:Yes, I'm fine thank u, and u?

Ruby@Sprout

Hello world! > 基本認識

程式語言?程式碼? Programming Language? Code?

:電腦腦,去洗碗!

:???

:0010101110101

1001100011101

0101010100111

Ruby@Sprout

Hello world! > 基本認識

程式語言?程式碼? Programming Language? Code?

go_wash_dishes();

編譯器

01010110101

01010101110

00001011111

Ruby@Sprout

Hello world! > 基本認識

程式語言?程式碼? Programming Language? Code?
Ruby@Sprout

Hello world! > 基本認識

程式語言?程式碼? Programming Language? Code?

go_wash_dishes();

01010110101

01010101110

00001011111

Ruby@Sprout

Hello world! > 基本認識

程式語言?程式碼? Programming Language? Code?

01010110101

01010101110

00001011111

編譯器

C++ Code
(.cpp)
Machine Code
編譯 compile

go_wash_dishes();

Ruby@Sprout

Hello world! > 基本認識

程式語言?程式碼? Programming Language? Code?
  • C++ 是一種高階的程式語言
  • C++ 程式碼只是遵守 C++ 語法的文字檔
  • 我們用 .cpp 副檔名來分辨 C++ 程式碼
  • 編譯器將程式碼編譯成電腦能讀懂的機器碼

基本認識

Ruby@Sprout

遞迴二

Foundations

內容大綱

遞迴二

Ruby@Sprout

開發環境

Environment

基本認識

Foundations

第一支程式

First Program!

開發環境

Ruby@Sprout

遞迴二

Environment
整合式開發環境
IDE
(Integrated Development Environment)
Ruby@Sprout

Hello world! > 基本認識

整合式開發環境 IDE
Ruby@Sprout

Hello world! > 基本認識

  • 較好上手、缺乏彈性
  • Dev-C++(教室內適用)
  • Code::Blocks
  • XCode for MacOS
整合式開發環境 IDE
Ruby@Sprout

Hello world! > 基本認識

編輯器+編譯器
Editor+Compiler
Ruby@Sprout

Hello world! > 基本認識

編輯器+編譯器 Editor+Compiler
Ruby@Sprout

Hello world! > 基本認識

  • 任何文字編輯器
    • 記事本
    • Notepad++
  • VSCode
  • Vim
  • gcc
  • g++
  • clang
  • clang++

編輯器

編譯器

線上開發環境
Online IDE
Ruby@Sprout

Hello world! > 基本認識

線上開發環境 Online IDE
Ruby@Sprout

Hello world! > 基本認識

開發環境

Ruby@Sprout

遞迴二

Environment

內容大綱

遞迴二

Ruby@Sprout

開發環境

Environment

基本認識

Foundations

 

第一支程式

First Program!

第一支程式

Ruby@Sprout

遞迴二

First Program!
Hello, world!
Ruby@Sprout

Hello world! > 基本認識

Hello, world!
Ruby@Sprout

Hello world! > 基本認識

學習新語言,從髒話開始;

Fuck!

Shit!

Bitch!

Damn!

Darn!

Idiot!

Son of a *!

Hello, world!
Ruby@Sprout

Hello world! > 基本認識

學習新程式語言,從 Hello world 開始。

cout << "Hello, world!" << endl;
01010110101
01010101110
00001011111

編譯器

Hello, world!
Ruby@Sprout

Hello world! > 基本認識

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, world!" << endl;
}
include?
Ruby@Sprout

Hello world! > 基本認識

  • include
    告訴編譯器需要用到什麼標頭檔(函式庫)
  • <>
    包住標頭檔的符號
  • iostream
    Iput/Output Stream,掌管輸入輸出
Hello, world!
Ruby@Sprout

Hello world! > 基本認識

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, world!" << endl;
}
main?
Ruby@Sprout

Hello world! > 基本認識

  • int:資料型態,下半堂就會教到!
  • main:程式的進入點,程式從這裡開始執行
  • (){} 括號們:跟函式的概念有關,將會在幾週後介紹
  • 縮排 (tab),非必要但請養成好習慣!
Hello, world!
Ruby@Sprout

Hello world! > 基本認識

#include <iostream>
using namespace std;

int main() {
    cout << "Hello, world!" << endl;
}
cout?
Ruby@Sprout

Hello world! > 基本認識

  • 輸出的方法,用 << 可以串連多個東西
  • 要印出來的字用 " " 包住
  • endlEnd of Line,代表要印出的是換行符號
    (像按 <enter> 或 word 中的 ↩ 符號)
課堂練習
Exercises!
Ruby@Sprout

Hello world! > 基本認識

課堂練習 - 字串輸出
Ruby@Sprout

Hello world! > 基本認識

有些東西印不出來? - 跳脫字元
Ruby@Sprout

Hello world! > 基本認識

  • 有些字元是有特殊用途
    • " 是拿來包住字串的
    • ' 是拿來包住字元的(之後會介紹到)
    • <tab> 是拿來縮排
    • <enter> 是拿來換行
有些東西印不出來? - 跳脫字元
Ruby@Sprout

Hello world! > 基本認識

課堂練習 - 福祿猴的反敗
Ruby@Sprout

Hello world! > 基本認識

課堂練習解答 - 字串輸出
Ruby@Sprout

Hello world! > 基本認識

#include <iostream>

using namespace std;

int main() {
    cout << "It is no secret that today’s workforce no longer" << endl;
    cout << "consists entirely of people. Rather, machines are" << endl; 
    cout << "being developed to complete many of the tasks" << endl;
    cout << "which humans have traditionally done. This can" << endl;
    cout << "greatly increase productivity and efficiency of" << endl;
    cout << "simple, repetitive tasks. Many people view this" << endl;
    cout << "as a great positive and point out that it leads" << endl;
    cout << "to a more uniform and less expensive product which" << endl;
    cout << "is better for everyone. However, some people are" << endl;
    cout << "more wary of this popular trend of automating the" << endl;
    cout << "workforce and question whether this progress is" << endl;
    cout << "truely positive. Their concerns, though, are" << endl;
    cout << "outweighed by the benefits these machines offer." << endl;
    return 0;
}
課堂練習解答 - 字串輸出
Ruby@Sprout

Hello world! > 基本認識

#include <iostream>
using namespace std;

int main() {
    int r1, r2; cin >> r1 >> r2;
    cout << 4 * 3 * (r1 * r1 + r2 * r2);
}

第一支程式

Ruby@Sprout

遞迴二

First Program!

內容大綱

遞迴二

Ruby@Sprout

開發環境

Environment

基本認識

Foundations

 

第一支程式

First Program!
謝謝大家

Brought to you by Ruby
Ruby@Sprout

資訊之芽 Sprout 2023 - Hello world!

By Ruby Ku

資訊之芽 Sprout 2023 - Hello world!

  • 500