ASZ PROGRAMMING ACADEMY - Introduction to C++ Programming – Basic Tutorial

1. What is C++?

C++ is a general-purpose programming language used to develop software, desktop applications, games, operating systems, embedded systems, and high-performance applications.

C++ was developed by Bjarne Stroustrup at Bell Labs. It was first introduced in 1985.

C++ is an extension of the C programming language, with additional features such as Object-Oriented Programming (OOP).

Key Features
  • High Performance: Compiled directly into machine code, making it ideal for systems programming and resource-intensive software.
  • Low-Level Control: Supports pointers, direct memory manipulation, and manual memory management.
  • Standard Library (STL): Includes a built-in collection of data structures (such as vectors and maps) and algorithms.
  • Language Evolution: Standardized across major versions like C++11, C++14, C++17, C++20, C++23, and upcoming specifications


What can you build with C++?

You can use C++ to build high-performance software, video games, operating systems, embedded hardware firmware, and large-scale backend infrastructure. Because C++ provides direct control over system hardware and memory management, it is the industry standard for applications where speed and efficiency are critical. [1, 2]
Major Real-World Applications
  • Video Games and Game Engines. C++ powers major game engines like Unreal Engine and handles real-time 3D rendering, physics simulations, and multiplayer networking. [1, 2, 3]
  • Operating Systems and System Software. Core components of Windows, macOS, and Linux, along with device drivers and hardware resource monitors, are written in C++ to communicate directly with hardware. [1, 2]
  • Web Browsers and Compilers. High-speed rendering engines like Chromium and compilers for other programming languages rely on C++ to parse and execute code rapidly. [1, 2, 3]
  • Databases and Cloud Infrastructure. High-throughput database management systems like MySQL use C++ to process millions of queries with minimal latency. [1, 2]
  • Embedded Systems and IoT. Smart appliances, medical devices, automotive firmware, and home automation controllers use C++ because it runs reliably on hardware with limited memory. [1, 2]
  • AI, Machine Learning, and Finance. Machine learning frameworks like TensorFlow and high-frequency financial trading platforms use C++ for heavy mathematical computations and sub-millisecond execution. [1, 2]
Personal Project Ideas by Skill Level
If you are looking for hands-on projects to practice, developers on Reddit's r/cpp community and coding guides like GeeksforGeeks commonly suggest building projects that scale with your experience: [1, 2]
Skill LevelExample ProjectsKey Concepts Practiced
BeginnerText-based adventure game, scientific calculator, student database, or banking record systemLoops, functions, file I/O, and basic data structures
Intermediate2D games (Snake, Minesweeper), custom text editor, music player, or computer vision tools using OpenCVObject-oriented programming, external libraries, and memory management
AdvancedCustom programming language compiler, retro console emulator (like Chip-8), 3D game engine, or multithreaded web serverLow-level architecture, concurrency, shaders, and network sockets

2. Setting up C++

To start programming in C++, you need:

  1. A code editor.

  2. A C++ compiler.

  3. A computer (Windows, Linux or macOS).

Recommended tools:

Software

Purpose

Visual Studio Code

Code editor

Visual Studio Community

C++ development IDE

GCC / G++

C++ compiler

Code::Blocks

Beginner-friendly IDE

You can also practise online using OnlineGDB C++ Compiler without installing anything.


3. Your first C++ program

FOR loop:


#include <iostream>
using namespace std;

int main()
{
    for (int i = 1; i <= 10; i++)
    {
        cout << "Number: " << i << endl;
    }

    return 0;
}

Output:

Number: 1
Number: 2
Number: 3
...
Number: 10

WHILE loop:


#include <iostream>
using namespace std;

int main()
{
    int i = 1;

    while (i <= 5)
    {
        cout << i << endl;
        i++;
    }

    return 0;
}

9. Functions

Functions allow you to divide a program into smaller reusable sections.


#include <iostream>
using namespace std;

int addNumbers(int a, int b)
{
    return a + b;
}

int main()
{
    int result = addNumbers(10, 20);

    cout << "Total: " << result << endl;

    return 0;
}

