C++ programming language

A high-level compiled, typed, object-oriented, class-based, and general purpose programming language.

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++.

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:

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++

 1#include <iostream>   // to include a system header to enable input/output
 2#include <string>   // to include a system header to enable string type
 3using namespace std;  // to avoid typing std:: in front of many common keywords
 4
 5int main() {
 6  string name;  // string variable called name
 7  cout << "What is your name? (use one word) "; // display to the screen
 8  cin >> name;  // read from keyboard input
 9  cout << "Hello " << name << " " << endl;
10
11  return 0;  // 0 means success, better use EXIT_SUCCESS constant
12}