Ultimate C++ Course

Jul 14, 2024

Ultimate C++ Course

Course Overview

  • Instructor: Mash Hamadani
  • Platform: codewithmash.com
  • Content: Comprehensive, easy-to-follow, well-organized practical course from basics to advanced levels.
  • Audience: No prior knowledge of C++ or programming needed.
  • Outcome: Ability to write C++ with confidence.

Introduction to C++

  • Popularity: One of the most used languages for performance-critical applications (games, OS, device drivers, servers, etc.). Used by companies like Adobe, Google, Microsoft, Netflix, and NASA.
  • Versions: New version every three years (Latest: C++20, Next: C++23).
  • Relevance: Despite newer languages (Java, C#), remains crucial for memory-efficient and fast applications.
  • Learning Benefit: Foundation for languages like Java, C#, JavaScript, TypeScript, Dart.
  • Salary: Average C++ programmer salary in the US: ~$170,000/year.

Mastering C++

  1. C++ Language: Syntax and grammar.
  2. C++ Standard Library (STL): Pre-written code for common functionalities (data structures, algorithms).
  • Approach: Step-by-step with practical exercises.

Tools and Setup

  • Integrated Development Environments (IDEs):
    • Visual Studio (Windows, Community edition is free)
    • Xcode (Mac, from App Store)
    • CLion (Cross-platform, 30-day free trial, requires license)
    • Recommended: CLion (Download from JetBrains, ensure correct version for Intel/Apple Silicon Macs).

First C++ Program: "Hello, World!"

  1. Project Creation:
  • Use IDE to create a new project.
  • Set C++ language standard (suggested: C++20).
  1. Code Structure:
  • Special Main Function: Entry point (int main())
  • Include header files (#include <iostream>)
  • Use STL objects like std::cout for output to console.
  1. Code Example:
#include <iostream>
int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}
  1. Compilation: Converts code to executable machine code specific to operating systems (Windows, macOS, Linux).
  2. Common Errors: Highlighted and suggested fixes in IDE.

Best Practices

  • Formatting: Professional and consistent code formatting.
  • Commenting:
    • Use comments for clarification and explaining logic.
    • Avoid over-commenting and obvious comments.
  • Themes: Customizing IDE themes for better readability.

Course Structure

  • Basic Concepts: Data types, decision making, loops, functions.
  • Intermediate Concepts: Arrays, pointers, strings, structures, enumerations, streams.
  • Advanced Concepts: Classes, exceptions, templates, containers.
  • Exercises: Regular exercises to enhance problem-solving skills.

Next Steps

  • Tools: Use IDE to write C++ code.
  • Problem-solving: Practice with coding exercises.
  • Cheat Sheet: Download the provided cheat sheet and summary notes for quick revisions.

Variables and Constants

  • Variables: Temporary data storage with types (int, double, etc.).
  • Declaration and Initialization:
    int fileSize = 100;
    double sales = 9.99;
    
  • Constants: Immutable values declared with const keyword.
    const double Pi = 3.14;
    
  • Best Practices: Use meaningful and unambiguous names.
  • Common Naming Conventions:
    • Snake Case: file_size
    • Camel Case: fileSize (preferred)
    • Pascal Case: FileSize
    • Hungarian Notation: iFileSize (outdated).

Mathematical Expressions

  • Operators: +, -, *, /, % (modulus), ++, -- (increment/decrement).
  • Order of Operations: Multiplication/Division > Addition/Subtraction.
    int x = 1 + 2 * 3; // Result: 7
    int y = (1 + 2) * 3; // Result: 9
    

Input and Output

  • Console I/O: Read/write using std::cout and std::cin.
    int value;
    std::cin >> value;
    std::cout << value;