欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Introduction to C++

程序员文章站 2022-06-15 18:43:56
...

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 
}