Output:

Total: 30

10. Arrays

Arrays store multiple values using one variable name.


#include <iostream>
using namespace std;

int main()
{
    int numbers[5] = {10, 20, 30, 40, 50};

    for (int i = 0; i < 5; i++)
    {
        cout << numbers[i] << endl;
    }

    return 0;
}

Remember: Array indexing starts at zero.

  • numbers[0] = 10

  • numbers[1] = 20

  • numbers[2] = 30

11. Object-Oriented Programming (OOP)

One of the most important features of C++ is Object-Oriented Programming.

OOP allows you to create classes and objects.

For example, imagine developing a Point of Sale (POS) system. You can create a Product class.


#include <iostream>
#include <string>
using namespace std;

class Product
{
public:
    string name;
    double price;
    int quantity;

    void displayProduct()
    {
        cout << "Product: " << name << endl;
        cout << "Price: RM" << price << endl;
        cout << "Quantity: " << quantity << endl;
    }
};

int main()
{
    Product product1;

    product1.name = "Burger";
    product1.price = 8.50;
    product1.quantity = 10;

    product1.displayProduct();

    return 0;
}

Output:

Product: Burger
Price: RM8.5
Quantity: 10

Important OOP concepts:

Concept

Explanation

Class

Blueprint for creating objects

Object

Instance of a class

Encapsulation

Protecting and organizing data

Inheritance

Reusing properties from another class

Polymorphism

Different implementations of the same interface

Abstraction

Hiding unnecessary implementation details

12. File Handling

C++ can create, read and write files.

Example: Save information into a text file.


#include <iostream>
#include <fstream>
using namespace std;

int main()
{
    ofstream file("data.txt");

    if (file.is_open())
    {
        file << "Welcome to C++ Programming!";
        file.close();

        cout << "File saved successfully!";
    }

    return 0;
}

This creates a file named data.txt.

13. Practical C++ Learning Roadmap

Here is a recommended learning sequence:

  1. Level 1 – Fundamentals

    Variables, data types, input/output, operators and conditions.

  2. Level 2 – Programming Logic

    Loops, functions, arrays and strings.

  3. Level 3 – Intermediate C++

    Pointers, references, memory management and structures.

  4. Level 4 – Object-Oriented Programming

    Classes, objects, constructors, inheritance and polymorphism.

  5. Level 5 – Advanced C++

    STL, templates, exception handling, file handling and multithreading.

  6. Level 6 – Practical Projects

    Develop a POS, inventory management, billing or database application.

14. Your first practical exercise: Simple POS

Try to build a simple POS program using what you have learned.

Requirements:

  • Enter product name.

  • Enter product price.

  • Enter quantity.

  • Calculate subtotal.

  • Calculate 6% tax.

  • Display the final payment.

POS practice calculator

Subtotal

RM 17.00

Tax (6%)

RM 1.02

Total Payment

RM 18.02

This is a learning example using an assumed 6% tax rate, not a statement of applicable tax law.

Example C++ solution:


#include <iostream>
#include <string>
using namespace std;

int main()
{
    string productName;
    double price, subtotal, tax, total;
    int quantity;

    cout << "Product Name: ";
    getline(cin, productName);

    cout << "Price: RM";
    cin >> price;

    cout << "Quantity: ";
    cin >> quantity;

    subtotal = price * quantity;
    tax = subtotal * 0.06;
    total = subtotal + tax;

    cout << "\n----- POS RECEIPT -----" << endl;
    cout << "Product: " << productName << endl;
    cout << "Price: RM" << price << endl;
    cout << "Quantity: " << quantity << endl;
    cout << "Subtotal: RM" << subtotal << endl;
    cout << "Tax: RM" << tax << endl;
    cout << "Total: RM" << total << endl;

    return 0;
}

15. Recommended C++ learning resources

My recommendation: Learn C++ in stages and practise by building small applications. Since POS, inventory, billing and business management systems are useful practical projects, these make excellent exercises for understanding programming logic and OOP.

THANK YOU


ASROL AFFANDI

ASZ PROGRAMMING ACADEMY