跳转至

Class 1: Introduction

What is Object-oriented Programming

computers are not so much machines as they are mind amplification tools and a different kind of expressive medium. As a result, the tools are beginning to look less like machines and more like parts of our minds, and also like other expressive mediums such as writing, painting, sculpture, animation, and filmmaking. Object-oriented programming is part of this movement toward using the computer as an expressive medium.

Buzzwords of it

  • responsibility-driven design
  • Encapsulation
  • Inheritance
  • iterators
  • overriding
  • coupling
  • cohesion
  • template
  • interface
  • collection classes
  • mutator methods
  • Polymorphism

Four main characters of C++

  • Encapsulation(封装)
  • Abstraction(抽象)
  • Inheritance(继承)
  • Polymorphism(多态)

The First C++ Program

1
2
3
4
5
6
7
8
9
#include <iostream>
using namespace std;

int main()
{
    cout << "Hello, World! I am " << 18 << "Today!" << endl;

    return 0
}

To choose development environment

Windows:

  • visual studio

Linux, macOS:

  • g++, clang, ...(compiler)
  • visual studio code(editor)

Read Input

How do we read the input in C++? Let's see the example below:

#include <iostream>
using namespace std;

int main()
{
    cout << "Enter a decimal number: " ;

    int number;
    cin >> number;

    cout << "The number you entered is " << number << " ." << endl;

    return 0;
}

The strengths and weakness of C

For C language:

Strengths:

  • Efficient programs
  • Direct access to machine, suitable for OS and ES
  • Flexible

Weakness:

  • Insufficient type checking
  • Poor support for programming-in-the-large
  • Procedure-oriented programming

The relationship between C and C++

Actually C is a subset of C++