2017 資訊營

Programming basics

A "Program" ?

If you think programming is

Assembly language

So we have

High level language !

You can use human-readable code

And turn it into machine code

Then run it

Let's get started!

Linux

Windows

  • Not free
  • closed source
  • often being attacked by virus
  • GUI friendly
  • for general use (slides/documents/games)

Linux

  • Free
  • open source
  • resist most virus designed for windows
  • CLI friendly
  • for development use (compilers/editors/...)

WannaCry ?

Linux command

指令 用途 用法
cd 進入目錄(資料夾) cd <directory>
ls  顯示目錄中檔案 ls [-la]
rm  刪除檔案 rm <file>
mkdir 建立目錄 mkdir <dir name>
g++ 編譯C++原始碼 g++ <file name>
./<program name> 執行程式 ./<program name>
vim 文字編輯器 見下頁

vim command

指令 用途 用法
i 進入輸入模式 i
ESC 回到指令模式 ESC
:w 存檔 :wq 存檔並離開
:q 離開 :q! 不存檔就離開
vim <filename> 開啟檔案用vim編輯

PRACTICE MODE

Try it !

 // use C++ standard library
#include <iostream>

using namespace std;

// each program must have main function
int main()
{
    cout << "Hello World!" << endl;
    //use "cout" to output text to screen
    return 0;
}

Run it !

Input data

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int number;
    cout << "Please input a number:";
    cin >> number;
    cout << "yout input is " << number << endl;

    return 0;
}

Multiple input

#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    int number1, number2;
    cout << "Please input 2 number:";
    cin >> number1 >> number2;
    cout << "number1 is " << number1 << endl;
    cout << "number2 is " << number2 << endl;

    return 0;
}

CSIE_CAMP_2017_CPP_1

By Liang Yu-Cheng

CSIE_CAMP_2017_CPP_1

Basic/IO/Execution

  • 1,496