学习要点

  1. 什么是编程语言(EN: programming language)
  2. 初步了解以下基本概念
    1. 指令(EN: instruction)
    2. 语句(EN: statement)
    3. 函数、方法、过程(EN: function, method, or procedure)
    4. 参数(EN: parameter)
  3. 输出字符串

代码示例

C++ Sample Code 隐藏/显示注释

//【知识点】注释是供人了解程序的逻辑用的,不会转换成机器指令。有两种注释的方式。
//            1. 双斜杠//是单一行的注释,例如本行。
//            2. /* */是多行注释,例如下面的几行。
/*
 * 【知识点】写好的C++代码需要先经过编译成机器指令,然后执行。
 *    1. 在Dev-C++环境中的编译和执行。
 *       1.1. 编译:  F9(或者选择菜单运行-> 编译)
 *       1.2. 执行: F10(或者选择菜单运行-> 运行)
 *    2. 在Linux环境中的编译和执行。
 *       1.1. 编译:  g++ helloworld.cc -o helloworld.out
 *       1.2. 执行: ./helloworld.out
 *    3. 在Visio Studio Code环境中的编译和执行。
 *       2.1. 编译:  Terminal -> Run Build Task
 *       2.2. 执行: Terminal -> New Terminal,输入命令, .\helloworld.exe
 */

//【知识点】引入输入输出流(input output stream)工具
#include<iostream>

//【知识点】 约定的"入口"
int main(){
    //【知识点】 输出到屏幕,cout(character out),endl(end line)
    std::cout<<"Hello, World!"<<std::endl;
    std::cout<<"你好!欢迎探索计算机科学的奥秘。"<<std::endl;
 
    // 【知识点】返回到调用的地方,同时告知这个程序执行的状态(成功、失败等)
    return 0;
} 

Python Sample Code

print("Hello, World!")

作业

  1. 在屏幕上用“-”和“|”这两个英文字符打印出一个长方形图案。
  2. 在屏幕上打出爱心的图片字样。可以用*表示爱心图片的边界。

Instroduction

When we write a computer program, we’re giving the computer a set of instructions for what we want it to do. Just like we can tell a dog to “sit” or “beg”, we can tell a computer to “add” or “print”. A computer isn’t as furry as a dog, but fortunately, it’s a lot more reliable! And just a bit better at math…

A laptop with a collar and a leash.

Try it

There are many languages we can use to write computer programs.

Let’s start with a simple “Hello World” program, the first program of many new programmers. Our goal is to get the computer to display “Hello World” somewhere on the screen. Please check above C++ and Python code.

How does it work?

Now let’s break down our 1-line python program:

print("Hello, World!")

That line of code is called a statement. All programs are made up of statements, and each statement is an instruction to the computer about something we need it to do.

The print() command is also called a function, method, or procedure. That line tells the computer to call the procedure named print that knows how to display output in a console.

The print() procedure expects a single parameter which specifies what text the computer should display. In this program, the value passed in is “Hello, World!”, so that is what’s displayed.

本页面采用知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
致谢:Khan Academy - AP® Computer Science Principles