Introduction to C++

LT1 Intro to programming

Computer: Motherboard + CPU + RAM (Primary Storage) + Secondary Storage

Programming Languages

  1. Machine Language (Binary Code): Directly executable by computer
  2. Symbolic Language (*Assembly Language): Abbrivs representing elementary operations
  3. High-Level Language: Closer to human language. eg C, C++, Java

Building a C++ Program

  1. Writing source code -> CPP file
  2. Preprocessing: process the source code for compilation: Preprocessor Directives
  3. Compilation: Syntax check, Generate Object Code from source
  4. Linking: Combine object code and libraries to create an executable

Differences between programming languages

  1. Syntax
  2. Libraries, SDK, Functions

Programming

  1. Develop the logic
  2. Implement into programming language
  3. Testing

which requires

  1. Correct syntax & logic
  2. Efficiency, Scalability, Maintainability

Computer program

  1. From the External View, the basic elements are
    Input -> Process -> Output

  2. From the Internal View, the computer program is

    • Logically ordered Instructions + Data (Variables & Constants)

A Simple Program

Preprocessor Directive
#include <iostream> // Include the library into the program
using namespace std; // Preprocessor Directive std::cout -> cout (shorthand name)
Functions

Left Brace { and Right Brace } marks the beginning and end of the func body

Library / SDK / Package

The wheels made for reuse, especially for repeating tasks / low-level operations.
e.g.: <iostream>, <iomanip>
The reusing code is well designed and packed into Libraries
Standard C++ comes with extensive libraries

Object An instance of a class

cout<<"Hello, workd!\n";

cout is an object provided by iostream library for screen output

<<: output operator outputs values to the output device, ie cout

Object is a unit that stores values and provides functions for the values.

An abstract from the real world

A simple C++ Program

#include <iostream> // Preprocessor Directive

using namespace std; // Namespace Declaration

int main(){ // Beginning of main() function body 
    cout<< "Hello, world!\n"; // starting point of the main function, use output operator << of cout object
    return 0; //return statement 
} 
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容