C++ ProgrammingSyntax, OOP & Modern C++
A structured C++ course covering setup, syntax, control flow, arrays and functions, object-oriented design, modern C++, templates and preprocessor essentials.
Your Learning Progress
Module 1 – C++ Basics, Syntax, and I/O
In Module 1, the goal is: Understand the structure of a simple C++ program Learn basic types, variables, and constants Learn how to compile and run code Use std::cout and std::cin for simple I/O
1. Introduction and “Hello World”
Definition (concept): C++ is a general-purpose, compiled programming language used for system software, game engines, high-performance applications, and teaching programming concepts.wscubetech Basic program structure:
1#include <iostream> // Preprocessor directive: include I/O library2 3int main() { // Entry point function4 std::cout << "Hello QuickRef\n"; // Output to the console5 return 0; // Exit status 0 (success)6}#include <iostream> tells the compiler to use the standard input/output stream library. int main() is the function where program execution begins. std::cout prints text; << is the “insertion” operator. Compiling and running (Linux/macOS terminal):
1g++ hello.cpp -o hello // Compile: source -> executable2./hello // Run the programOn Windows with g++ (MinGW), you might do:
1g++ hello.cpp -o hello.exe2hello.exeThis mirrors your cheatsheet’s “Getting Started” section.w3schools+1
2. Basic Syntax and Statements
Definition: A C++ program is made of statements (like std::cout << 5;) grouped into blocks using {}. Each statement ends with a semicolon. Key syntax rules: Curly braces {} define a block (like inside main or if). Each line that does something (print, calculate) ends with ;. Whitespace and newlines usually don’t matter, but make code readable. Example:
1#include <iostream>2 3int main() {4 std::cout << "Line 1\n";5 std::cout << "Line 2\n"; // Each statement ends with ;6}3. Primitive Data Types and Variables
Definition: A variable is a named storage location that holds a value of a specific type (like int or double). Types control what kind of data and what range of values can be stored.scribd+1 Common types (as in your cheatsheet): int – integer numbers (typically 4 bytes, around −2,147,483,648 to 2,147,483,647). float – single-precision floating point (decimal numbers). double – double-precision floating point. char – single character (usually 1 byte). bool – Boolean: true or false. void – “no type” (used for functions that don’t return anything). wchar_t – wide character type (typically 2 or 4 bytes).asgteach Declaring and initializing variables:
1#include <iostream>2#include <string> // needed for std::string3 4int main() {5 int number = 5; // Integer6 float f = 0.95f; // Float (note the f suffix is common)7 double PI = 3.14159; // Double8 char yes = 'Y'; // Character9 std::string s = "ME"; // String10 bool isRight = true; // Boolean11 12 std::cout << number << " " << PI << " " << s << "\n";13}Brace initialization (C++11 style):
1int age {25}; // Uniform initialization2std::cout << age; // Prints 25This style helps avoid some subtle bugs and is widely used in modern C++.kdab+1 Constants:
1const float RATE = 0.8f; // RATE cannot be changed later4. Operators (Basic Overview)
You already listed many in your cheatsheet; here’s how they look in code. Arithmetic operators:
1int a = 10, b = 3;2int sum = a + b; // 133int diff = a - b; // 74int prod = a * b; // 305int quot = a / b; // 3 (integer division)6int rem = a % b; // 1 (remainder)Assignment and compound assignment:
1int x = 5;2x += 2; // x = x + 2 -> 73x *= 3; // x = x * 3 -> 21Relational and logical operators:
1int n = 10;2bool isTen = (n == 10); // true3bool big = (n > 5); // true4bool ok = (isTen && big); // trueTernary operator (from your cheatsheet):
1int x = 3, y = 5;int max = (x > y) ? x : y; // Result is the larger of x and y std::cout << max << "\n"; // Outputs: 5
5. Comments
Comments document code and are ignored by the compiler.
1 // This is a single-line comment
/* This is a multi-line comment */ Use comments to explain why you are doing something, especially in longer programs.
6. Basic Input and Output
Output with std::cout:
1#include <iostream>2 3int main() {4 std::cout << "Hello QuickRef\n";5 std::cout << "Number: " << 42 << "\n";6}7<< chains multiple things into a single output statement.Input with std::cin:
1#include <iostream>2 3int main() {4 int num;5 std::cout << "Type a number: ";6 std::cin >> num; // Reads from keyboard7 std::cout << "You entered " << num << "\n";8}This matches the “User Input” section of your cheatsheet and is essential for interactive programs.w3schools
We’ve now: Defined what a C++ program looks like Compiled and run a simple hello.cpp Used basic types, variables, and constants Introduced operators, comments, and simple I/O
Practice Drill
Module 1 Quiz
Practice Drill Bank
Every practice drill from the course, organised by module. Rehearse these until they feel automatic.
Final Revision Checklist
Tick items as you master them — progress saves automatically.
Module 1 – C++ Basics, Syntax, and I/O
Module 2 – Conditionals and Loops (Detailed)
Module 3 – Arrays, Functions, and References
Module 4 – Classes, Objects, and Basic Object-Oriented Programming (detailed)
Module 5 – Advanced OOP & Modern C++
Module 6 – Preprocessor and Practical Utilities
Congratulations!
You've finished the CodeStudio C++ Programming course. Revise, drill, and keep building.