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
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.
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 |
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
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
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.
Lab 2: Conditional Statements
Enter a grade to determine whether the student passed or failed.
Lab 3: Loop Statements
Enter the number of iterations to observe how a for loop works.
10. Knowledge Check
Test your understanding of C++ programming fundamentals.