FREE COURSE | BEGINNER

C++ Programming Fundamentals

Develop programming logic, computational thinking, and problem-solving skills.

01. Introduction to C++

C++ is a general-purpose programming language developed by Bjarne Stroustrup. It supports procedural, object-oriented, and generic programming.

What can C++ do?

  • Develop desktop applications.
  • Create video games.
  • Develop embedded systems.
  • Build high-performance software.
  • Solve computational problems.

02. C++ Program Structure

Let's create our first C++ program.

#include <iostream>
using namespace std;

int main() {

    cout << "Hello, LOOPNODELAB!";

    return 0;

}

Understanding the code

  • #include <iostream> - Provides standard input and output.
  • using namespace std; - Allows standard library names without the std:: prefix.
  • int main() - Entry point of the program.
  • cout - Displays output.
  • return 0; - Indicates successful termination.

Expected Output

Hello, LOOPNODELAB!

03. Variables and Data Types

Variables are named storage locations used to hold data in a program.

int age = 18;
float temperature = 36.5f;
double price = 99.99;
char grade = 'A';
bool isStudent = true;
std::string name = "Alex";

To use std::string, include the <string> header.

Common Data Types

Type Description Example
int Whole number 18
float Floating-point number 36.5f
double Double-precision number 99.99
char Single character 'A'
bool Boolean value true
string Text "Alex"

04. Input and Output

C++ uses cin to receive input and cout to display output.

Editable C++ practice code
Original example output
Enter your age: 18 Your age is 18

Edit and copy this code to a C++ compiler. The sample output is static; this editor does not compile C++.

05. Operators

Operators perform calculations, comparisons, and logical operations.

Arithmetic Operators

Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
% Integer remainder
Editable C++ practice code
Original example output
15

Edit and copy this code to a C++ compiler. The sample output is static; this editor does not compile C++.

Comparison Operators

==   Equal to
!=   Not equal to
>    Greater than
<    Less than
>=   Greater than or equal to
<=   Less than or equal to

06. Conditional Statements

Conditional statements allow a program to make decisions based on conditions.

If Statement

int age = 18;

if (age >= 18) {

    cout << "Adult";

}

If-Else Statement

Editable C++ practice code
Original example output
Passed

Edit and copy this code to a C++ compiler. The sample output is static; this editor does not compile C++.

Switch Statement

int choice = 1;

switch (choice) {

    case 1:
        cout << "Start";
        break;

    case 2:
        cout << "Exit";
        break;

    default:
        cout << "Invalid choice";

}

07. Loops

Loops allow instructions to be executed repeatedly.

For Loop

Editable C++ practice code
Original example output
1 2 3 4 5

Edit and copy this code to a C++ compiler. The sample output is static; this editor does not compile C++.

While Loop

int i = 1;

while (i <= 5) {

    cout << i << endl;

    i++;

}

Do-While Loop

int i = 1;

do {

    cout << i << endl;

    i++;

} while (i <= 5);

08. Practice Exercises

Apply what you have learned by completing the following challenges using a C++ compiler.

Challenge 1: Personal Profile

Create a program that displays your name, age, and course.

Challenge 2: Simple Calculator

Accept two integers and display their sum, difference, and product.

Challenge 3: Grade Checker

Accept a grade and display Passed if it is 75 or higher. Otherwise, display Failed.

Challenge 4: Number Counter

Use a loop to display numbers from 1 to 10.

09. Interactive C++ Logic Lab

Experiment with programming concepts and observe the expected output.

Note: This is an educational simulator, not an actual C++ compiler.

Lab 1: Arithmetic Operators

Enter two integers.

Generated C++ code
Simulation output

Lab 2: Conditional Statements

Enter a grade to determine whether the student passed or failed.

Generated C++ code
Simulation output

Lab 3: Loop Statements

Enter the number of iterations to observe how a for loop works.

Generated C++ code
Simulation output

10. Knowledge Check

Test your understanding of C++ programming fundamentals.

1. Which header provides standard input and output?

2. Which function is the entry point of a C++ program?

3. Which data type stores whole numbers?

4. Which object receives standard input?

5. What is the result of 10 % 3?

6. Which operator checks equality?

7. What is the expected output?

int grade = 74;

if (grade >= 75) {

    cout << "Passed";

} else {

    cout << "Failed";

}

8. Which statement selects among multiple constant cases?

9. How many times will this loop execute?

for (int i = 1; i <= 5; i++) {

    cout << i;

}

10. Which loop executes its body at least once?

Back to Courses