LT1 Intro to programming
Computer: Motherboard + CPU + RAM (Primary Storage) + Secondary Storage
Programming Languages
- Machine Language (Binary Code): Directly executable by computer
- Symbolic Language (*Assembly Language): Abbrivs representing elementary operations
- High-Level Language: Closer to human language. eg C, C++, Java
Building a C++ Program
- Writing source code -> CPP file
- Preprocessing: process the source code for compilation: Preprocessor Directives
- Compilation: Syntax check, Generate Object Code from source
- Linking: Combine object code and libraries to create an executable
Differences between programming languages
- Syntax
- Libraries, SDK, Functions
Programming
- Develop the logic
- Implement into programming language
- Testing
which requires
- Correct syntax & logic
- Efficiency, Scalability, Maintainability
Computer program
-
From the External View, the basic elements are
Input -> Process -> Output -
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 byiostream
library for screen output
<<
: output operator outputs values to the output device, iecout
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
}
网友评论