This lesson includes an expert video walkthrough — purchase once for a full year of unlimited replays to master every key point 🎬
Milestone Achievement
I. Knowledge Summary
✨ Computer Languages
Development Levels of Computer Languages
Computer languages evolved through three stages from low-level to high-level:
| Level | Name | Characteristics | Example |
|---|---|---|---|
| 1st | Binary Language (Machine Language) | Runs directly on CPU, composed of 0s and 1s | 01010011... |
| 2nd | Low-Level Programming Language | Uses mnemonics instead of binary, close to hardware | Assembly language |
| 3rd | High-Level Programming Language | Close to human language, easy to understand | C, C++, Python |
Classification of High-Level Languages
By purpose:
| Purpose | Representative Languages |
|---|---|
| System Programming | C, C++, Rust |
| Application Programming | Java, Python, Ruby |
| Web Programming | JavaScript, PHP |
| Scientific Computing | Matlab, Fortran, R |
| Data Querying | SQL |
By programming paradigm:
| Paradigm | Description | Representative Languages |
|---|---|---|
| Procedural | Executes steps sequentially | C, Pascal |
| Object-Oriented | Organizes code around objects | C++, Python, Java |
| Functional | Functions as basic units | Haskell, Erlang |
| Logic | Reasoning through logical rules | Prolog |
| Declarative | Describes "what" rather than "how" | SQL, HTML |
| Concurrent | Supports multiple simultaneous tasks | Erlang, Go |
By compilation method:
| Method | Characteristics | Representative Languages |
|---|---|---|
| Compiled | Compiles to machine code first, then runs; faster | C, C++, Fortran |
| Interpreted | Interprets and executes line by line; more flexible | Python, Ruby, JavaScript |
| JIT (Just-In-Time) | Compiles to intermediate code, then to machine code at runtime | Java, C# |
✨ Common C++ Math Functions
Function Reference
The following functions require the <cmath> header (math functions) or <algorithm> (max/min). Using #include <bits/stdc++.h> includes all headers.
| Function | Purpose | Example Call | Return Value |
|---|---|---|---|
max(a, b) | Returns larger value | max(10, 20) | 20 |
min(a, b) | Returns smaller value | min(10, 20) | 10 |
abs(x) | Returns absolute value | abs(-10) | 10 |
ceil(x) | Rounds up | ceil(3.14) | 4 |
floor(x) | Rounds down | floor(3.14) | 3 |
round(x) | Rounds to nearest | round(3.5) | 4 |
trunc(x) | Truncates (removes decimal) | trunc(3.14) | 3 |
sqrt(x) | Square root | sqrt(16.0) | 4 |
pow(x, y) | x to the power of y | pow(2.0, 3.0) | 8 |
rand() | Generates random number | rand() % 100 | Random 0-99 |
Rounding Function Comparison
These four rounding functions are easy to confuse. Here's a comparison with different input values:
| Input | ceil (up) | floor (down) | round (nearest) | trunc (truncate) |
|---|---|---|---|---|
| 3.14 | 4 | 3 | 3 | 3 |
| 3.75 | 4 | 3 | 4 | 3 |
| -3.14 | -3 | -4 | -3 | -3 |
| -3.75 | -3 | -4 | -4 | -3 |
Code Examples
1#include <bits/stdc++.h>
2using namespace std;
3
4int main() {
5 int a = 10, b = 20;
6 cout << max(a, b) << endl; // Output 20
7 cout << min(a, b) << endl; // Output 10
8 return 0;
9}1#include <bits/stdc++.h>
2using namespace std;
3
4int main() {
5 int value = -10;
6 cout << abs(value) << endl; // Output 10
7 return 0;
8}1#include <bits/stdc++.h>
2using namespace std;
3
4int main() {
5 double x = 3.14;
6 cout << ceil(x) << endl; // Output 4 (round up)
7 cout << floor(x) << endl; // Output 3 (round down)
8 cout << round(x) << endl; // Output 3 (round to nearest)
9 cout << trunc(x) << endl; // Output 3 (truncate)
10 return 0;
11}1#include <bits/stdc++.h>
2using namespace std;
3
4int main() {
5 cout << sqrt(16.0) << endl; // Output 4 (square root)
6 cout << pow(2.0, 3.0) << endl; // Output 8 (2 to the power of 3)
7 return 0;
8}1#include <bits/stdc++.h>
2using namespace std;
3
4int main() {
5 srand(time(0)); // Set random seed
6 for (int i = 0; i < 5; ++i) {
7 cout << rand() % 100 << endl; // Output random numbers 0-99
8 }
9 return 0;
10}✨ Flowchart Summary
Flowcharts are tools that use graphical symbols to represent program execution steps. Common symbols:
| Symbol | Shape | Purpose |
|---|---|---|
| Start/End | Rounded rectangle/oval | Indicates program start and end |
| Process/Step | Rectangle | Indicates specific operation steps |
| Decision/Condition | Diamond | Indicates condition check with true/false branches |
| Input/Output | Parallelogram | Indicates data input or output |
| Arrow | Line with arrow | Indicates flow direction |
正在渲染流程图...