.. highlight:: c++ :linenothreshold: 5 ************************ C++ programming language ************************ A high-level compiled, typed, object-oriented, class-based, and general purpose programming language. .. _coding-style: Naming convention required in class =================================== We use a common naming convention in the class: :Type, class/struct, and template names: UpperCamelCase (Pascal case) :Function, variable names: lowerCamelCase :Constant/Macro names: ALL_UPPER_CASE_WITH_UNDERSCORE :Header file extension: hpp :Source code file extension: cpp :File names: all-lowercase-with-hyphen.cpp .. warning:: Please follow the naming convention to in this course to avoid losing points in exams and assignments. Compilation Requirement in Class ================================ In this course, we stick to the C++14 standard for consistency. Always add ``-std=c++14`` flag to the ``g++`` commands during compilation. Best practices in C++ ===================== There are some great guidelines on how to code correct and efficient programs in C++. + The `C++ Core Guideline`_. + The `Google C++ Style Guide`_. .. _`C++ Core Guideline`: https://github.com/isocpp/CppCoreGuidelines .. _`Google C++ Style Guide`: https://google.github.io/styleguide/cppguide.html .. warning:: When these guidelines conflict with the course requirements, the course requirements take precedence! Type of Errors ============== Three types of errors for C++ as a typical compiled programming language: .. glossary:: Syntax error Also known as compilation error. It will be identified by the compiler and will stop the compilation process. Any program with syntax errors cannot be compiled. Runtime error Errors that abort a compiled program during its runtime. Any program with runtime errors can be compiled but will abort when it is executed. Logic error Errors that cause a program to provide unexpected outcome. Any program with logic errors can compile and run but fail to give the correct outcome. Hello World in C++ ================== :: #include // to include a system header to enable input/output #include // to include a system header to enable string type using namespace std; // to avoid typing std:: in front of many common keywords int main() { string name; // string variable called name cout << "What is your name? (use one word) "; // display to the screen cin >> name; // read from keyboard input cout << "Hello " << name << " " << endl; return 0; // 0 means success, better use EXIT_SUCCESS constant }