From 48eced00846076bd94d9d657420c3e3bd892fb0c Mon Sep 17 00:00:00 2001 From: Vipul_Lakum Date: Wed, 5 Jun 2024 14:47:52 +0530 Subject: [PATCH 1/6] Find Triplet with zero sum solution added --- .../0023-Find-triplet-with-zero-sum.md | 194 ++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100644 dsa-solutions/gfg-solutions/0023-Find-triplet-with-zero-sum.md diff --git a/dsa-solutions/gfg-solutions/0023-Find-triplet-with-zero-sum.md b/dsa-solutions/gfg-solutions/0023-Find-triplet-with-zero-sum.md new file mode 100644 index 000000000..f54a8a3b8 --- /dev/null +++ b/dsa-solutions/gfg-solutions/0023-Find-triplet-with-zero-sum.md @@ -0,0 +1,194 @@ +--- +id: Find-triplet-with-zero-sum +title: Find Triplet with Zero Sum +sidebar_label: 0023 Find Triplet with Zero Sum +tags: +- Array +- Sorting +- Two Pointers +- JavaScript +- TypeScript +- Python +- Java +- C++ +description: "This document explores different approaches to solving the problem of finding a triplet in an array that sums up to zero, including solutions in JavaScript, TypeScript, Python, Java, and C++." +--- + +## Problem + +Given an array `arr[]` of distinct integers of size N, the task is to find if there are any three elements in `arr[]` whose sum is equal to zero. + +### Examples + +**Example 1:** + +``` +Input: +N = 5 +arr[] = {-1, 0, 1, 2, -1, -4} + +Output: +True + +Explanation: +The triplets {-1, 0, 1} and {-1, -1, 2} both have a sum of zero. +``` + +**Example 2:** + +``` +Input: +N = 3 +arr[] = {1, 2, 3} + +Output: +False + +Explanation: +No triplet has a sum of zero. +``` + +### Your Task +You don't need to read input or print anything. Your task is to complete the function `findTriplet()` which takes the integer `N` and integer array `arr[]` as parameters and returns true if there is a triplet with a sum of zero, otherwise false. + +**Expected Time Complexity:** O(N^2) +**Expected Auxiliary Space:** O(1) + +### Constraints +- 1 ≤ N ≤ 10^5 +- -10^3 ≤ arr[i] ≤ 10^3 + +## Solution + +### Approach + +We can solve this problem using sorting and the two-pointer technique. Here's a step-by-step approach: + +1. Sort the array. +2. Iterate through the array using a for loop, fixing one element at a time. +3. Use two pointers to find the other two elements that sum up to zero with the fixed element: + - One pointer starts from the next element after the fixed element. + - The other pointer starts from the end of the array. +4. Adjust the pointers based on the sum of the three elements: + - If the sum is zero, return true. + - If the sum is less than zero, move the left pointer to the right. + - If the sum is greater than zero, move the right pointer to the left. +5. If no triplet is found, return false. + +### Implementation + + + + +```cpp +class Solution { +public: + bool findTriplet(int arr[], int n) { + sort(arr, arr + n); + for (int i = 0; i < n - 2; i++) { + int left = i + 1, right = n - 1; + while (left < right) { + int sum = arr[i] + arr[left] + arr[right]; + if (sum == 0) return true; + if (sum < 0) left++; + else right--; + } + } + return false; + } +}; +``` + + + + +```javascript +function findTriplet(arr) { + arr.sort((a, b) => a - b); + for (let i = 0; i < arr.length - 2; i++) { + let left = i + 1, right = arr.length - 1; + while (left < right) { + const sum = arr[i] + arr[left] + arr[right]; + if (sum === 0) return true; + if (sum < 0) left++; + else right--; + } + } + return false; +} +``` + + + + +```typescript +function findTriplet(arr: number[]): boolean { + arr.sort((a, b) => a - b); + for (let i = 0; i < arr.length - 2; i++) { + let left = i + 1, right = arr.length - 1; + while (left < right) { + const sum = arr[i] + arr[left] + arr[right]; + if (sum === 0) return true; + if (sum < 0) left++; + else right--; + } + } + return false; +} +``` + + + + +```python +class Solution: + def findTriplet(self, arr: List[int], n: int) -> bool: + arr.sort() + for i in range(n - 2): + left, right = i + 1, n - 1 + while left < right: + total = arr[i] + arr[left] + arr[right] + if total == 0: + return True + if total < 0: + left += 1 + else: + right -= 1 + return False +``` + + + + +```java +class Solution { + public boolean findTriplet(int[] arr, int n) { + Arrays.sort(arr); + for (int i = 0; i < n - 2; i++) { + int left = i + 1, right = n - 1; + while (left < right) { + int sum = arr[i] + arr[left] + arr[right]; + if (sum == 0) return true; + if (sum < 0) left++; + else right--; + } + } + return false; + } +} +``` + + + + +### Complexity Analysis + +- **Time Complexity:** $O(N^2)$, where N is the length of the array. We iterate through the array and for each element, we use the two-pointer technique which takes linear time. +- **Space Complexity:** $O(1)$, as we only use a constant amount of extra space for variables. + +--- + +## References + +- **GeeksforGeeks Problem:** [Find Triplet with Zero Sum](https://www.geeksforgeeks.org/find-triplet-sum-zero/) +- **Author GeeksforGeeks Profile:** [GeeksforGeeks](https://www.geeksforgeeks.org/user/GeeksforGeeks/) From 14781d00d2f7a0feab2e63363ebcc60ca994f9d7 Mon Sep 17 00:00:00 2001 From: Vipul_Lakum Date: Wed, 5 Jun 2024 14:51:35 +0530 Subject: [PATCH 2/6] Find Triplet with zero sum solution added --- .../gfg-solutions/0023-Find-triplet-with-zero-sum.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dsa-solutions/gfg-solutions/0023-Find-triplet-with-zero-sum.md b/dsa-solutions/gfg-solutions/0023-Find-triplet-with-zero-sum.md index f54a8a3b8..9a7b95e67 100644 --- a/dsa-solutions/gfg-solutions/0023-Find-triplet-with-zero-sum.md +++ b/dsa-solutions/gfg-solutions/0023-Find-triplet-with-zero-sum.md @@ -14,7 +14,7 @@ tags: description: "This document explores different approaches to solving the problem of finding a triplet in an array that sums up to zero, including solutions in JavaScript, TypeScript, Python, Java, and C++." --- -## Problem +## Problem Statement Given an array `arr[]` of distinct integers of size N, the task is to find if there are any three elements in `arr[]` whose sum is equal to zero. @@ -191,4 +191,4 @@ class Solution { ## References - **GeeksforGeeks Problem:** [Find Triplet with Zero Sum](https://www.geeksforgeeks.org/find-triplet-sum-zero/) -- **Author GeeksforGeeks Profile:** [GeeksforGeeks](https://www.geeksforgeeks.org/user/GeeksforGeeks/) +- **Authors GeeksforGeeks Profile:** [Vipul lakum](https://www.geeksforgeeks.org/user/lakumvipwjge/) \ No newline at end of file From 93810a16a295e8306df80ca722e678c26305bd1f Mon Sep 17 00:00:00 2001 From: Vipul_Lakum Date: Wed, 5 Jun 2024 15:00:52 +0530 Subject: [PATCH 3/6] Minimum indexed character solutoin added --- .../0024-minimum-indexed-character.md | 180 ++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 dsa-solutions/gfg-solutions/0024-minimum-indexed-character.md diff --git a/dsa-solutions/gfg-solutions/0024-minimum-indexed-character.md b/dsa-solutions/gfg-solutions/0024-minimum-indexed-character.md new file mode 100644 index 000000000..f15b7dc58 --- /dev/null +++ b/dsa-solutions/gfg-solutions/0024-minimum-indexed-character.md @@ -0,0 +1,180 @@ +--- +id: minimum-indexed-character +title: Minimum Indexed Character +sidebar_label: 0024 Minimum Indexed Character +tags: +- String +- Hashing +- JavaScript +- TypeScript +- Python +- Java +- C++ +description: "This document explores different approaches to solving the problem of finding the minimum index of a character in a string that is also present in another string, including solutions in JavaScript, TypeScript, Python, Java, and C++." +--- + +## Problem + +Given a string `str` and another string `patt`, find the minimum index of the character in `str` that is also present in `patt`. + +### Examples + +**Example 1:** + +``` +Input: +str = "geeksforgeeks" +patt = "set" + +Output: +1 + +Explanation: +'e' is the character which is present in the given string "geeksforgeeks" and is also present in "set". The minimum index of 'e' is 1. +``` + +**Example 2:** + +``` +Input: +str = "adcffaet" +patt = "onkl" + +Output: +-1 + +Explanation: +There are no characters that are common in "patt" and "str". +``` + +### Your Task +You only need to complete the function `minIndexChar()` that returns the index of the answer in `str` or returns `-1` if no character of `patt` is present in `str`. + +**Expected Time Complexity:** O(N) +**Expected Auxiliary Space:** O(Number of distinct characters) + +### Constraints +- 1 ≤ |str|,|patt| ≤ 10^5 +- 'a' ≤ str[i], patt[i] ≤ 'z' + +## Solution + +### Approach + +To solve this problem, we can follow these steps: + +1. Iterate through the characters in the `patt` string. +2. For each character in `patt`, find its index in the `str` string using the `find` method. +3. Store the indices in a vector. +4. Iterate through the vector to find the minimum index that is not `-1` (indicating the character is found in `str`). +5. If no valid index is found, return `-1`; otherwise, return the minimum index. + +### Implementation + + + + +```cpp +class Solution +{ + public: + int minIndexChar(string str, string patt) + { + int res = INT_MAX; + vector v1; + for (int i = 0; i < patt.length(); i++) + { + int p = str.find(patt[i]); + v1.push_back(p); + } + int min = INT_MAX; + for (int i = 0; i < v1.size(); i++) + { + if (min > v1[i] && v1[i] != -1) + min = v1[i]; + } + if (min == INT_MAX) + return -1; + return min; + } +}; +``` + + + + +```javascript +function minIndexChar(str, patt) { + let minIndex = Infinity; + for (let char of patt) { + let index = str.indexOf(char); + if (index !== -1 && index < minIndex) { + minIndex = index; + } + } + return minIndex === Infinity ? -1 : minIndex; +} +``` + + + + +```typescript +function minIndexChar(str: string, patt: string): number { + let minIndex = Infinity; + for (let char of patt) { + let index = str.indexOf(char); + if (index !== -1 && index < minIndex) { + minIndex = index; + } + } + return minIndex === Infinity ? -1 : minIndex; +} +``` + + + + +```python +class Solution: + def minIndexChar(self, str: str, patt: str) -> int: + min_index = float('inf') + for char in patt: + index = str.find(char) + if index != -1 and index < min_index: + min_index = index + return -1 if min_index == float('inf') else min_index +``` + + + + +```java +class Solution { + public int minIndexChar(String str, String patt) { + int minIndex = Integer.MAX_VALUE; + for (char ch : patt.toCharArray()) { + int index = str.indexOf(ch); + if (index != -1 && index < minIndex) { + minIndex = index; + } + } + return minIndex == Integer.MAX_VALUE ? -1 : minIndex; + } +} +``` + + + + +### Complexity Analysis + +- **Time Complexity:** O(N), where N is the length of the string `str`. We iterate through each character in `patt` and use the `find` or `indexOf` method, which runs in O(N) time. +- **Space Complexity:** O(1), as we only use a constant amount of extra space for variables. + +--- + +## References + +- **GeeksforGeeks Problem:** [Minimum Indexed Character](https://www.geeksforgeeks.org/minimum-indexed-character/) +- **Authors GeeksforGeeks Profile:** [Vipul lakum](https://www.geeksforgeeks.org/user/lakumvipwjge/) \ No newline at end of file From e7ef3b520f18180748adf432f53e2bf1931bdd65 Mon Sep 17 00:00:00 2001 From: Vipul_Lakum Date: Wed, 5 Jun 2024 16:44:04 +0530 Subject: [PATCH 4/6] c++ docs added --- .../02_Variables_and_Data_Types.md | 69 ++++++++++++++- .../03_Operators_and_Expressions.md | 69 ++++++++++++++- .../cpp-syntax-basics.md | 87 ++++++++++++++++++- docs/cpp/home.md | 47 +++++++++- .../setting-up-your-cpp-environment.md | 43 ++++++++- docs/cpp/introduction-to-cpp/what-is-cpp.md | 41 ++++++++- docs/cpp/introduction-to-cpp/why-learn-cpp.md | 28 +++++- 7 files changed, 377 insertions(+), 7 deletions(-) diff --git a/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md b/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md index 054a00863..db27271ae 100644 --- a/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md +++ b/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md @@ -13,4 +13,71 @@ tags: c++ data types ] description: In this tutorial, we will learn about variables and data types in C++. We will learn about what variables are, how to declare and initialize variables, and the different data types available in the language. ---- \ No newline at end of file +--- + +# Variables and Data Types in C++ + +## Data Types + +C++ is a strongly-typed language, meaning every variable must be declared with a data type. + +### Primitive Data Types + +- **int**: Integer type. +- **double**: Double-precision floating point. +- **char**: Character type. +- **bool**: Boolean type (true or false). + +Example: + +```cpp +int number = 10; +double price = 9.99; +char letter = 'A'; +bool isCppFun = true; +``` + +### Derived Data Types + +Derived data types are created from fundamental data types. + +- **Array**: A collection of elements of the same data type. +- **Pointer**: A variable that stores the memory address of another variable. +- **Reference**: A reference to another variable, often used in functions. + +Example: + +```cpp +int numbers[] = {1, 2, 3, 4, 5}; +int* ptr = &number; +int& refNumber = number; +``` + +## Variables + +Variables store data values and must be declared before use. + +### Variable Declaration + +```cpp +int age; +char grade; +``` + +### Variable Initialization + +```cpp +age = 25; +grade = 'A'; +``` + +### Combined Declaration and Initialization + +```cpp +int age = 25; +char grade = 'A'; +``` + +## Conclusion + +Understanding C++ variables and data types is fundamental to writing efficient and effective C++ code. By mastering these concepts, you can work with different types of data and create dynamic and robust applications in C++. diff --git a/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md b/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md index 813d677bd..c9b530c37 100644 --- a/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md +++ b/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md @@ -6,4 +6,71 @@ sidebar_position: 3 tags: [c++, operators, expressions, programming, c++ operators, c++ expressions] description: In this tutorial, we will learn about operators and expressions in C++. We will learn about the different types of operators available in C++, how to use them, and how to create expressions using operators. ---- \ No newline at end of file +--- + +# Operators and Expressions in C++ + +## Operators + +C++ supports various operators for arithmetic, comparison, logical operations, etc. + +### Arithmetic Operators + +- `+` (addition) +- `-` (subtraction) +- `*` (multiplication) +- `/` (division) +- `%` (modulus) + +Example: + +```cpp +int sum = 10 + 5; // 15 +int difference = 10 - 5; // 5 +``` + +### Comparison Operators + +- `==` (equal to) +- `!=` (not equal to) +- `>` (greater than) +- `<` (less than) +- `>=` (greater than or equal to) +- `<=` (less than or equal to) + +Example: + +```cpp +bool isEqual = (10 == 10); // true +bool isGreater = (10 > 5); // true +``` + +### Logical Operators + +- `&&` (logical AND) +- `||` (logical OR) +- `!` (logical NOT) + +Example: + +```cpp +bool result = (true && false); // false +bool orResult = (true || false); // true +``` + +## Expressions + +Expressions in C++ are formed using operators and operands. An expression can be a combination of literals, variables, and operators. + +Example: + +```cpp +int x = 10; +int y = 5; +int z = x + y; // z = 15 +bool isTrue = (x > y) && (z != y); // true +``` + +## Conclusion + +Understanding C++ operators and expressions is fundamental to writing effective C++ code. By mastering these concepts, you can perform various operations and create complex expressions in your C++ programs. diff --git a/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md b/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md index 99d24c2d0..98ca5c996 100644 --- a/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md +++ b/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md @@ -14,4 +14,89 @@ tags: c++ features, ] description: In this tutorial, we will learn about the syntax and structure of the C++ programming language. We will learn about the basic structure of a C++ program, C++ syntax, and the rules that govern the C++ programming language. ---- \ No newline at end of file +--- + +# C++ Syntax and Structure + +## Introduction + +Understanding the basic syntax and structure of C++ is essential for writing effective C++ programs. This guide covers the fundamental elements of C++ syntax and how to structure a C++ program. + +## Basic Syntax + +### Hello World Example + +The simplest C++ program is a "Hello, World!" application. Here's what it looks like: + +```cpp +#include + +int main() { + std::cout << "Hello, World!" << std::endl; + return 0; +} +``` + +### Explanation + +- **Header File**: The `#include ` line includes the input/output stream library, allowing us to use `cout` and `endl`. +- **Main Function**: The `main` function is the entry point of any C++ application. It returns an integer value (`int`) indicating the exit status. +- **Output Statement**: The `std::cout << "Hello, World!" << std::endl;` statement prints the specified message to the console. + +## Comments + +Comments are used to explain code and are ignored by the compiler. + +- **Single-line comments** start with `//`. + +```cpp +// This is a single-line comment +``` + +- **Multi-line comments** are enclosed in `/* ... */`. + +```cpp +/* + This is a multi-line comment + that spans multiple lines. + */ +``` + +## Data Types and Variables + +C++ supports various data types such as `int`, `double`, `char`, `bool`, etc., and allows the declaration of variables using the syntax `datatype variableName;`. + +```cpp +int age = 25; +double salary = 50000.50; +char grade = 'A'; +bool isEmployed = true; +``` + +## Control Structures + +C++ provides control structures like `if`, `else`, `for`, `while`, and `switch` for conditional and looping operations. + +```cpp +if (age >= 18) { + std::cout << "You are an adult." << std::endl; +} else { + std::cout << "You are a minor." << std::endl; +} +``` + +## Functions + +Functions in C++ are declared using the syntax `returnType functionName(parameters) { ... }`. + +```cpp +int add(int a, int b) { + return a + b; +} + +int result = add(5, 10); // result = 15 +``` + +## Conclusion + +Understanding the basic syntax and structure of C++ is foundational to becoming proficient in C++ programming. By mastering these concepts, you can write efficient and reliable C++ code for various applications. diff --git a/docs/cpp/home.md b/docs/cpp/home.md index 79b9ac816..8086d20f8 100644 --- a/docs/cpp/home.md +++ b/docs/cpp/home.md @@ -5,4 +5,49 @@ sidebar_label: Overview sidebar_position: 1 tags: [C++, overview] description: In this tutorial, you will learn about the C++ programming language, its features, and its applications. ---- \ No newline at end of file +--- + +C++ is a high-level, general-purpose programming language that is widely used for developing system software, application software, game development, and more. It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, and templates. + +## What we will learn in this tutorial? + +In this tutorial, you will learn about the C++ programming language, its features, and its applications. You will also learn how to set up a C++ development environment on your computer and write your first C++ program. + +## What is C++? + +- C++ is a high-level, general-purpose programming language. +- It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, and templates. +- C++ is designed for system programming, application development, game development, and more. +- It is a statically typed language, which means that variable types are checked at compile time. +- C++ supports both procedural programming and object-oriented programming paradigms. +- C++ code is typically compiled into machine code for execution. + +## Features of C++ + +- **Object-Oriented**: C++ is an object-oriented programming language. It supports the concepts of classes and objects, inheritance, polymorphism, and encapsulation. +- **Statically Typed**: C++ is a statically typed language, which means that variable types are checked at compile time. +- **Compiled Language**: C++ code is compiled into machine code for execution, which can result in high performance. +- **Portable**: C++ code can be compiled and executed on different platforms, making it portable. +- **Memory Management**: C++ allows manual memory management using pointers, which gives developers more control over memory allocation and deallocation. +- **Standard Library**: C++ provides a rich standard library that includes data structures, algorithms, input/output functions, and more. +- **Compatibility with C**: C++ is compatible with C code, allowing developers to use existing C libraries and code in C++ programs. + +## Applications of C++ + +C++ is used in a wide range of applications, including: + +- **System Software**: C++ is used to develop system software such as operating systems, device drivers, and firmware. +- **Application Software**: C++ is used to develop application software such as desktop applications, business applications, and productivity tools. +- **Game Development**: C++ is widely used in game development. It is used to build game engines, game logic, and graphics rendering. +- **Embedded Systems**: C++ is used in embedded systems development. It is used to build embedded software for devices such as microcontrollers, IoT devices, and automotive systems. +- **High-Performance Computing**: C++ is used in high-performance computing (HPC) applications such as scientific computing, simulations, and data analysis. +- **Graphics Programming**: C++ is used in graphics programming. It is used to develop graphics libraries, rendering engines, and graphical user interfaces (GUIs). +- **Financial Applications**: C++ is used in financial applications such as trading systems, risk management software, and financial modeling tools. +- **Compiler Development**: C++ is used to develop compilers, interpreters, and language tools for other programming languages. +- **Networking**: C++ is used in networking applications such as network protocols, servers, and communication software. +- **Artificial Intelligence**: C++ is used in artificial intelligence (AI) applications such as machine learning algorithms, neural networks, and AI research. +- **Multimedia Applications**: C++ is used in multimedia applications such as audio/video processing, image processing, and media players. + +## Conclusion + +C++ is a powerful and versatile programming language that is widely used in various domains. It combines the features of procedural programming with object-oriented programming, making it suitable for a wide range of applications. Whether you are a beginner or an experienced developer, learning C++ can open up opportunities to work on exciting projects and technologies. In this tutorial, you will learn the basics of C++ programming and how to get started with C++ development. Let's dive in! diff --git a/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md b/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md index 31aadab51..b4deb4829 100644 --- a/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md +++ b/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md @@ -5,4 +5,45 @@ sidebar_label: Setup C++ Development Environment sidebar_position: 3 tags: [c++, setup c++ development environment] description: In this tutorial, you will walk through all the steps of setting up a C++ development environment on your local computer. ---- \ No newline at end of file +--- + +# Setting Up a C++ Environment + +## Introduction + +Before you can start programming in C++, you need to set up your development environment. This typically involves installing the necessary software and configuring your system to compile and run C++ code. + +## Steps to Set Up C++ Environment + +1. **Install a C++ Compiler**: + + - For Windows, you can install MinGW or Microsoft Visual C++ Compiler. + - For macOS, you can install Xcode Command Line Tools or use Homebrew to install GCC. + - For Linux, you can use your package manager to install GCC or Clang. + +2. **Choose a Text Editor or Integrated Development Environment (IDE)**: + + - Choose a text editor like Visual Studio Code, Sublime Text, or Atom, or an IDE like Visual Studio or CLion for C++ development. + - Download and install the chosen editor or IDE from their official websites. + +3. **Set Up Compiler and Build Tools**: + + - If using an IDE, configure it to use the installed C++ compiler (e.g., GCC or Clang). + - For text editors, install C++ language support extensions or plugins for syntax highlighting and code completion. + +4. **Install C++ Libraries and Frameworks** (Optional but recommended): + + - Depending on your project requirements, install any necessary C++ libraries or frameworks like Boost, Qt, or OpenGL. + - Configure your development environment to include these libraries in your project. + +5. **Verify Installation**: + + - Open a terminal or command prompt and type `g++ --version` (for GCC) or `clang++ --version` (for Clang) to verify that the C++ compiler is installed and accessible. + +6. **Set Up Environment Variables** (Optional but recommended): + + - Set up environment variables such as `PATH` to include the directory containing the C++ compiler and build tools, allowing you to run C++ commands from any directory in the terminal or command prompt. + +## Conclusion + +Setting up a C++ environment is crucial for C++ developers to compile, run, and manage C++ applications effectively. By following these steps and choosing the right tools for your needs, you can create a well-configured development environment that enhances your productivity and workflow when working with C++ code. diff --git a/docs/cpp/introduction-to-cpp/what-is-cpp.md b/docs/cpp/introduction-to-cpp/what-is-cpp.md index 9d595be6f..585f7e029 100644 --- a/docs/cpp/introduction-to-cpp/what-is-cpp.md +++ b/docs/cpp/introduction-to-cpp/what-is-cpp.md @@ -5,4 +5,43 @@ sidebar_label: What is C++? sidebar_position: 1 tags: [c++, what is c++, introduction to c++] description: In this tutorial, you will learn about the C++ programming language, what it is, its features, and its applications. ---- \ No newline at end of file +--- + +# Introduction to C++ + +## What is C++? + +C++ is a powerful and widely-used programming language known for its versatility, performance, and extensive feature set. It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, templates, and more. C++ is designed for system programming, application development, game development, and other domains. + +## Key Features of C++ + +- **Object-Oriented**: C++ is an object-oriented programming (OOP) language, allowing developers to create classes and objects that encapsulate data and behavior. +- **Statically Typed**: C++ is a statically typed language, meaning that variable types are checked at compile time for type safety. +- **Compiled Language**: C++ code is compiled into machine code for execution, resulting in high performance and efficiency. +- **Memory Management**: C++ allows manual memory management using pointers, giving developers control over memory allocation and deallocation. +- **Standard Library**: C++ provides a rich standard library with data structures, algorithms, input/output functions, and more, facilitating software development. +- **Compatibility with C**: C++ is compatible with C code, allowing developers to use existing C libraries and code in C++ programs. + +## C++ Development Ecosystem + +C++ has a comprehensive development ecosystem comprising various tools, libraries, and frameworks: + +- **Integrated Development Environments (IDEs)**: Popular IDEs for C++ development include Visual Studio, Code::Blocks, and CLion, offering features like code completion, debugging, and project management. + +- **Libraries and Frameworks**: C++ has numerous libraries and frameworks for different purposes, such as Boost for general-purpose programming, Qt for GUI development, and OpenGL for graphics programming. + +- **Community Support**: C++ has a vibrant community of developers who contribute to open-source projects, share knowledge through forums and blogs, and provide support to fellow developers. + +## C++ Editions + +C++ has evolved over time, leading to different editions tailored for specific platforms and use cases: + +- **Standard C++**: Also known as ISO C++, this is the standardized version of the language maintained by the International Organization for Standardization (ISO). + +- **C++11, C++14, C++17, C++20**: These are versions of the language that introduce new features and improvements, enhancing productivity and code quality. + +- **Embedded C++ (EC++)**: Optimized for embedded systems development, EC++ focuses on efficiency, low-level programming, and resource-constrained environments. + +## Conclusion + +C++ continues to be a preferred choice for developers due to its versatility, performance, and extensive ecosystem. Whether you are building system software, applications, games, or embedded systems, C++ offers the tools and capabilities to meet diverse development needs. Its object-oriented nature, strong memory management, and compatibility with C make it a robust and reliable language for a wide range of projects. diff --git a/docs/cpp/introduction-to-cpp/why-learn-cpp.md b/docs/cpp/introduction-to-cpp/why-learn-cpp.md index 7a1db0850..9e530479b 100644 --- a/docs/cpp/introduction-to-cpp/why-learn-cpp.md +++ b/docs/cpp/introduction-to-cpp/why-learn-cpp.md @@ -5,4 +5,30 @@ sidebar_label: Why Learn C++? sidebar_position: 2 tags: [c++, why learn c++] description: In this tutorial, you will learn about the many applications of the C++ programming language and the benefits of learning it. ---- \ No newline at end of file +--- + +# Why Learn C++? + +## Introduction + +C++ is a powerful and widely-used programming language with numerous advantages that make it a valuable skill for developers. + +## Reasons to Learn C++ + +- **Versatility**: C++ is a versatile language used in system programming, game development, high-performance applications, embedded systems, and more. Learning C++ opens doors to diverse career opportunities. + +- **Performance**: C++ is known for its high performance and efficiency, making it suitable for applications that require speed and resource optimization, such as real-time systems, simulations, and games. + +- **Compatibility with C**: C++ is compatible with C code, allowing developers to leverage existing C libraries and code in C++ programs. This compatibility enhances code reusability and integration. + +- **Object-Oriented Programming (OOP)**: C++ is an object-oriented programming language, emphasizing concepts like classes, objects, inheritance, and polymorphism. Learning C++ helps developers master OOP principles, which are fundamental in modern software development. + +- **Memory Management**: C++ offers manual memory management through pointers, giving developers fine-grained control over memory allocation and deallocation. This level of control is beneficial for optimizing resource usage and performance. + +- **Strong Community and Resources**: C++ has a robust community of developers, forums, libraries, and frameworks that provide support, resources, and tools for C++ development. Being part of this community can enhance your learning experience and accelerate your growth as a developer. + +- **Industry Demand**: C++ developers are in demand across various industries, including finance, gaming, automotive, aerospace, and technology. Learning C++ increases your marketability and opens doors to exciting career opportunities. + +## Conclusion + +Whether you're interested in system programming, game development, high-performance computing, or embedded systems, learning C++ offers numerous benefits. Its versatility, performance, compatibility with C, strong community support, and industry demand make it a valuable language to learn and master in today's competitive software development landscape. From 1ffa18e1e7608771c0a828cee97d33ea60216fd8 Mon Sep 17 00:00:00 2001 From: Vipul_Lakum Date: Wed, 5 Jun 2024 16:52:13 +0530 Subject: [PATCH 5/6] commits switch to cpp-docs --- .../02_Variables_and_Data_Types.md | 69 +-------------- .../03_Operators_and_Expressions.md | 69 +-------------- .../cpp-syntax-basics.md | 87 +------------------ docs/cpp/home.md | 47 +--------- .../setting-up-your-cpp-environment.md | 43 +-------- docs/cpp/introduction-to-cpp/what-is-cpp.md | 41 +-------- docs/cpp/introduction-to-cpp/why-learn-cpp.md | 28 +----- 7 files changed, 7 insertions(+), 377 deletions(-) diff --git a/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md b/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md index db27271ae..054a00863 100644 --- a/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md +++ b/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md @@ -13,71 +13,4 @@ tags: c++ data types ] description: In this tutorial, we will learn about variables and data types in C++. We will learn about what variables are, how to declare and initialize variables, and the different data types available in the language. ---- - -# Variables and Data Types in C++ - -## Data Types - -C++ is a strongly-typed language, meaning every variable must be declared with a data type. - -### Primitive Data Types - -- **int**: Integer type. -- **double**: Double-precision floating point. -- **char**: Character type. -- **bool**: Boolean type (true or false). - -Example: - -```cpp -int number = 10; -double price = 9.99; -char letter = 'A'; -bool isCppFun = true; -``` - -### Derived Data Types - -Derived data types are created from fundamental data types. - -- **Array**: A collection of elements of the same data type. -- **Pointer**: A variable that stores the memory address of another variable. -- **Reference**: A reference to another variable, often used in functions. - -Example: - -```cpp -int numbers[] = {1, 2, 3, 4, 5}; -int* ptr = &number; -int& refNumber = number; -``` - -## Variables - -Variables store data values and must be declared before use. - -### Variable Declaration - -```cpp -int age; -char grade; -``` - -### Variable Initialization - -```cpp -age = 25; -grade = 'A'; -``` - -### Combined Declaration and Initialization - -```cpp -int age = 25; -char grade = 'A'; -``` - -## Conclusion - -Understanding C++ variables and data types is fundamental to writing efficient and effective C++ code. By mastering these concepts, you can work with different types of data and create dynamic and robust applications in C++. +--- \ No newline at end of file diff --git a/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md b/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md index c9b530c37..813d677bd 100644 --- a/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md +++ b/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md @@ -6,71 +6,4 @@ sidebar_position: 3 tags: [c++, operators, expressions, programming, c++ operators, c++ expressions] description: In this tutorial, we will learn about operators and expressions in C++. We will learn about the different types of operators available in C++, how to use them, and how to create expressions using operators. ---- - -# Operators and Expressions in C++ - -## Operators - -C++ supports various operators for arithmetic, comparison, logical operations, etc. - -### Arithmetic Operators - -- `+` (addition) -- `-` (subtraction) -- `*` (multiplication) -- `/` (division) -- `%` (modulus) - -Example: - -```cpp -int sum = 10 + 5; // 15 -int difference = 10 - 5; // 5 -``` - -### Comparison Operators - -- `==` (equal to) -- `!=` (not equal to) -- `>` (greater than) -- `<` (less than) -- `>=` (greater than or equal to) -- `<=` (less than or equal to) - -Example: - -```cpp -bool isEqual = (10 == 10); // true -bool isGreater = (10 > 5); // true -``` - -### Logical Operators - -- `&&` (logical AND) -- `||` (logical OR) -- `!` (logical NOT) - -Example: - -```cpp -bool result = (true && false); // false -bool orResult = (true || false); // true -``` - -## Expressions - -Expressions in C++ are formed using operators and operands. An expression can be a combination of literals, variables, and operators. - -Example: - -```cpp -int x = 10; -int y = 5; -int z = x + y; // z = 15 -bool isTrue = (x > y) && (z != y); // true -``` - -## Conclusion - -Understanding C++ operators and expressions is fundamental to writing effective C++ code. By mastering these concepts, you can perform various operations and create complex expressions in your C++ programs. +--- \ No newline at end of file diff --git a/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md b/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md index 98ca5c996..99d24c2d0 100644 --- a/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md +++ b/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md @@ -14,89 +14,4 @@ tags: c++ features, ] description: In this tutorial, we will learn about the syntax and structure of the C++ programming language. We will learn about the basic structure of a C++ program, C++ syntax, and the rules that govern the C++ programming language. ---- - -# C++ Syntax and Structure - -## Introduction - -Understanding the basic syntax and structure of C++ is essential for writing effective C++ programs. This guide covers the fundamental elements of C++ syntax and how to structure a C++ program. - -## Basic Syntax - -### Hello World Example - -The simplest C++ program is a "Hello, World!" application. Here's what it looks like: - -```cpp -#include - -int main() { - std::cout << "Hello, World!" << std::endl; - return 0; -} -``` - -### Explanation - -- **Header File**: The `#include ` line includes the input/output stream library, allowing us to use `cout` and `endl`. -- **Main Function**: The `main` function is the entry point of any C++ application. It returns an integer value (`int`) indicating the exit status. -- **Output Statement**: The `std::cout << "Hello, World!" << std::endl;` statement prints the specified message to the console. - -## Comments - -Comments are used to explain code and are ignored by the compiler. - -- **Single-line comments** start with `//`. - -```cpp -// This is a single-line comment -``` - -- **Multi-line comments** are enclosed in `/* ... */`. - -```cpp -/* - This is a multi-line comment - that spans multiple lines. - */ -``` - -## Data Types and Variables - -C++ supports various data types such as `int`, `double`, `char`, `bool`, etc., and allows the declaration of variables using the syntax `datatype variableName;`. - -```cpp -int age = 25; -double salary = 50000.50; -char grade = 'A'; -bool isEmployed = true; -``` - -## Control Structures - -C++ provides control structures like `if`, `else`, `for`, `while`, and `switch` for conditional and looping operations. - -```cpp -if (age >= 18) { - std::cout << "You are an adult." << std::endl; -} else { - std::cout << "You are a minor." << std::endl; -} -``` - -## Functions - -Functions in C++ are declared using the syntax `returnType functionName(parameters) { ... }`. - -```cpp -int add(int a, int b) { - return a + b; -} - -int result = add(5, 10); // result = 15 -``` - -## Conclusion - -Understanding the basic syntax and structure of C++ is foundational to becoming proficient in C++ programming. By mastering these concepts, you can write efficient and reliable C++ code for various applications. +--- \ No newline at end of file diff --git a/docs/cpp/home.md b/docs/cpp/home.md index 8086d20f8..79b9ac816 100644 --- a/docs/cpp/home.md +++ b/docs/cpp/home.md @@ -5,49 +5,4 @@ sidebar_label: Overview sidebar_position: 1 tags: [C++, overview] description: In this tutorial, you will learn about the C++ programming language, its features, and its applications. ---- - -C++ is a high-level, general-purpose programming language that is widely used for developing system software, application software, game development, and more. It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, and templates. - -## What we will learn in this tutorial? - -In this tutorial, you will learn about the C++ programming language, its features, and its applications. You will also learn how to set up a C++ development environment on your computer and write your first C++ program. - -## What is C++? - -- C++ is a high-level, general-purpose programming language. -- It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, and templates. -- C++ is designed for system programming, application development, game development, and more. -- It is a statically typed language, which means that variable types are checked at compile time. -- C++ supports both procedural programming and object-oriented programming paradigms. -- C++ code is typically compiled into machine code for execution. - -## Features of C++ - -- **Object-Oriented**: C++ is an object-oriented programming language. It supports the concepts of classes and objects, inheritance, polymorphism, and encapsulation. -- **Statically Typed**: C++ is a statically typed language, which means that variable types are checked at compile time. -- **Compiled Language**: C++ code is compiled into machine code for execution, which can result in high performance. -- **Portable**: C++ code can be compiled and executed on different platforms, making it portable. -- **Memory Management**: C++ allows manual memory management using pointers, which gives developers more control over memory allocation and deallocation. -- **Standard Library**: C++ provides a rich standard library that includes data structures, algorithms, input/output functions, and more. -- **Compatibility with C**: C++ is compatible with C code, allowing developers to use existing C libraries and code in C++ programs. - -## Applications of C++ - -C++ is used in a wide range of applications, including: - -- **System Software**: C++ is used to develop system software such as operating systems, device drivers, and firmware. -- **Application Software**: C++ is used to develop application software such as desktop applications, business applications, and productivity tools. -- **Game Development**: C++ is widely used in game development. It is used to build game engines, game logic, and graphics rendering. -- **Embedded Systems**: C++ is used in embedded systems development. It is used to build embedded software for devices such as microcontrollers, IoT devices, and automotive systems. -- **High-Performance Computing**: C++ is used in high-performance computing (HPC) applications such as scientific computing, simulations, and data analysis. -- **Graphics Programming**: C++ is used in graphics programming. It is used to develop graphics libraries, rendering engines, and graphical user interfaces (GUIs). -- **Financial Applications**: C++ is used in financial applications such as trading systems, risk management software, and financial modeling tools. -- **Compiler Development**: C++ is used to develop compilers, interpreters, and language tools for other programming languages. -- **Networking**: C++ is used in networking applications such as network protocols, servers, and communication software. -- **Artificial Intelligence**: C++ is used in artificial intelligence (AI) applications such as machine learning algorithms, neural networks, and AI research. -- **Multimedia Applications**: C++ is used in multimedia applications such as audio/video processing, image processing, and media players. - -## Conclusion - -C++ is a powerful and versatile programming language that is widely used in various domains. It combines the features of procedural programming with object-oriented programming, making it suitable for a wide range of applications. Whether you are a beginner or an experienced developer, learning C++ can open up opportunities to work on exciting projects and technologies. In this tutorial, you will learn the basics of C++ programming and how to get started with C++ development. Let's dive in! +--- \ No newline at end of file diff --git a/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md b/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md index b4deb4829..31aadab51 100644 --- a/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md +++ b/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md @@ -5,45 +5,4 @@ sidebar_label: Setup C++ Development Environment sidebar_position: 3 tags: [c++, setup c++ development environment] description: In this tutorial, you will walk through all the steps of setting up a C++ development environment on your local computer. ---- - -# Setting Up a C++ Environment - -## Introduction - -Before you can start programming in C++, you need to set up your development environment. This typically involves installing the necessary software and configuring your system to compile and run C++ code. - -## Steps to Set Up C++ Environment - -1. **Install a C++ Compiler**: - - - For Windows, you can install MinGW or Microsoft Visual C++ Compiler. - - For macOS, you can install Xcode Command Line Tools or use Homebrew to install GCC. - - For Linux, you can use your package manager to install GCC or Clang. - -2. **Choose a Text Editor or Integrated Development Environment (IDE)**: - - - Choose a text editor like Visual Studio Code, Sublime Text, or Atom, or an IDE like Visual Studio or CLion for C++ development. - - Download and install the chosen editor or IDE from their official websites. - -3. **Set Up Compiler and Build Tools**: - - - If using an IDE, configure it to use the installed C++ compiler (e.g., GCC or Clang). - - For text editors, install C++ language support extensions or plugins for syntax highlighting and code completion. - -4. **Install C++ Libraries and Frameworks** (Optional but recommended): - - - Depending on your project requirements, install any necessary C++ libraries or frameworks like Boost, Qt, or OpenGL. - - Configure your development environment to include these libraries in your project. - -5. **Verify Installation**: - - - Open a terminal or command prompt and type `g++ --version` (for GCC) or `clang++ --version` (for Clang) to verify that the C++ compiler is installed and accessible. - -6. **Set Up Environment Variables** (Optional but recommended): - - - Set up environment variables such as `PATH` to include the directory containing the C++ compiler and build tools, allowing you to run C++ commands from any directory in the terminal or command prompt. - -## Conclusion - -Setting up a C++ environment is crucial for C++ developers to compile, run, and manage C++ applications effectively. By following these steps and choosing the right tools for your needs, you can create a well-configured development environment that enhances your productivity and workflow when working with C++ code. +--- \ No newline at end of file diff --git a/docs/cpp/introduction-to-cpp/what-is-cpp.md b/docs/cpp/introduction-to-cpp/what-is-cpp.md index 585f7e029..9d595be6f 100644 --- a/docs/cpp/introduction-to-cpp/what-is-cpp.md +++ b/docs/cpp/introduction-to-cpp/what-is-cpp.md @@ -5,43 +5,4 @@ sidebar_label: What is C++? sidebar_position: 1 tags: [c++, what is c++, introduction to c++] description: In this tutorial, you will learn about the C++ programming language, what it is, its features, and its applications. ---- - -# Introduction to C++ - -## What is C++? - -C++ is a powerful and widely-used programming language known for its versatility, performance, and extensive feature set. It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, templates, and more. C++ is designed for system programming, application development, game development, and other domains. - -## Key Features of C++ - -- **Object-Oriented**: C++ is an object-oriented programming (OOP) language, allowing developers to create classes and objects that encapsulate data and behavior. -- **Statically Typed**: C++ is a statically typed language, meaning that variable types are checked at compile time for type safety. -- **Compiled Language**: C++ code is compiled into machine code for execution, resulting in high performance and efficiency. -- **Memory Management**: C++ allows manual memory management using pointers, giving developers control over memory allocation and deallocation. -- **Standard Library**: C++ provides a rich standard library with data structures, algorithms, input/output functions, and more, facilitating software development. -- **Compatibility with C**: C++ is compatible with C code, allowing developers to use existing C libraries and code in C++ programs. - -## C++ Development Ecosystem - -C++ has a comprehensive development ecosystem comprising various tools, libraries, and frameworks: - -- **Integrated Development Environments (IDEs)**: Popular IDEs for C++ development include Visual Studio, Code::Blocks, and CLion, offering features like code completion, debugging, and project management. - -- **Libraries and Frameworks**: C++ has numerous libraries and frameworks for different purposes, such as Boost for general-purpose programming, Qt for GUI development, and OpenGL for graphics programming. - -- **Community Support**: C++ has a vibrant community of developers who contribute to open-source projects, share knowledge through forums and blogs, and provide support to fellow developers. - -## C++ Editions - -C++ has evolved over time, leading to different editions tailored for specific platforms and use cases: - -- **Standard C++**: Also known as ISO C++, this is the standardized version of the language maintained by the International Organization for Standardization (ISO). - -- **C++11, C++14, C++17, C++20**: These are versions of the language that introduce new features and improvements, enhancing productivity and code quality. - -- **Embedded C++ (EC++)**: Optimized for embedded systems development, EC++ focuses on efficiency, low-level programming, and resource-constrained environments. - -## Conclusion - -C++ continues to be a preferred choice for developers due to its versatility, performance, and extensive ecosystem. Whether you are building system software, applications, games, or embedded systems, C++ offers the tools and capabilities to meet diverse development needs. Its object-oriented nature, strong memory management, and compatibility with C make it a robust and reliable language for a wide range of projects. +--- \ No newline at end of file diff --git a/docs/cpp/introduction-to-cpp/why-learn-cpp.md b/docs/cpp/introduction-to-cpp/why-learn-cpp.md index 9e530479b..7a1db0850 100644 --- a/docs/cpp/introduction-to-cpp/why-learn-cpp.md +++ b/docs/cpp/introduction-to-cpp/why-learn-cpp.md @@ -5,30 +5,4 @@ sidebar_label: Why Learn C++? sidebar_position: 2 tags: [c++, why learn c++] description: In this tutorial, you will learn about the many applications of the C++ programming language and the benefits of learning it. ---- - -# Why Learn C++? - -## Introduction - -C++ is a powerful and widely-used programming language with numerous advantages that make it a valuable skill for developers. - -## Reasons to Learn C++ - -- **Versatility**: C++ is a versatile language used in system programming, game development, high-performance applications, embedded systems, and more. Learning C++ opens doors to diverse career opportunities. - -- **Performance**: C++ is known for its high performance and efficiency, making it suitable for applications that require speed and resource optimization, such as real-time systems, simulations, and games. - -- **Compatibility with C**: C++ is compatible with C code, allowing developers to leverage existing C libraries and code in C++ programs. This compatibility enhances code reusability and integration. - -- **Object-Oriented Programming (OOP)**: C++ is an object-oriented programming language, emphasizing concepts like classes, objects, inheritance, and polymorphism. Learning C++ helps developers master OOP principles, which are fundamental in modern software development. - -- **Memory Management**: C++ offers manual memory management through pointers, giving developers fine-grained control over memory allocation and deallocation. This level of control is beneficial for optimizing resource usage and performance. - -- **Strong Community and Resources**: C++ has a robust community of developers, forums, libraries, and frameworks that provide support, resources, and tools for C++ development. Being part of this community can enhance your learning experience and accelerate your growth as a developer. - -- **Industry Demand**: C++ developers are in demand across various industries, including finance, gaming, automotive, aerospace, and technology. Learning C++ increases your marketability and opens doors to exciting career opportunities. - -## Conclusion - -Whether you're interested in system programming, game development, high-performance computing, or embedded systems, learning C++ offers numerous benefits. Its versatility, performance, compatibility with C, strong community support, and industry demand make it a valuable language to learn and master in today's competitive software development landscape. +--- \ No newline at end of file From d0de603a3f395e9f6b844d51dc816ff84b69f8e3 Mon Sep 17 00:00:00 2001 From: Vipul_Lakum Date: Wed, 5 Jun 2024 16:54:32 +0530 Subject: [PATCH 6/6] cpp docs added --- .../02_Variables_and_Data_Types.md | 69 ++++++++++++++- .../03_Operators_and_Expressions.md | 69 ++++++++++++++- .../cpp-syntax-basics.md | 87 ++++++++++++++++++- docs/cpp/home.md | 47 +++++++++- .../setting-up-your-cpp-environment.md | 43 ++++++++- docs/cpp/introduction-to-cpp/what-is-cpp.md | 41 ++++++++- docs/cpp/introduction-to-cpp/why-learn-cpp.md | 28 +++++- 7 files changed, 377 insertions(+), 7 deletions(-) diff --git a/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md b/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md index 054a00863..db27271ae 100644 --- a/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md +++ b/docs/cpp/basic-syntax-and-structure/02_Variables_and_Data_Types.md @@ -13,4 +13,71 @@ tags: c++ data types ] description: In this tutorial, we will learn about variables and data types in C++. We will learn about what variables are, how to declare and initialize variables, and the different data types available in the language. ---- \ No newline at end of file +--- + +# Variables and Data Types in C++ + +## Data Types + +C++ is a strongly-typed language, meaning every variable must be declared with a data type. + +### Primitive Data Types + +- **int**: Integer type. +- **double**: Double-precision floating point. +- **char**: Character type. +- **bool**: Boolean type (true or false). + +Example: + +```cpp +int number = 10; +double price = 9.99; +char letter = 'A'; +bool isCppFun = true; +``` + +### Derived Data Types + +Derived data types are created from fundamental data types. + +- **Array**: A collection of elements of the same data type. +- **Pointer**: A variable that stores the memory address of another variable. +- **Reference**: A reference to another variable, often used in functions. + +Example: + +```cpp +int numbers[] = {1, 2, 3, 4, 5}; +int* ptr = &number; +int& refNumber = number; +``` + +## Variables + +Variables store data values and must be declared before use. + +### Variable Declaration + +```cpp +int age; +char grade; +``` + +### Variable Initialization + +```cpp +age = 25; +grade = 'A'; +``` + +### Combined Declaration and Initialization + +```cpp +int age = 25; +char grade = 'A'; +``` + +## Conclusion + +Understanding C++ variables and data types is fundamental to writing efficient and effective C++ code. By mastering these concepts, you can work with different types of data and create dynamic and robust applications in C++. diff --git a/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md b/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md index 813d677bd..c9b530c37 100644 --- a/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md +++ b/docs/cpp/basic-syntax-and-structure/03_Operators_and_Expressions.md @@ -6,4 +6,71 @@ sidebar_position: 3 tags: [c++, operators, expressions, programming, c++ operators, c++ expressions] description: In this tutorial, we will learn about operators and expressions in C++. We will learn about the different types of operators available in C++, how to use them, and how to create expressions using operators. ---- \ No newline at end of file +--- + +# Operators and Expressions in C++ + +## Operators + +C++ supports various operators for arithmetic, comparison, logical operations, etc. + +### Arithmetic Operators + +- `+` (addition) +- `-` (subtraction) +- `*` (multiplication) +- `/` (division) +- `%` (modulus) + +Example: + +```cpp +int sum = 10 + 5; // 15 +int difference = 10 - 5; // 5 +``` + +### Comparison Operators + +- `==` (equal to) +- `!=` (not equal to) +- `>` (greater than) +- `<` (less than) +- `>=` (greater than or equal to) +- `<=` (less than or equal to) + +Example: + +```cpp +bool isEqual = (10 == 10); // true +bool isGreater = (10 > 5); // true +``` + +### Logical Operators + +- `&&` (logical AND) +- `||` (logical OR) +- `!` (logical NOT) + +Example: + +```cpp +bool result = (true && false); // false +bool orResult = (true || false); // true +``` + +## Expressions + +Expressions in C++ are formed using operators and operands. An expression can be a combination of literals, variables, and operators. + +Example: + +```cpp +int x = 10; +int y = 5; +int z = x + y; // z = 15 +bool isTrue = (x > y) && (z != y); // true +``` + +## Conclusion + +Understanding C++ operators and expressions is fundamental to writing effective C++ code. By mastering these concepts, you can perform various operations and create complex expressions in your C++ programs. diff --git a/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md b/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md index 99d24c2d0..98ca5c996 100644 --- a/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md +++ b/docs/cpp/basic-syntax-and-structure/cpp-syntax-basics.md @@ -14,4 +14,89 @@ tags: c++ features, ] description: In this tutorial, we will learn about the syntax and structure of the C++ programming language. We will learn about the basic structure of a C++ program, C++ syntax, and the rules that govern the C++ programming language. ---- \ No newline at end of file +--- + +# C++ Syntax and Structure + +## Introduction + +Understanding the basic syntax and structure of C++ is essential for writing effective C++ programs. This guide covers the fundamental elements of C++ syntax and how to structure a C++ program. + +## Basic Syntax + +### Hello World Example + +The simplest C++ program is a "Hello, World!" application. Here's what it looks like: + +```cpp +#include + +int main() { + std::cout << "Hello, World!" << std::endl; + return 0; +} +``` + +### Explanation + +- **Header File**: The `#include ` line includes the input/output stream library, allowing us to use `cout` and `endl`. +- **Main Function**: The `main` function is the entry point of any C++ application. It returns an integer value (`int`) indicating the exit status. +- **Output Statement**: The `std::cout << "Hello, World!" << std::endl;` statement prints the specified message to the console. + +## Comments + +Comments are used to explain code and are ignored by the compiler. + +- **Single-line comments** start with `//`. + +```cpp +// This is a single-line comment +``` + +- **Multi-line comments** are enclosed in `/* ... */`. + +```cpp +/* + This is a multi-line comment + that spans multiple lines. + */ +``` + +## Data Types and Variables + +C++ supports various data types such as `int`, `double`, `char`, `bool`, etc., and allows the declaration of variables using the syntax `datatype variableName;`. + +```cpp +int age = 25; +double salary = 50000.50; +char grade = 'A'; +bool isEmployed = true; +``` + +## Control Structures + +C++ provides control structures like `if`, `else`, `for`, `while`, and `switch` for conditional and looping operations. + +```cpp +if (age >= 18) { + std::cout << "You are an adult." << std::endl; +} else { + std::cout << "You are a minor." << std::endl; +} +``` + +## Functions + +Functions in C++ are declared using the syntax `returnType functionName(parameters) { ... }`. + +```cpp +int add(int a, int b) { + return a + b; +} + +int result = add(5, 10); // result = 15 +``` + +## Conclusion + +Understanding the basic syntax and structure of C++ is foundational to becoming proficient in C++ programming. By mastering these concepts, you can write efficient and reliable C++ code for various applications. diff --git a/docs/cpp/home.md b/docs/cpp/home.md index 79b9ac816..8086d20f8 100644 --- a/docs/cpp/home.md +++ b/docs/cpp/home.md @@ -5,4 +5,49 @@ sidebar_label: Overview sidebar_position: 1 tags: [C++, overview] description: In this tutorial, you will learn about the C++ programming language, its features, and its applications. ---- \ No newline at end of file +--- + +C++ is a high-level, general-purpose programming language that is widely used for developing system software, application software, game development, and more. It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, and templates. + +## What we will learn in this tutorial? + +In this tutorial, you will learn about the C++ programming language, its features, and its applications. You will also learn how to set up a C++ development environment on your computer and write your first C++ program. + +## What is C++? + +- C++ is a high-level, general-purpose programming language. +- It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, and templates. +- C++ is designed for system programming, application development, game development, and more. +- It is a statically typed language, which means that variable types are checked at compile time. +- C++ supports both procedural programming and object-oriented programming paradigms. +- C++ code is typically compiled into machine code for execution. + +## Features of C++ + +- **Object-Oriented**: C++ is an object-oriented programming language. It supports the concepts of classes and objects, inheritance, polymorphism, and encapsulation. +- **Statically Typed**: C++ is a statically typed language, which means that variable types are checked at compile time. +- **Compiled Language**: C++ code is compiled into machine code for execution, which can result in high performance. +- **Portable**: C++ code can be compiled and executed on different platforms, making it portable. +- **Memory Management**: C++ allows manual memory management using pointers, which gives developers more control over memory allocation and deallocation. +- **Standard Library**: C++ provides a rich standard library that includes data structures, algorithms, input/output functions, and more. +- **Compatibility with C**: C++ is compatible with C code, allowing developers to use existing C libraries and code in C++ programs. + +## Applications of C++ + +C++ is used in a wide range of applications, including: + +- **System Software**: C++ is used to develop system software such as operating systems, device drivers, and firmware. +- **Application Software**: C++ is used to develop application software such as desktop applications, business applications, and productivity tools. +- **Game Development**: C++ is widely used in game development. It is used to build game engines, game logic, and graphics rendering. +- **Embedded Systems**: C++ is used in embedded systems development. It is used to build embedded software for devices such as microcontrollers, IoT devices, and automotive systems. +- **High-Performance Computing**: C++ is used in high-performance computing (HPC) applications such as scientific computing, simulations, and data analysis. +- **Graphics Programming**: C++ is used in graphics programming. It is used to develop graphics libraries, rendering engines, and graphical user interfaces (GUIs). +- **Financial Applications**: C++ is used in financial applications such as trading systems, risk management software, and financial modeling tools. +- **Compiler Development**: C++ is used to develop compilers, interpreters, and language tools for other programming languages. +- **Networking**: C++ is used in networking applications such as network protocols, servers, and communication software. +- **Artificial Intelligence**: C++ is used in artificial intelligence (AI) applications such as machine learning algorithms, neural networks, and AI research. +- **Multimedia Applications**: C++ is used in multimedia applications such as audio/video processing, image processing, and media players. + +## Conclusion + +C++ is a powerful and versatile programming language that is widely used in various domains. It combines the features of procedural programming with object-oriented programming, making it suitable for a wide range of applications. Whether you are a beginner or an experienced developer, learning C++ can open up opportunities to work on exciting projects and technologies. In this tutorial, you will learn the basics of C++ programming and how to get started with C++ development. Let's dive in! diff --git a/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md b/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md index 31aadab51..b4deb4829 100644 --- a/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md +++ b/docs/cpp/introduction-to-cpp/setting-up-your-cpp-environment.md @@ -5,4 +5,45 @@ sidebar_label: Setup C++ Development Environment sidebar_position: 3 tags: [c++, setup c++ development environment] description: In this tutorial, you will walk through all the steps of setting up a C++ development environment on your local computer. ---- \ No newline at end of file +--- + +# Setting Up a C++ Environment + +## Introduction + +Before you can start programming in C++, you need to set up your development environment. This typically involves installing the necessary software and configuring your system to compile and run C++ code. + +## Steps to Set Up C++ Environment + +1. **Install a C++ Compiler**: + + - For Windows, you can install MinGW or Microsoft Visual C++ Compiler. + - For macOS, you can install Xcode Command Line Tools or use Homebrew to install GCC. + - For Linux, you can use your package manager to install GCC or Clang. + +2. **Choose a Text Editor or Integrated Development Environment (IDE)**: + + - Choose a text editor like Visual Studio Code, Sublime Text, or Atom, or an IDE like Visual Studio or CLion for C++ development. + - Download and install the chosen editor or IDE from their official websites. + +3. **Set Up Compiler and Build Tools**: + + - If using an IDE, configure it to use the installed C++ compiler (e.g., GCC or Clang). + - For text editors, install C++ language support extensions or plugins for syntax highlighting and code completion. + +4. **Install C++ Libraries and Frameworks** (Optional but recommended): + + - Depending on your project requirements, install any necessary C++ libraries or frameworks like Boost, Qt, or OpenGL. + - Configure your development environment to include these libraries in your project. + +5. **Verify Installation**: + + - Open a terminal or command prompt and type `g++ --version` (for GCC) or `clang++ --version` (for Clang) to verify that the C++ compiler is installed and accessible. + +6. **Set Up Environment Variables** (Optional but recommended): + + - Set up environment variables such as `PATH` to include the directory containing the C++ compiler and build tools, allowing you to run C++ commands from any directory in the terminal or command prompt. + +## Conclusion + +Setting up a C++ environment is crucial for C++ developers to compile, run, and manage C++ applications effectively. By following these steps and choosing the right tools for your needs, you can create a well-configured development environment that enhances your productivity and workflow when working with C++ code. diff --git a/docs/cpp/introduction-to-cpp/what-is-cpp.md b/docs/cpp/introduction-to-cpp/what-is-cpp.md index 9d595be6f..585f7e029 100644 --- a/docs/cpp/introduction-to-cpp/what-is-cpp.md +++ b/docs/cpp/introduction-to-cpp/what-is-cpp.md @@ -5,4 +5,43 @@ sidebar_label: What is C++? sidebar_position: 1 tags: [c++, what is c++, introduction to c++] description: In this tutorial, you will learn about the C++ programming language, what it is, its features, and its applications. ---- \ No newline at end of file +--- + +# Introduction to C++ + +## What is C++? + +C++ is a powerful and widely-used programming language known for its versatility, performance, and extensive feature set. It is an extension of the C programming language with additional features such as classes and objects, inheritance, polymorphism, templates, and more. C++ is designed for system programming, application development, game development, and other domains. + +## Key Features of C++ + +- **Object-Oriented**: C++ is an object-oriented programming (OOP) language, allowing developers to create classes and objects that encapsulate data and behavior. +- **Statically Typed**: C++ is a statically typed language, meaning that variable types are checked at compile time for type safety. +- **Compiled Language**: C++ code is compiled into machine code for execution, resulting in high performance and efficiency. +- **Memory Management**: C++ allows manual memory management using pointers, giving developers control over memory allocation and deallocation. +- **Standard Library**: C++ provides a rich standard library with data structures, algorithms, input/output functions, and more, facilitating software development. +- **Compatibility with C**: C++ is compatible with C code, allowing developers to use existing C libraries and code in C++ programs. + +## C++ Development Ecosystem + +C++ has a comprehensive development ecosystem comprising various tools, libraries, and frameworks: + +- **Integrated Development Environments (IDEs)**: Popular IDEs for C++ development include Visual Studio, Code::Blocks, and CLion, offering features like code completion, debugging, and project management. + +- **Libraries and Frameworks**: C++ has numerous libraries and frameworks for different purposes, such as Boost for general-purpose programming, Qt for GUI development, and OpenGL for graphics programming. + +- **Community Support**: C++ has a vibrant community of developers who contribute to open-source projects, share knowledge through forums and blogs, and provide support to fellow developers. + +## C++ Editions + +C++ has evolved over time, leading to different editions tailored for specific platforms and use cases: + +- **Standard C++**: Also known as ISO C++, this is the standardized version of the language maintained by the International Organization for Standardization (ISO). + +- **C++11, C++14, C++17, C++20**: These are versions of the language that introduce new features and improvements, enhancing productivity and code quality. + +- **Embedded C++ (EC++)**: Optimized for embedded systems development, EC++ focuses on efficiency, low-level programming, and resource-constrained environments. + +## Conclusion + +C++ continues to be a preferred choice for developers due to its versatility, performance, and extensive ecosystem. Whether you are building system software, applications, games, or embedded systems, C++ offers the tools and capabilities to meet diverse development needs. Its object-oriented nature, strong memory management, and compatibility with C make it a robust and reliable language for a wide range of projects. diff --git a/docs/cpp/introduction-to-cpp/why-learn-cpp.md b/docs/cpp/introduction-to-cpp/why-learn-cpp.md index 7a1db0850..9e530479b 100644 --- a/docs/cpp/introduction-to-cpp/why-learn-cpp.md +++ b/docs/cpp/introduction-to-cpp/why-learn-cpp.md @@ -5,4 +5,30 @@ sidebar_label: Why Learn C++? sidebar_position: 2 tags: [c++, why learn c++] description: In this tutorial, you will learn about the many applications of the C++ programming language and the benefits of learning it. ---- \ No newline at end of file +--- + +# Why Learn C++? + +## Introduction + +C++ is a powerful and widely-used programming language with numerous advantages that make it a valuable skill for developers. + +## Reasons to Learn C++ + +- **Versatility**: C++ is a versatile language used in system programming, game development, high-performance applications, embedded systems, and more. Learning C++ opens doors to diverse career opportunities. + +- **Performance**: C++ is known for its high performance and efficiency, making it suitable for applications that require speed and resource optimization, such as real-time systems, simulations, and games. + +- **Compatibility with C**: C++ is compatible with C code, allowing developers to leverage existing C libraries and code in C++ programs. This compatibility enhances code reusability and integration. + +- **Object-Oriented Programming (OOP)**: C++ is an object-oriented programming language, emphasizing concepts like classes, objects, inheritance, and polymorphism. Learning C++ helps developers master OOP principles, which are fundamental in modern software development. + +- **Memory Management**: C++ offers manual memory management through pointers, giving developers fine-grained control over memory allocation and deallocation. This level of control is beneficial for optimizing resource usage and performance. + +- **Strong Community and Resources**: C++ has a robust community of developers, forums, libraries, and frameworks that provide support, resources, and tools for C++ development. Being part of this community can enhance your learning experience and accelerate your growth as a developer. + +- **Industry Demand**: C++ developers are in demand across various industries, including finance, gaming, automotive, aerospace, and technology. Learning C++ increases your marketability and opens doors to exciting career opportunities. + +## Conclusion + +Whether you're interested in system programming, game development, high-performance computing, or embedded systems, learning C++ offers numerous benefits. Its versatility, performance, compatibility with C, strong community support, and industry demand make it a valuable language to learn and master in today's competitive software development landscape.