diff --git a/courses/C++ /advance-Level/Advance-File-Handling/File-locking.md b/courses/C++ /advance-Level/Advance-File-Handling/File-locking.md new file mode 100644 index 000000000..5defce48c --- /dev/null +++ b/courses/C++ /advance-Level/Advance-File-Handling/File-locking.md @@ -0,0 +1,105 @@ +--- +id: lesson-1 +title: "Advanced File Handling in C++" +sidebar_label: Advanced File Handling +sidebar_position: 1 +description: "Learn Advanced File Handling in C++" +tags: [courses,Advance-level,Introduction] +--- + + +Advanced file handling techniques allow for better control, performance optimization, and handling of large files. Let's explore these techniques: + +### Flowchart + +```mermaid +graph TD; + A[Start] --> B[File Locking Mechanisms]; + B --> C[File I/O Performance Optimization]; + C --> D[Handling Large Files]; + D --> E[Working with Memory-Mapped Files]; + E --> F[End]; +``` + +#### 1. File Locking Mechanisms + +File locking prevents simultaneous access to a file, which can cause data corruption. It ensures that only one process can write to a file at a time. + +##### Example: File Locking with `fcntl` + +```cpp +#include +#include +#include + +int main() { + int fd = open("example.txt", O_RDWR | O_CREAT, 0666); + if (fd == -1) { + std::cerr << "Failed to open file" << std::endl; + return 1; + } + + struct flock lock; + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 0; // Lock the whole file + + if (fcntl(fd, F_SETLK, &lock) == -1) { + std::cerr << "Failed to lock file" << std::endl; + close(fd); + return 1; + } + + std::cout << "File locked. Press Enter to unlock..." << std::endl; + std::cin.get(); + + lock.l_type = F_UNLCK; + if (fcntl(fd, F_SETLK, &lock) == -1) { + std::cerr << "Failed to unlock file" << std::endl; + } + + close(fd); + return 0; +} +``` + +#### 2. File I/O Performance Optimization + +Optimizing file I/O can significantly improve performance, especially when dealing with large files or high-frequency I/O operations. + +:::tip +- **Buffering**: Use buffered I/O for efficient data handling. +- **Asynchronous I/O**: Perform non-blocking I/O operations to avoid waiting for I/O completion. +- **Memory Mapping**: Use memory-mapped files for direct memory access to file contents. +::: + +#### 3. Handling Large Files + +Handling large files efficiently is crucial for applications that deal with massive datasets. + +##### Example: Reading Large Files in Chunks + +```cpp +#include +#include + +int main() { + std::ifstream file("largefile.txt", std::ios::in | std::ios::binary); + if (!file) { + std::cerr << "Failed to open file" << std::endl; + return 1; + } + + const size_t bufferSize = 1024 * 1024; // 1 MB buffer + char buffer[bufferSize]; + + while (file.read(buffer, bufferSize) || file.gcount() > 0) { + // Process buffer contents + std::cout.write(buffer, file.gcount()); + } + + file.close(); + return 0; +} +``` diff --git a/courses/C++ /advance-Level/Advance-File-Handling/_category_.json b/courses/C++ /advance-Level/Advance-File-Handling/_category_.json new file mode 100644 index 000000000..997a62e33 --- /dev/null +++ b/courses/C++ /advance-Level/Advance-File-Handling/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Advance File Handling", + "position": 5, + "link": { + "type": "generated-index", + "description": "Learn Advance File Handling." + } + } \ No newline at end of file diff --git a/courses/C++ /advance-Level/Advance-File-Handling/memory-mapped.md b/courses/C++ /advance-Level/Advance-File-Handling/memory-mapped.md new file mode 100644 index 000000000..a842f5d5f --- /dev/null +++ b/courses/C++ /advance-Level/Advance-File-Handling/memory-mapped.md @@ -0,0 +1,62 @@ +--- +id: lesson-2 +title: "Working with Memory-Mapped Files" +sidebar_label: Working with Memory-Mapped Files +sidebar_position: 2 +description: "Learn Working with Memory-Mapped Files" +tags: [courses,Advance-level,Introduction] +--- + + +Memory-mapped files allow for efficient file access by mapping a file's contents to memory. This technique is useful for large files and random access patterns. + +##### Example: Memory-Mapped File Access + +```cpp +#include +#include +#include +#include +#include + +int main() { + int fd = open("largefile.txt", O_RDONLY); + if (fd == -1) { + std::cerr << "Failed to open file" << std::endl; + return 1; + } + + struct stat sb; + if (fstat(fd, &sb) == -1) { + std::cerr << "Failed to get file size" << std::endl; + close(fd); + return 1; + } + + size_t fileSize = sb.st_size; + char *mapped = static_cast(mmap(NULL, fileSize, PROT_READ, MAP_PRIVATE, fd, 0)); + if (mapped == MAP_FAILED) { + std::cerr << "Failed to map file" << std::endl; + close(fd); + return 1; + } + + // Access the file content through the mapped memory + std::cout.write(mapped, fileSize); + + if (munmap(mapped, fileSize) == -1) { + std::cerr << "Failed to unmap file" << std::endl; + } + + close(fd); + return 0; +} +``` +:::tip +- **File Locking**: Use file locking mechanisms to prevent concurrent write operations. +- **Buffered I/O**: Implement buffering to reduce the number of I/O operations. +- **Asynchronous I/O**: Utilize asynchronous I/O for non-blocking operations. +- **Memory Mapping**: Use memory-mapped files for efficient access to large files. +::: + + diff --git a/courses/C++ /advance-Level/Advanced-Memory-Allocation/_category_.json b/courses/C++ /advance-Level/Advanced-Memory-Allocation/_category_.json new file mode 100644 index 000000000..fb535db55 --- /dev/null +++ b/courses/C++ /advance-Level/Advanced-Memory-Allocation/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Advanced Memory Allocation", + "position": 2, + "link": { + "type": "generated-index", + "description": "Learn Advanced Memory Allocation." + } + } \ No newline at end of file diff --git a/courses/C++ /advance-Level/Advanced-Memory-Allocation/custom-allocators.md b/courses/C++ /advance-Level/Advanced-Memory-Allocation/custom-allocators.md new file mode 100644 index 000000000..2a35cba19 --- /dev/null +++ b/courses/C++ /advance-Level/Advanced-Memory-Allocation/custom-allocators.md @@ -0,0 +1,98 @@ +--- +id: lesson-2 +title: "Custom Allocators" +sidebar_label: Custom Allocators +sidebar_position: 2 +description: "Learn Custom Allocators" +tags: [courses,Advance-level,Introduction] +--- + +**Custom Allocators**: Custom allocators provide control over memory allocation strategies and can be used to optimize memory usage for specific applications. + +##### Example: Custom Allocator + +```cpp +#include +#include +#include + +template +class CustomAllocator : public std::allocator { +public: + typedef T value_type; + + T* allocate(std::size_t n) { + std::cout << "Allocating " << n << " elements." << std::endl; + return std::allocator::allocate(n); + } + + void deallocate(T* p, std::size_t n) { + std::cout << "Deallocating " << n << " elements." << std::endl; + std::allocator::deallocate(p, n); + } +}; + +int main() { + std::vector> vec; + vec.push_back(1); + vec.push_back(2); + vec.push_back(3); + + std::cout << "Vector size: " << vec.size() << std::endl; + return 0; +} +``` + +**Output:** +``` +Allocating 1 elements. +Allocating 1 elements. +Allocating 1 elements. +Vector size: 3 +Deallocating 1 elements. +Deallocating 1 elements. +Deallocating 1 elements. +``` + +### Memory Alignment and Padding + +**Memory Alignment and Padding**: Memory alignment refers to arranging data in memory to meet certain hardware requirements. Padding is used to align data structures in memory. + +##### Example: Memory Alignment + +```cpp +#include +#include // For offsetof + +struct AlignedStruct { + char a; + int b; + double c; +}; + +int main() { + std::cout << "Size of AlignedStruct: " << sizeof(AlignedStruct) << std::endl; + std::cout << "Offset of 'a': " << offsetof(AlignedStruct, a) << std::endl; + std::cout << "Offset of 'b': " << offsetof(AlignedStruct, b) << std::endl; + std::cout << "Offset of 'c': " << offsetof(AlignedStruct, c) << std::endl; + + return 0; +} +``` + +**Output:** +``` +Size of AlignedStruct: 16 +Offset of 'a': 0 +Offset of 'b': 4 +Offset of 'c': 8 +``` + + + +:::tip +- **Memory Pools**: Useful for scenarios with frequent allocation and deallocation. They reduce fragmentation and improve performance. +- **Smart Pointers**: Prefer using `unique_ptr` for single ownership, `shared_ptr` for shared ownership, and `weak_ptr` for non-owning references. +- **Custom Allocators**: Utilize custom allocators for specialized memory management needs, especially in performance-critical applications. +- **Memory Alignment**: Ensure data structures are aligned properly to meet hardware requirements and avoid performance penalties. +::: \ No newline at end of file diff --git a/courses/C++ /advance-Level/Advanced-Memory-Allocation/memory-pools.md b/courses/C++ /advance-Level/Advanced-Memory-Allocation/memory-pools.md new file mode 100644 index 000000000..7224d45b2 --- /dev/null +++ b/courses/C++ /advance-Level/Advanced-Memory-Allocation/memory-pools.md @@ -0,0 +1,148 @@ +--- +id: lesson-1 +title: "Advanced Memory Management in C++" +sidebar_label: Advanced Memory Management +sidebar_position: 1 +description: "Learn Advanced Memory Management in C++" +tags: [courses,Advance-level,Introduction] +--- + +Advanced memory management techniques in C++ can significantly improve the efficiency and safety of memory usage in your applications. Key topics include memory pools, smart pointers, custom allocators, and memory alignment. + +### Flowchart + +```mermaid +graph TD; + A[Start] --> B[Memory Pools]; + B --> C[Pre-allocate Memory Blocks]; + C --> D[Efficient Memory Allocation]; + D --> E[Smart Pointers]; + E --> F[unique_ptr]; + E --> G[shared_ptr]; + E --> H[weak_ptr]; + F --> I[Automatic Memory Management]; + G --> I; + H --> I; + I --> J[Custom Allocators]; + J --> K[Custom Allocation Strategies]; + K --> L[Control Over Memory Usage]; + L --> M[Memory Alignment and Padding]; + M --> N[Data Alignment]; + M --> O[Padding for Alignment]; + N --> P[End]; + O --> P; +``` + +#### 1. Memory Pools + +**Memory Pools**: A memory pool is a collection of pre-allocated memory blocks that are used to manage memory more efficiently. They are useful when you need to allocate and deallocate memory frequently. + +##### Example: Memory Pool + +```cpp +#include +#include + +class MemoryPool { + std::vector pool; + size_t blockSize; + size_t poolSize; + +public: + MemoryPool(size_t blockSize, size_t poolSize) + : blockSize(blockSize), poolSize(poolSize) { + pool.reserve(poolSize); + for (size_t i = 0; i < poolSize; ++i) { + pool.push_back(::operator new(blockSize)); + } + } + + ~MemoryPool() { + for (void* block : pool) { + ::operator delete(block); + } + } + + void* allocate() { + if (pool.empty()) { + throw std::bad_alloc(); + } + void* block = pool.back(); + pool.pop_back(); + return block; + } + + void deallocate(void* block) { + pool.push_back(block); + } +}; + +int main() { + MemoryPool mp(128, 10); // Block size of 128 bytes, 10 blocks + + void* ptr1 = mp.allocate(); + void* ptr2 = mp.allocate(); + + mp.deallocate(ptr1); + mp.deallocate(ptr2); + + std::cout << "Memory pool operations completed." << std::endl; + return 0; +} +``` + +**Output:** +``` +Memory pool operations completed. +``` + +#### 2. Smart Pointers + +**Smart Pointers**: Smart pointers manage the lifetime of dynamically allocated objects and automatically deallocate memory when it is no longer needed. The three main types are `unique_ptr`, `shared_ptr`, and `weak_ptr`. + +##### Example: Smart Pointers + +```cpp +#include +#include +#include + +class MyClass { +public: + MyClass() { std::cout << "MyClass constructed." << std::endl; } + ~MyClass() { std::cout << "MyClass destructed." << std::endl; } + void hello() { std::cout << "Hello, world!" << std::endl; } +}; + +int main() { + // unique_ptr example + std::unique_ptr uptr1(new MyClass()); + uptr1->hello(); + + // shared_ptr example + std::shared_ptr sptr1 = std::make_shared(); + std::shared_ptr sptr2 = sptr1; + sptr1->hello(); + + // weak_ptr example + std::weak_ptr wptr = sptr1; + if (auto sptr3 = wptr.lock()) { + sptr3->hello(); + } + + return 0; +} +``` + +**Output:** +``` +MyClass constructed. +Hello, world! +MyClass constructed. +Hello, world! +MyClass constructed. +Hello, world! +MyClass destructed. +MyClass destructed. +MyClass destructed. +``` diff --git a/courses/C++ /advance-Level/Advanced-OOPS/RTTI.md b/courses/C++ /advance-Level/Advanced-OOPS/RTTI.md new file mode 100644 index 000000000..b902c6770 --- /dev/null +++ b/courses/C++ /advance-Level/Advanced-OOPS/RTTI.md @@ -0,0 +1,52 @@ +--- +id: lesson-2 +title: "RTTI (Run-Time Type Information)" +sidebar_label: RTTI +sidebar_position: 2 +description: "Learn RTTI (Run-Time Type Information)" +tags: [courses,Advance-level,Introduction] +--- + + + +**RTTI**: Run-Time Type Information allows the type of an object to be determined during program execution. It provides mechanisms for safe downcasting and type checking. + +##### Example: RTTI + +```cpp +#include +#include +using namespace std; + +class Base { +public: + virtual ~Base() {} +}; + +class Derived : public Base {}; + +int main() { + Base* b = new Derived(); + + if (typeid(*b) == typeid(Derived)) { + cout << "b is of type Derived" << endl; + } else { + cout << "b is not of type Derived" << endl; + } + + delete b; + return 0; +} +``` + +**Output:** +``` +b is of type Derived +``` + +:::tip +- **Abstract Classes**: Use abstract classes to define a common interface and enforce implementation in derived classes. +- **Multiple Inheritance**: While useful, be cautious of the complexities and ambiguities it may introduce. +- **Virtual Inheritance**: Utilize virtual inheritance to prevent multiple instances of a base class in complex inheritance hierarchies. +- **RTTI**: Use RTTI for safe type identification and downcasting, but avoid overusing it as it can impact performance. +::: \ No newline at end of file diff --git a/courses/C++ /advance-Level/Advanced-OOPS/_category_.json b/courses/C++ /advance-Level/Advanced-OOPS/_category_.json new file mode 100644 index 000000000..8b11e7c82 --- /dev/null +++ b/courses/C++ /advance-Level/Advanced-OOPS/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Advanced OOPS concept", + "position": 1, + "link": { + "type": "generated-index", + "description": "Learn Advanced OOPS Techniques." + } + } \ No newline at end of file diff --git a/courses/C++ /advance-Level/Advanced-OOPS/inheritance.md b/courses/C++ /advance-Level/Advanced-OOPS/inheritance.md new file mode 100644 index 000000000..fb29611e1 --- /dev/null +++ b/courses/C++ /advance-Level/Advanced-OOPS/inheritance.md @@ -0,0 +1,167 @@ +--- +id: lesson-1 +title: "Advanced OOP Concepts in C++" +sidebar_label: Inheritance +sidebar_position: 1 +description: "Learn Advanced OOP Concepts in C++" +tags: [courses,Advance-level,Introduction] +--- + +Advanced Object-Oriented Programming (OOP) concepts in C++ enhance the flexibility and functionality of your code. These include abstract classes, interfaces, multiple inheritance, virtual inheritance, and run-time type information (RTTI). + +### Diagram + +```mermaid +graph TD; + A[Start] --> B[Abstract Classes]; + B --> C[Define Pure Virtual Functions]; + C --> D[Implement in Derived Classes]; + D --> E[Multiple Inheritance]; + E --> F[Inherit from Multiple Classes]; + F --> G[Virtual Inheritance]; + G --> H[Resolve Diamond Problem]; + H --> I[RTTI]; + I --> J[Use typeid and dynamic_cast]; + J --> K[End]; +``` + +#### 1. Abstract Classes and Interfaces + +**Abstract Classes**: An abstract class is a class that cannot be instantiated and is used to define a common interface for derived classes. It can contain pure virtual functions, which must be implemented by derived classes. + +**Interfaces**: In C++, an interface is typically represented by an abstract class that only contains pure virtual functions. + +##### Example: Abstract Class and Interface + +```cpp +#include +using namespace std; + +// Abstract class with pure virtual function +class Shape { +public: + virtual void draw() const = 0; // Pure virtual function +}; + +// Derived class implementing the pure virtual function +class Circle : public Shape { +public: + void draw() const override { + cout << "Drawing a Circle" << endl; + } +}; + +int main() { + Circle c; + c.draw(); // Output: Drawing a Circle + return 0; +} +``` + +**Output:** +``` +Drawing a Circle +``` + +#### 2. Multiple Inheritance + +**Multiple Inheritance**: This is a feature where a class can inherit from more than one base class. While powerful, it can lead to complexity and ambiguity if not handled carefully. + +##### Example: Multiple Inheritance + +```cpp +#include +using namespace std; + +class A { +public: + void showA() { + cout << "Class A" << endl; + } +}; + +class B { +public: + void showB() { + cout << "Class B" << endl; + } +}; + +class C : public A, public B { +public: + void showC() { + cout << "Class C" << endl; + } +}; + +int main() { + C obj; + obj.showA(); // Output: Class A + obj.showB(); // Output: Class B + obj.showC(); // Output: Class C + return 0; +} +``` + +**Output:** +``` +Class A +Class B +Class C +``` + +#### 3. Virtual Inheritance + +**Virtual Inheritance**: Virtual inheritance is used to solve the diamond problem in multiple inheritance scenarios. It ensures that only one instance of the base class is inherited. + +##### Example: Virtual Inheritance + +```cpp +#include +using namespace std; + +class A { +public: + void showA() { + cout << "Class A" << endl; + } +}; + +class B : virtual public A { +public: + void showB() { + cout << "Class B" << endl; + } +}; + +class C : virtual public A { +public: + void showC() { + cout << "Class C" << endl; + } +}; + +class D : public B, public C { +public: + void showD() { + cout << "Class D" << endl; + } +}; + +int main() { + D obj; + obj.showA(); // Output: Class A + obj.showB(); // Output: Class B + obj.showC(); // Output: Class C + obj.showD(); // Output: Class D + return 0; +} +``` + +**Output:** +``` +Class A +Class B +Class C +Class D +``` \ No newline at end of file diff --git a/courses/C++ /advance-Level/Multithreading/Deadlocks.md b/courses/C++ /advance-Level/Multithreading/Deadlocks.md new file mode 100644 index 000000000..286c70111 --- /dev/null +++ b/courses/C++ /advance-Level/Multithreading/Deadlocks.md @@ -0,0 +1,71 @@ +--- +id: lesson-2 +title: "Deadlocks" +sidebar_label: Deadlocks +sidebar_position: 2 +description: "Learn Deadlocks in C++" +tags: [courses,Advance-level,Introduction] +--- + + +#### Avoiding Race Conditions and Deadlocks + +**Race Conditions** occur when multiple threads access shared resources concurrently without proper synchronization, leading to unpredictable results. + +**Deadlocks** occur when two or more threads are waiting for each other to release resources, causing a standstill. + +##### Tips to Avoid Race Conditions: +- Use mutexes or other synchronization primitives to protect shared resources. +- Minimize the scope of locks to reduce contention. + +##### Tips to Avoid Deadlocks: +- Always lock resources in the same order. +- Use timeout-based locking to detect potential deadlocks. + +##### Example: Avoiding Deadlock + +```cpp +#include +#include +#include + +std::mutex mtx1, mtx2; + +void task1() { + std::lock(mtx1, mtx2); + std::lock_guard lg1(mtx1, std::adopt_lock); + std::lock_guard lg2(mtx2, std::adopt_lock); + std::cout << "Task 1 completed." << std::endl; +} + +void task2() { + std::lock(mtx1, mtx2); + std::lock_guard lg1(mtx1, std::adopt_lock); + std::lock_guard lg2(mtx2, std::adopt_lock); + std::cout << "Task 2 completed." << std::endl; +} + +int main() { + std::thread t1(task1); + std::thread t2(task2); + + t1.join(); + t2.join(); + + return 0; +} +``` + +**Output:** +``` +Task 1 completed. +Task 2 completed. +``` + + +:::tip +- **Thread Management**: Ensure threads are properly managed using `join()` to avoid detaching issues. +- **Synchronization**: Use the appropriate synchronization primitive based on your needs (e.g., `mutex`, `condition_variable`). +- **Avoid Race Conditions**: Always protect shared resources with locks. +- **Avoid Deadlocks**: Lock resources in a consistent order and use timeout mechanisms when appropriate. +::: \ No newline at end of file diff --git a/courses/C++ /advance-Level/Multithreading/Introduction.md b/courses/C++ /advance-Level/Multithreading/Introduction.md new file mode 100644 index 000000000..87f16b58c --- /dev/null +++ b/courses/C++ /advance-Level/Multithreading/Introduction.md @@ -0,0 +1,141 @@ +--- +id: lesson-2 +title: "Multithreading and Concurrency in C++" +sidebar_label: Multithreading and Concurrency +sidebar_position: 2 +description: "Learn Multithreading and Concurrency in C++" +tags: [courses,Advance-level,Introduction] +--- + + +Multithreading allows a program to perform multiple operations concurrently, which can lead to improved performance and responsiveness. In C++, multithreading is primarily handled through the `` library, and synchronization between threads is managed using various synchronization primitives. + +#### 1. Introduction to Multithreading + +**Multithreading** involves dividing a program into multiple threads, each performing its own task. Threads share the same process space but operate independently, which can lead to more efficient CPU usage. + +### Flowchart + +```mermaid +graph TD; + A[Start] --> B[Create Threads]; + B --> C[Manage Threads]; + C --> D[Synchronize Threads]; + D --> E[Thread Communication]; + E --> F[Avoid Race Conditions]; + F --> G[Avoid Deadlocks]; + G --> H[End]; +``` + + +#### 2. Creating and Managing Threads + +Threads in C++ can be created using the `` library. Each thread executes a function or callable object. + +##### Example: Creating and Managing Threads + +```cpp +#include +#include + +void printHello() { + std::cout << "Hello from thread!" << std::endl; +} + +int main() { + std::thread t1(printHello); // Create and start a thread + t1.join(); // Wait for the thread to finish + + std::cout << "Hello from main!" << std::endl; + return 0; +} +``` + +**Output:** +``` +Hello from thread! +Hello from main! +``` + +#### 3. Synchronization Techniques + +**Synchronization** is crucial for managing access to shared resources and preventing data races. Common synchronization techniques include mutexes and semaphores. + +##### Example: Using Mutexes + +```cpp +#include +#include +#include + +std::mutex mtx; // Mutex for synchronization +int counter = 0; + +void increment() { + std::lock_guard lock(mtx); // Lock mutex + ++counter; + std::cout << "Counter: " << counter << std::endl; +} + +int main() { + std::thread t1(increment); + std::thread t2(increment); + + t1.join(); + t2.join(); + + return 0; +} +``` + +**Output:** +``` +Counter: 1 +Counter: 2 +``` + +#### 4. Thread Communication + +**Thread Communication** allows threads to coordinate their actions. This can be achieved using condition variables. + +##### Example: Using Condition Variables + +```cpp +#include +#include +#include +#include + +std::mutex mtx; +std::condition_variable cv; +bool ready = false; + +void waitForReady() { + std::unique_lock lock(mtx); + cv.wait(lock, []{ return ready; }); + std::cout << "Thread proceeding!" << std::endl; +} + +void signalReady() { + { + std::lock_guard lock(mtx); + ready = true; + } + cv.notify_one(); +} + +int main() { + std::thread t1(waitForReady); + std::thread t2(signalReady); + + t1.join(); + t2.join(); + + return 0; +} +``` + +**Output:** +``` +Thread proceeding! +``` \ No newline at end of file diff --git a/courses/C++ /advance-Level/Multithreading/_category_.json b/courses/C++ /advance-Level/Multithreading/_category_.json new file mode 100644 index 000000000..ba8174134 --- /dev/null +++ b/courses/C++ /advance-Level/Multithreading/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Multithreading and Concurrency", + "position": 3, + "link": { + "type": "generated-index", + "description": "Learn Multithreading and Concurrency." + } + } \ No newline at end of file diff --git a/courses/C++ /advance-Level/Network/Introduction.md b/courses/C++ /advance-Level/Network/Introduction.md new file mode 100644 index 000000000..4d793a49c --- /dev/null +++ b/courses/C++ /advance-Level/Network/Introduction.md @@ -0,0 +1,32 @@ +--- +id: lesson-1 +title: "Network Programming in C++" +sidebar_label: Network Programming +sidebar_position: 1 +description: "Learn Network Programming in C++" +tags: [courses,Advance-level,Introduction] +--- + + +Network programming involves writing programs that communicate over a network, typically using sockets. Sockets provide a way for programs to exchange data, either locally on the same machine or over a network. + +#### 1. Introduction to Network Programming + +**Network Programming** allows computers to communicate over a network. It is essential for developing applications like web browsers, email clients, and chat applications. + +#### 2. Sockets and Socket Programming + +**Sockets** are endpoints for sending and receiving data. They can use various protocols, but the most common ones are TCP (Transmission Control Protocol) and UDP (User Datagram Protocol). + +##### Types of Sockets: +- **Stream Sockets (TCP)**: Provide reliable, connection-oriented communication. +- **Datagram Sockets (UDP)**: Provide connectionless, unreliable communication. + +#### 3. Client-Server Model + +The **Client-Server Model** is a common design pattern in network programming. The server provides services, and the client consumes these services. + +##### Example Workflow: +1. **Server**: Listens for incoming connections. +2. **Client**: Connects to the server. +3. **Client and Server**: Exchange data. diff --git a/courses/C++ /advance-Level/Network/TCP-IP.md b/courses/C++ /advance-Level/Network/TCP-IP.md new file mode 100644 index 000000000..f34250478 --- /dev/null +++ b/courses/C++ /advance-Level/Network/TCP-IP.md @@ -0,0 +1,155 @@ +--- +id: lesson-2 +title: "Basic TCP/IP Communication" +sidebar_label: TCP/IP Communication +sidebar_position: 2 +description: "Learn Basic TCP/IP Communication" +tags: [courses,Advance-level,Introduction] +--- + + + +TCP/IP is the fundamental communication protocol suite for the internet. + +:::important +1. **Create a Socket**. +2. **Bind the Socket** (server only). +3. **Listen for Connections** (server only). +4. **Accept Connections** (server only). +5. **Connect to Server** (client only). +6. **Send and Receive Data**. +7. **Close the Socket**. +::: + +### Flowchart + +```mermaid +graph TD; + A[Start] --> B[Create Socket]; + B --> C[Bind Socket Server ]; + C --> D[Listen for Connections Server]; + D --> E[Accept Connections Server]; + E --> F[Connect to Server Client]; + F --> G[Send and Receive Data]; + G --> H[Close Socket]; + H --> I[End]; +``` +### Simple Network Applications + +Let's implement a simple TCP client-server application. + +##### Example + +```cpp +#include +#include +#include +#include +#include + +void handleClient(int clientSocket) { + char buffer[1024]; + std::string message = "Hello from server!"; + send(clientSocket, message.c_str(), message.size(), 0); + + int bytesRead = read(clientSocket, buffer, 1024); + if (bytesRead > 0) { + std::cout << "Received from client: " << buffer << std::endl; + } + close(clientSocket); +} + +int main() { + int serverSocket = socket(AF_INET, SOCK_STREAM, 0); + if (serverSocket == -1) { + std::cerr << "Failed to create socket" << std::endl; + return -1; + } + + sockaddr_in serverAddr; + serverAddr.sin_family = AF_INET; + serverAddr.sin_port = htons(8080); + serverAddr.sin_addr.s_addr = INADDR_ANY; + + if (bind(serverSocket, (struct sockaddr*)&serverAddr, sizeof(serverAddr)) == -1) { + std::cerr << "Bind failed" << std::endl; + return -1; + } + + if (listen(serverSocket, 5) == -1) { + std::cerr << "Listen failed" << std::endl; + return -1; + } + + std::cout << "Server is listening on port 8080" << std::endl; + + while (true) { + int clientSocket = accept(serverSocket, nullptr, nullptr); + if (clientSocket == -1) { + std::cerr << "Accept failed" << std::endl; + continue; + } + std::thread(handleClient, clientSocket).detach(); + } + + close(serverSocket); + return 0; +} +``` + +##### Example + +```cpp +#include +#include +#include + +int main() { + int clientSocket = socket(AF_INET, SOCK_STREAM, 0); + if (clientSocket == -1) { + std::cerr << "Failed to create socket" << std::endl; + return -1; + } + + sockaddr_in serverAddr; + serverAddr.sin_family = AF_INET; + serverAddr.sin_port = htons(8080); + inet_pton(AF_INET, "127.0.0.1", &serverAddr.sin_addr); + + if (connect(clientSocket, (struct sockaddr*)&serverAddr, sizeof(serverAddr)) == -1) { + std::cerr << "Connect failed" << std::endl; + return -1; + } + + char buffer[1024]; + int bytesRead = read(clientSocket, buffer, 1024); + if (bytesRead > 0) { + std::cout << "Received from server: " << buffer << std::endl; + } + + std::string message = "Hello from client!"; + send(clientSocket, message.c_str(), message.size(), 0); + + close(clientSocket); + return 0; +} +``` + +**Output:** +``` +Server is listening on port 8080 +Received from client: Hello from client! +``` + +**Client Output:** +``` +Received from server: Hello from server! +``` + + +:::tip +- **Socket Management**: Always close sockets to avoid resource leaks. +- **Error Handling**: Implement robust error handling for network operations. +- **Concurrency**: Use multithreading to handle multiple clients in server applications. +- **Data Encoding**: Ensure proper encoding and decoding of data sent over the network. +::: \ No newline at end of file diff --git a/courses/C++ /advance-Level/Network/_category_.json b/courses/C++ /advance-Level/Network/_category_.json new file mode 100644 index 000000000..d5c65116e --- /dev/null +++ b/courses/C++ /advance-Level/Network/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Network Programming", + "position": 4, + "link": { + "type": "generated-index", + "description": "Learn Network Programming." + } + } \ No newline at end of file diff --git a/courses/C++ /advance-Level/_category_.json b/courses/C++ /advance-Level/_category_.json new file mode 100644 index 000000000..3702575de --- /dev/null +++ b/courses/C++ /advance-Level/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Advanced Level", + "position": 4, + "link": { + "type": "generated-index", + "description": "Learn Advanced C++ Language Techniques." + } + } \ No newline at end of file diff --git a/courses/C++ /beginner-level/Array-and-strings/_category_.json b/courses/C++ /beginner-level/Array-and-strings/_category_.json new file mode 100644 index 000000000..86994c857 --- /dev/null +++ b/courses/C++ /beginner-level/Array-and-strings/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Array and Strings", + "position": 6, + "link": { + "type": "generated-index", + "description": "Array and Strings in C++ Language." + } + } \ No newline at end of file diff --git a/courses/C++ /beginner-level/Array-and-strings/intro.md b/courses/C++ /beginner-level/Array-and-strings/intro.md new file mode 100644 index 000000000..2818174dc --- /dev/null +++ b/courses/C++ /beginner-level/Array-and-strings/intro.md @@ -0,0 +1,96 @@ +--- +id: lesson-1 +title: "Introduction to Arrays" +sidebar_label: Arrays +sidebar_position: 1 +description: "Learn Array techniques" +tags: [courses,beginner-level,C++,Introduction] +--- + + +Arrays are collections of elements of the same type stored in contiguous memory locations. + +### Flowchart for Arrays and Strings +```mermaid +graph TD; + A[Start] --> B[Declare Array]; + B --> C[Initialize Array]; + C --> D{Single-Dimensional or Multidimensional?}; + D -- Single-Dimensional --> E[Access/Modify Elements]; + E --> F[Print Elements]; + F --> G[End]; + D -- Multidimensional --> H[Access/Modify Elements]; + H --> I[Print Elements]; + I --> G; + G --> J{String Handling}; + J -- Character Array --> K[Declare Char Array]; + K --> L[Access/Modify Elements]; + L --> M[Print Char Array]; + M --> G; + J -- String Class --> N[Include ]; + N --> O[Declare string Object]; + O --> P[Access/Modify Elements]; + P --> Q[Print String]; + Q --> G; +``` + +#### Single-Dimensional Arrays + +A single-dimensional array is a list of elements of the same type. + +#### Example +```cpp +#include +using namespace std; + +int main() { + int arr[5] = {1, 2, 3, 4, 5}; + + for(int i = 0; i < 5; i++) { + cout << "Element at index " << i << ": " << arr[i] << endl; + } + + return 0; +} +``` + +**Output:** +``` +Element at index 0: 1 +Element at index 1: 2 +Element at index 2: 3 +Element at index 3: 4 +Element at index 4: 5 +``` + +#### Multidimensional Arrays + +Multidimensional arrays are arrays of arrays. + +#### Example +```cpp +#include +using namespace std; + +int main() { + int matrix[2][3] = {{1, 2, 3}, {4, 5, 6}}; + + for(int i = 0; i < 2; i++) { + for(int j = 0; j < 3; j++) { + cout << "Element at [" << i << "][" << j << "]: " << matrix[i][j] << endl; + } + } + + return 0; +} +``` + +**Output:** +``` +Element at [0][0]: 1 +Element at [0][1]: 2 +Element at [0][2]: 3 +Element at [1][0]: 4 +Element at [1][1]: 5 +Element at [1][2]: 6 +``` \ No newline at end of file diff --git a/courses/C++ /beginner-level/Array-and-strings/string-handling.md b/courses/C++ /beginner-level/Array-and-strings/string-handling.md new file mode 100644 index 000000000..85d5a92c0 --- /dev/null +++ b/courses/C++ /beginner-level/Array-and-strings/string-handling.md @@ -0,0 +1,74 @@ +--- +id: lesson-2 +title: "String Handling and Manipulation" +sidebar_label: String +sidebar_position: 2 +description: "Learn String Handling and Manipulation" +tags: [courses,beginner-level,C++,Introduction] +--- + + + +Strings in C++ can be handled using character arrays or the `string` class from the Standard Library. + +#### Example with Character Arrays +```cpp +#include +using namespace std; + +int main() { + char str[] = "Hello, World!"; + cout << "String: " << str << endl; + + // Changing a character + str[7] = 'C'; + cout << "Modified String: " << str << endl; + + return 0; +} +``` + +**Output:** +``` +String: Hello, World! +Modified String: Hello, Corld! +``` + +#### Example with `string` Class +```cpp +#include +#include +using namespace std; + +int main() { + string str = "Hello, World!"; + cout << "String: " << str << endl; + + // Changing a character + str[7] = 'C'; + cout << "Modified String: " << str << endl; + + // String concatenation + str += " How are you?"; + cout << "Concatenated String: " << str << endl; + + return 0; +} +``` + +**Output:** +``` +String: Hello, World! +Modified String: Hello, Corld! +Concatenated String: Hello, Corld! How are you? +``` + + + +:::tip +- **Initialization:** Always initialize arrays to avoid garbage values. +- **Bounds Checking:** Ensure you do not access elements outside the array bounds to avoid undefined behavior. +- **Use Standard Library:** Prefer using the `string` class over character arrays for easier manipulation and safety. +- **Nested Loops for Multidimensional Arrays:** Use nested loops to iterate through elements of multidimensional arrays effectively. +- **String Functions:** Utilize string functions like `length()`, `substr()`, and `find()` from the Standard Library for efficient string manipulation. +::: \ No newline at end of file diff --git a/courses/C++ /beginner-level/Control-flow/Loops.md b/courses/C++ /beginner-level/Control-flow/Loops.md new file mode 100644 index 000000000..65c707431 --- /dev/null +++ b/courses/C++ /beginner-level/Control-flow/Loops.md @@ -0,0 +1,140 @@ +--- +id: lesson-2 +title: "Loops" +sidebar_label: Loops +sidebar_position: 2 +description: "Loops in C++" +tags: [courses,beginner-level,C++,Introduction] +--- + + +1. **for Loop** + - Executes a block of code a specific number of times. + +2. **while Loop** + - Repeatedly executes a block of code while a condition is true. + +3. **do-while Loop** + - Similar to the while loop, but it executes the block of code once before checking the condition. + +#### Example +```cpp +#include +using namespace std; + +int main() { + // for loop + for (int i = 0; i < 5; ++i) { + cout << "for loop: " << i << endl; + } + + // while loop + int j = 0; + while (j < 5) { + cout << "while loop: " << j << endl; + ++j; + } + + // do-while loop + int k = 0; + do { + cout << "do-while loop: " << k << endl; + ++k; + } while (k < 5); + + return 0; +} +``` + +**Output:** +``` +for loop: 0 +for loop: 1 +for loop: 2 +for loop: 3 +for loop: 4 +while loop: 0 +while loop: 1 +while loop: 2 +while loop: 3 +while loop: 4 +do-while loop: 0 +do-while loop: 1 +do-while loop: 2 +do-while loop: 3 +do-while loop: 4 +``` + +#### Flowchart +```mermaid +graph TD; + A[Start] --> B{for loop: i < 5}; + B -- Yes --> C[Print i]; + C --> D[Increment i]; + D --> B; + B -- No --> E{while loop: j < 5}; + E -- Yes --> F[Print j]; + F --> G[Increment j]; + G --> E; + E -- No --> H{do-while loop: k < 5}; + H --> I[Print k]; + I --> J[Increment k]; + J --> K[Check condition]; + K -- Yes --> H; + K -- No --> L[End]; +``` + +#### Break and Continue Statements + +- **break** : Exits the loop or switch-case statement. +- **continue** : Skips the current iteration and proceeds to the next iteration of the loop. + +#### Example +```cpp +#include +using namespace std; + +int main() { + for (int i = 0; i < 10; ++i) { + if (i == 5) { + break; // exit the loop when i is 5 + } + cout << "i: " << i << endl; + } + + for (int j = 0; j < 10; ++j) { + if (j == 5) { + continue; // skip the iteration when j is 5 + } + cout << "j: " << j << endl; + } + + return 0; +} +``` + +**Output:** +``` +i: 0 +i: 1 +i: 2 +i: 3 +i: 4 +j: 0 +j: 1 +j: 2 +j: 3 +j: 4 +j: 6 +j: 7 +j: 8 +j: 9 +``` + +:::tip +- **Consistent Formatting:** Keep your code clean and well-formatted to improve readability and maintainability. +- **Use Comments:** Comment your code to explain complex logic, making it easier for others (and yourself) to understand later. +- **Avoid Deep Nesting:** Too many nested statements can make code difficult to read. Consider breaking them into separate functions. +- **Edge Cases:** Always test your code with various inputs, including edge cases, to ensure robustness. +- **Debugging:** Use debugging tools and print statements to trace and fix issues in your code efficiently. +::: \ No newline at end of file diff --git a/courses/C++ /beginner-level/Control-flow/_category_.json b/courses/C++ /beginner-level/Control-flow/_category_.json new file mode 100644 index 000000000..299af78bc --- /dev/null +++ b/courses/C++ /beginner-level/Control-flow/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Control-Flow", + "position": 4, + "link": { + "type": "generated-index", + "description": "Control-Flow in C++ Language." + } + } \ No newline at end of file diff --git a/courses/C++ /beginner-level/Control-flow/statements.md b/courses/C++ /beginner-level/Control-flow/statements.md new file mode 100644 index 000000000..c20575834 --- /dev/null +++ b/courses/C++ /beginner-level/Control-flow/statements.md @@ -0,0 +1,121 @@ +--- +id: lesson-1 +title: "Conditional Statements" +sidebar_label: Conditional Statements +sidebar_position: 1 +description: "Conditional Statements in C++" +tags: [courses,beginner-level,C++,Introduction] +--- + + +1. **if Statement** + - Evaluates a condition. If true, executes the associated block of code. + +2. **if-else Statement** + - Evaluates a condition. If true, executes the associated block of code. Otherwise, executes an alternative block of code. + +3. **Nested if Statement** + - An if or if-else statement inside another if or if-else statement. + +#### Example +```cpp +#include +using namespace std; + +int main() { + int x = 10; + + if (x > 0) { + cout << "x is positive" << endl; + } else { + cout << "x is not positive" << endl; + } + + if (x > 0) { + if (x < 20) { + cout << "x is between 0 and 20" << endl; + } + } + + return 0; +} +``` + +**Output:** +``` +x is positive +x is between 0 and 20 +``` + +#### Flowchart +```mermaid +graph TD; + A[Start] --> B[Is x > 0?]; + B -- Yes --> C[x is positive]; + B -- No --> D[x is not positive]; + C --> E[Is x < 20?]; + E -- Yes --> F[x is between 0 and 20]; + E -- No --> G[End]; + D --> G; + F --> G; +``` + +#### Switch-Case Statement + +Evaluates a variable against a list of values (cases). Executes the matching case block and continues with the following cases until a break statement is encountered. + +#### Example +```cpp +#include +using namespace std; + +int main() { + int day = 4; + + switch (day) { + case 1: + cout << "Monday" << endl; + break; + case 2: + cout << "Tuesday" << endl; + break; + case 3: + cout << "Wednesday" << endl; + break; + case 4: + cout << "Thursday" << endl; + break; + case 5: + cout << "Friday" << endl; + break; + default: + cout << "Weekend" << endl; + } + + return 0; +} +``` + +**Output:** +``` +Thursday +``` + +#### Flowchart +```mermaid +graph TD; + A[Start] --> B[Evaluate day]; + B --> C{Match day?}; + C -- 1 --> D[Monday]; + C -- 2 --> E[Tuesday]; + C -- 3 --> F[Wednesday]; + C -- 4 --> G[Thursday]; + C -- 5 --> H[Friday]; + C -- Default --> I[Weekend]; + D --> J[End]; + E --> J; + F --> J; + G --> J; + H --> J; + I --> J; +``` diff --git a/courses/C++ /beginner-level/Functions/Defining.md b/courses/C++ /beginner-level/Functions/Defining.md new file mode 100644 index 000000000..d281a5444 --- /dev/null +++ b/courses/C++ /beginner-level/Functions/Defining.md @@ -0,0 +1,110 @@ +--- +id: lesson-1 +title: "Functions" +sidebar_label: Functions +sidebar_position: 1 +description: "Learn Functions in C++" +tags: [courses,beginner-level,C++,Introduction] +--- + + +#### Defining and Declaring Functions + +- **Function Declaration:** Provides the function's name, return type, and parameters. +- **Function Definition:** Contains the actual body of the function. + + +### Flowchart +```mermaid +graph TD; + A[Start] --> B[Declare Function add]; + B --> C[Call add in main]; + C --> D{Is it defined?}; + D -- Yes --> E[Execute add]; + E --> F[Return Result]; + F --> G[Print Result]; + G --> H[End]; + D -- No --> I[Error]; + I --> H; +``` + +#### Example +```cpp +#include +using namespace std; + +// Function declaration +int add(int, int); + +int main() { + int a = 5, b = 3; + cout << "Sum: " << add(a, b) << endl; + return 0; +} + +// Function definition +int add(int x, int y) { + return x + y; +} +``` + +**Output:** +``` +Sum: 8 +``` + +#### Function Arguments and Return Values + +Functions can take arguments and return values. The return type is specified before the function name. + +#### Example +```cpp +#include +using namespace std; + +int multiply(int a, int b) { + return a * b; +} + +int main() { + int x = 4, y = 7; + int result = multiply(x, y); + cout << "Product: " << result << endl; + return 0; +} +``` + +**Output:** +``` +Product: 28 +``` + +#### Overloading Functions + +Function overloading allows multiple functions with the same name but different parameters. + +#### Example +```cpp +#include +using namespace std; + +int add(int a, int b) { + return a + b; +} + +double add(double a, double b) { + return a + b; +} + +int main() { + cout << "Int sum: " << add(2, 3) << endl; + cout << "Double sum: " << add(2.5, 3.5) << endl; + return 0; +} +``` + +**Output:** +``` +Int sum: 5 +Double sum: 6 +``` \ No newline at end of file diff --git a/courses/C++ /beginner-level/Functions/Recursion.md b/courses/C++ /beginner-level/Functions/Recursion.md new file mode 100644 index 000000000..6eee2b717 --- /dev/null +++ b/courses/C++ /beginner-level/Functions/Recursion.md @@ -0,0 +1,71 @@ +--- +id: lesson-2 +title: "Recursion" +sidebar_label: Recursion & Scope variable +sidebar_position: 2 +description: "Learn Recursion & Scope Variable in C++" +tags: [courses,beginner-level,C++,Introduction] +--- + + + +A function calling itself to solve a problem. + +#### Example +```cpp +#include +using namespace std; + +int factorial(int n) { + if (n <= 1) + return 1; + else + return n * factorial(n - 1); +} + +int main() { + int num = 5; + cout << "Factorial of " << num << " is " << factorial(num) << endl; + return 0; +} +``` + +**Output:** +``` +Factorial of 5 is 120 +``` + +### Scope and Lifetime of Variables + +- **Scope:** The region of code where a variable is accessible. +- **Lifetime:** The duration for which a variable exists in memory. + +#### Example +```cpp +#include +using namespace std; + +void display() { + int localVar = 10; // local scope + cout << "Local variable: " << localVar << endl; +} + +int main() { + display(); + // cout << localVar; // Error: localVar is not accessible here + return 0; +} +``` + +**Output:** +``` +Local variable: 10 +``` + +:::tip +- **Meaningful Names:** Use descriptive names for functions and variables to make your code more readable. +- **Modular Code:** Break your code into smaller, reusable functions. +- **Avoid Global Variables:** Minimize the use of global variables to reduce dependency and potential bugs. +- **Commenting:** Document your functions with comments explaining their purpose and usage. +- **Testing:** Thoroughly test each function independently to ensure it works correctly. +::: \ No newline at end of file diff --git a/courses/C++ /beginner-level/Functions/_category_.json b/courses/C++ /beginner-level/Functions/_category_.json new file mode 100644 index 000000000..6ae8128e0 --- /dev/null +++ b/courses/C++ /beginner-level/Functions/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Functions", + "position": 5, + "link": { + "type": "generated-index", + "description": "Functions in C++ Language." + } + } \ No newline at end of file diff --git a/courses/C++ /beginner-level/Introduction/_category_.json b/courses/C++ /beginner-level/Introduction/_category_.json new file mode 100644 index 000000000..304629adc --- /dev/null +++ b/courses/C++ /beginner-level/Introduction/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Introduction", + "position": 1, + "link": { + "type": "generated-index", + "description": "Understanding C++ Language." + } + } \ No newline at end of file diff --git a/courses/C++ /beginner-level/Introduction/setting-up.md b/courses/C++ /beginner-level/Introduction/setting-up.md new file mode 100644 index 000000000..969e6bb50 --- /dev/null +++ b/courses/C++ /beginner-level/Introduction/setting-up.md @@ -0,0 +1,75 @@ +--- +id: lesson-2 +title: "Setting up the Development Environment" +sidebar_label: SetUp +sidebar_position: 2 +description: "Setting up the Development Environment" +tags: [courses,beginner-level,C++,Introduction] +--- + +To start programming in C++, you need to set up a development environment. This typically involves installing a C++ compiler and an Integrated Development Environment (IDE). + +**Common Compilers and IDEs:** +- **Compilers:** GCC (GNU Compiler Collection), Clang, Microsoft Visual C++. +- **IDEs:** Visual Studio, Code::Blocks, CLion, Eclipse, Dev-C++. + +**Installing GCC on Windows using MinGW:** +1. Download MinGW from the [MinGW website](http://www.mingw.org/). +2. Run the installer and select the necessary packages (e.g., `mingw32-gcc-g++`). +3. Add the MinGW `bin` directory to your system's PATH environment variable. + +**Installing GCC on macOS using Homebrew:** +```bash +brew install gcc +``` + +**Installing GCC on Linux:** +```bash +sudo apt update +sudo apt install build-essential +``` + +#### Writing and Compiling Your First C++ Program + +**Example Program:** +```cpp +#include // Include the iostream library for input/output operations + +int main() { + std::cout << "Hello, World!" << std::endl; // Print "Hello, World!" to the console + return 0; // Return 0 to indicate that the program executed successfully +} +``` + +**Explanation:** +- `#include `: This line includes the iostream library, which allows for input and output operations. +- `int main()`: This is the main function where the execution of the program begins. +- `std::cout << "Hello, World!" << std::endl;`: This line prints "Hello, World!" to the console. `std::cout` is the standard output stream in C++. `std::endl` inserts a newline character. +- `return 0;`: This line terminates the main function and returns 0 to the operating system, indicating that the program executed successfully. + +**Compiling and Running the Program:** +1. Save the program to a file named `hello.cpp`. +2. Open a terminal or command prompt and navigate to the directory where `hello.cpp` is saved. +3. Compile the program using the following command: + ```bash + g++ hello.cpp -o hello + ``` + This command tells the `g++` compiler to compile `hello.cpp` and produce an executable file named `hello`. + +4. Run the compiled program: + ```bash + ./hello + ``` + +**Output:** +``` +Hello, World! +``` + +:::tip +- **Practice Regularly:** The best way to learn C++ is through consistent practice. Write small programs to understand the syntax and features. +- **Use Version Control:** As you progress, use version control systems like Git to manage your code and track changes. +- **Read Documentation:** Familiarize yourself with the C++ Standard Library and refer to the official documentation for functions and features. +- **Debugging:** Learn to use debugging tools available in your IDE to troubleshoot and fix issues in your code. +- **Join Communities:** Engage with C++ communities online to seek help, share knowledge, and stay updated with the latest developments in the language. +::: \ No newline at end of file diff --git a/courses/C++ /beginner-level/Introduction/what.md b/courses/C++ /beginner-level/Introduction/what.md new file mode 100644 index 000000000..048657a65 --- /dev/null +++ b/courses/C++ /beginner-level/Introduction/what.md @@ -0,0 +1,22 @@ +--- +id: lesson-1 +title: "Introduction to C++e" +sidebar_label: Getting Started +sidebar_position: 1 +description: "Introduction to C++" +tags: [courses,beginner-level,C++,Introduction] +--- + + +#### History of C++ +C++ was developed by Bjarne Stroustrup starting in 1979 at Bell Labs in Murray Hill, New Jersey. It was designed as an extension of the C programming language with the addition of object-oriented features. The first commercial release of C++ was in 1985, and since then, it has undergone numerous updates and improvements, making it a powerful and versatile programming language. + +:::note +#### Features and Benefits of C++ +- **Object-Oriented Programming:** Supports classes, inheritance, polymorphism, and encapsulation. +- **Rich Standard Library:** Provides a wide range of functions and data structures. +- **High Performance:** Offers fine-grained control over system resources. +- **Portability:** Can be used to develop applications on various platforms. +- **Multi-Paradigm Language:** Supports procedural, object-oriented, and generic programming paradigms. +- **Memory Management:** Allows manual memory management through pointers and dynamic allocation. +::: diff --git a/courses/C++ /beginner-level/Operators/Operators.md b/courses/C++ /beginner-level/Operators/Operators.md new file mode 100644 index 000000000..0566bb195 --- /dev/null +++ b/courses/C++ /beginner-level/Operators/Operators.md @@ -0,0 +1,119 @@ +--- +id: lesson-1 +title: "Operators and Expressions" +sidebar_label: "Important Operators" +sidebar_position: 1 +description: "Operators and Expressions" +tags: [courses, beginner-level, C++, Introduction] +--- + +### Arithmetic Operators +- `+` : Addition +- `-` : Subtraction +- `*` : Multiplication +- `/` : Division +- `%` : Modulus + +### Relational Operators +- `==` : Equal to +- `!=` : Not equal to +- `>` : Greater than +- `<` : Less than +- `>=` : Greater than or equal to +- `<=` : Less than or equal to + +### Logical Operators +- `&&` : Logical AND +- `||` : Logical OR +- `!` : Logical NOT + +### Assignment Operators +- `=` : Assign +- `+=` : Add and assign +- `-=` : Subtract and assign +- `*=` : Multiply and assign +- `/=` : Divide and assign +- `%=` : Modulus and assign + +### Increment and Decrement Operators +- `++` : Increment +- `--` : Decrement + +### Example Code + +```cpp +#include + +int main() { + int a = 10, b = 5; + int sum, diff, product, quotient, remainder; + bool isEqual, isGreater, isLess, isAnd, isOr, isNot; + + // Arithmetic operators + sum = a + b; + diff = a - b; + product = a * b; + quotient = a / b; + remainder = a % b; + + // Relational operators + isEqual = (a == b); + isGreater = (a > b); + isLess = (a < b); + + // Logical operators + isAnd = (a > 0 && b > 0); + isOr = (a > 0 || b > 0); + isNot = !(a == b); + + // Assignment operators + a += b; + a -= b; + a *= b; + a /= b; + a %= b; + + // Increment and decrement operators + a++; + b--; + + std::cout << "Sum: " << sum << std::endl; + std::cout << "Difference: " << diff << std::endl; + std::cout << "Product: " << product << std::endl; + std::cout << "Quotient: " << quotient << std::endl; + std::cout << "Remainder: " << remainder << std::endl; + std::cout << "Is Equal: " << isEqual << std::endl; + std::cout << "Is Greater: " << isGreater << std::endl; + std::cout << "Is Less: " << isLess << std::endl; + std::cout << "Logical AND: " << isAnd << std::endl; + std::cout << "Logical OR: " << isOr << std::endl; + std::cout << "Logical NOT: " << isNot << std::endl; + + return 0; +} +``` + +### Output + +``` +Sum: 15 +Difference: 5 +Product: 50 +Quotient: 2 +Remainder: 0 +Is Equal: 0 +Is Greater: 1 +Is Less: 0 +Logical AND: 1 +Logical OR: 1 +Logical NOT: 1 +``` + + +:::tip +- **Use Parentheses:** When in doubt about operator precedence, use parentheses to ensure clarity. +- **Avoid Division by Zero:** Always check to ensure the divisor is not zero before performing division. +- **Consistent Use of Logical Operators:** Ensure logical operations are used consistently to avoid unexpected results. +- **Increment/Decrement in Loops:** Increment and decrement operators are commonly used in loop control statements for better performance and readability. +- **Test Thoroughly:** Always test your expressions with different inputs to ensure they handle edge cases properly. +::: \ No newline at end of file diff --git a/courses/C++ /beginner-level/Operators/_category_.json b/courses/C++ /beginner-level/Operators/_category_.json new file mode 100644 index 000000000..8e889db76 --- /dev/null +++ b/courses/C++ /beginner-level/Operators/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Operators", + "position": 3, + "link": { + "type": "generated-index", + "description": "Operators in C++." + } + } \ No newline at end of file diff --git a/courses/C++ /beginner-level/Pointers/_category_.json b/courses/C++ /beginner-level/Pointers/_category_.json new file mode 100644 index 000000000..10246c5a7 --- /dev/null +++ b/courses/C++ /beginner-level/Pointers/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Pointers", + "position": 7, + "link": { + "type": "generated-index", + "description": "Pointers in C++ Language." + } + } \ No newline at end of file diff --git a/courses/C++ /beginner-level/Pointers/intro.md b/courses/C++ /beginner-level/Pointers/intro.md new file mode 100644 index 000000000..80e795808 --- /dev/null +++ b/courses/C++ /beginner-level/Pointers/intro.md @@ -0,0 +1,146 @@ +--- +id: lesson-1 +title: "Pointers" +sidebar_label: Introduction +sidebar_position: 1 +description: "Learn pointers" +tags: [courses,beginner-level,C++,Introduction] +--- + + +### Introduction to Pointers +Pointers are variables that store the memory address of another variable. + +### Flowchart +```mermaid +graph TD; + A[Start] --> B[Declare Variable]; + B --> C[Declare Pointer]; + C --> D[Initialize Pointer with Variable Address]; + D --> E{Pointer Arithmetic?}; + E -- Yes --> F[Increment/Decrement Pointer]; + F --> G[Access Memory Location]; + E -- No --> H{Pointer to Pointer?}; + H -- Yes --> I[Declare Pointer to Pointer]; + I --> J[Initialize Pointer to Pointer]; + J --> K[Access Memory Location]; + H -- No --> L[Pass Pointer to Function]; + L --> M[Function Modifies Variable]; + M --> K; + G --> N[End]; + K --> N; +``` + + +### Example + +```cpp +#include +using namespace std; + +int main() { + int var = 10; + int *ptr = &var; // Pointer to var + + cout << "Value of var: " << var << endl; + cout << "Address of var: " << &var << endl; + cout << "Value of ptr: " << ptr << endl; + cout << "Value pointed by ptr: " << *ptr << endl; + + return 0; +} +``` + +**Output:** +``` +Value of var: 10 +Address of var: 0x7ffd6fdfd8ac +Value of ptr: 0x7ffd6fdfd8ac +Value pointed by ptr: 10 +``` + +#### Pointer Arithmetic +Pointer arithmetic allows you to navigate through arrays and memory efficiently. + +#### Example +```cpp +#include +using namespace std; + +int main() { + int arr[3] = {10, 20, 30}; + int *ptr = arr; // Pointer to the first element of the array + + for(int i = 0; i < 3; i++) { + cout << "Value at arr[" << i << "]: " << *(ptr + i) << endl; + } + + return 0; +} +``` + +**Output:** +``` +Value at arr[0]: 10 +Value at arr[1]: 20 +Value at arr[2]: 30 +``` + +#### Pointers and Arrays +Arrays and pointers are closely related. The name of the array acts as a pointer to its first element. + + +#### Example +```cpp +#include +using namespace std; + +void printArray(int *ptr, int size) { + for(int i = 0; i < size; i++) { + cout << "Element " << i << ": " << *(ptr + i) << endl; + } +} + +int main() { + int arr[3] = {10, 20, 30}; + printArray(arr, 3); + + return 0; +} +``` + +**Output:** +``` +Element 0: 10 +Element 1: 20 +Element 2: 30 +``` + +#### Pointers and Functions +Pointers can be passed to functions to allow the function to modify the argument passed. + + + +#### Example +```cpp +#include +using namespace std; + +void increment(int *ptr) { + (*ptr)++; +} + +int main() { + int var = 10; + increment(&var); + + cout << "Value of var after increment: " << var << endl; + + return 0; +} +``` + +**Output:** +``` +Value of var after increment: 11 +``` diff --git a/courses/C++ /beginner-level/Pointers/pointer-to-point.md b/courses/C++ /beginner-level/Pointers/pointer-to-point.md new file mode 100644 index 000000000..416e01e69 --- /dev/null +++ b/courses/C++ /beginner-level/Pointers/pointer-to-point.md @@ -0,0 +1,49 @@ +--- +id: lesson-2 +title: "Pointer to Pointer" +sidebar_label: Pointer to Pointer +sidebar_position: 2 +description: "Learn Pointer to Pointer" +tags: [courses,beginner-level,C++,Introduction] +--- + +A pointer to a pointer is a form of multiple indirection or a chain of pointers. + + +#### Example +```cpp +#include +using namespace std; + +int main() { + int var = 10; + int *ptr = &var; + int **ptr2ptr = &ptr; + + cout << "Value of var: " << var << endl; + cout << "Value of ptr: " << ptr << endl; + cout << "Value pointed by ptr: " << *ptr << endl; + cout << "Value of ptr2ptr: " << ptr2ptr << endl; + cout << "Value pointed by ptr2ptr: " << **ptr2ptr << endl; + + return 0; +} +``` + +**Output:** +``` +Value of var: 10 +Value of ptr: 0x7ffd6fdfd8ac +Value pointed by ptr: 10 +Value of ptr2ptr: 0x7ffd6fdfd8a0 +Value pointed by ptr2ptr: 10 +``` + + +:::tip +- **Pointer Initialization:** Always initialize pointers to avoid undefined behavior. +- **Pointer Arithmetic:** Understand pointer arithmetic to efficiently navigate arrays. +- **Function Arguments:** Use pointers in function arguments to modify variables outside the function. +- **Multiple Indirection:** Use pointers to pointers for complex data structures and dynamic memory management. +- **Debugging:** Be cautious with pointer operations to avoid memory leaks and segmentation faults. +::: \ No newline at end of file diff --git a/courses/C++ /beginner-level/Structure-and-unions/Strucutre.md b/courses/C++ /beginner-level/Structure-and-unions/Strucutre.md new file mode 100644 index 000000000..50acd75a6 --- /dev/null +++ b/courses/C++ /beginner-level/Structure-and-unions/Strucutre.md @@ -0,0 +1,155 @@ +--- +id: lesson-1 +title: "Structures" +sidebar_label: Structures +sidebar_position: 1 +description: "Structures in c++" +tags: [courses,beginner-level,C++,Introduction] +--- + +#### Defining and Using Structures + +**Structures** in C/C++ are user-defined data types that allow grouping variables of different types together. + +### Flowchart +```mermaid +graph TD; + A[Start] --> B[Define Structure/Union]; + B --> C{Structure or Union?}; + C -- Structure --> D[Declare Structure Variable]; + C -- Union --> E[Declare Union Variable]; + D --> F[Initialize Structure Members]; + E --> G[Assign Value to Union Member]; + F --> H[Access Structure Members]; + G --> I[Access Union Member]; + H --> J[End]; + I --> J; +``` + +```cpp +#include +using namespace std; + +// Define a structure +struct Person { + string name; + int age; + float height; +}; + +int main() { + // Declare a structure variable + Person person1; + + // Initialize structure members + person1.name = "John Doe"; + person1.age = 30; + person1.height = 5.9; + + // Access and print structure members + cout << "Name: " << person1.name << endl; + cout << "Age: " << person1.age << endl; + cout << "Height: " << person1.height << endl; + + return 0; +} +``` + +**Output:** +``` +Name: John Doe +Age: 30 +Height: 5.9 +``` + +#### Array of Structures + +An array of structures is useful for storing multiple records. + +```cpp +#include +using namespace std; + +// Define a structure +struct Person { + string name; + int age; + float height; +}; + +int main() { + // Declare an array of structures + Person people[3] = { + {"Alice", 28, 5.6}, + {"Bob", 34, 5.8}, + {"Charlie", 22, 5.7} + }; + + // Access and print array of structures + for (int i = 0; i < 3; i++) { + cout << "Name: " << people[i].name << endl; + cout << "Age: " << people[i].age << endl; + cout << "Height: " << people[i].height << endl; + } + + return 0; +} +``` + +**Output:** +``` +Name: Alice +Age: 28 +Height: 5.6 +Name: Bob +Age: 34 +Height: 5.8 +Name: Charlie +Age: 22 +Height: 5.7 +``` + +#### Nested Structures + +Nested structures allow for more complex data representation. + +```cpp +#include +using namespace std; + +// Define a structure +struct Address { + string city; + string state; + int zipCode; +}; + +struct Person { + string name; + int age; + Address address; // Nested structure +}; + +int main() { + // Declare a structure variable + Person person = {"John Doe", 30, {"New York", "NY", 10001}}; + + // Access and print nested structure members + cout << "Name: " << person.name << endl; + cout << "Age: " << person.age << endl; + cout << "City: " << person.address.city << endl; + cout << "State: " << person.address.state << endl; + cout << "Zip Code: " << person.address.zipCode << endl; + + return 0; +} +``` + +**Output:** +``` +Name: John Doe +Age: 30 +City: New York +State: NY +Zip Code: 10001 +``` diff --git a/courses/C++ /beginner-level/Structure-and-unions/Union.md b/courses/C++ /beginner-level/Structure-and-unions/Union.md new file mode 100644 index 000000000..6427a8373 --- /dev/null +++ b/courses/C++ /beginner-level/Structure-and-unions/Union.md @@ -0,0 +1,65 @@ +--- +id: lesson-2 +title: "Introduction to Unions" +sidebar_label: Unions +sidebar_position: 2 +description: "Unions in c++" +tags: [courses,beginner-level,C++,Introduction] +--- + + +A **union** is a user-defined data type that allows storing different data types in the same memory location. Only one of the members can contain a value at any given time. + +```cpp +#include +using namespace std; + +// Define a union +union Data { + int intValue; + float floatValue; + char charValue; +}; + +int main() { + // Declare a union variable + Data data; + + // Assign and access union members + data.intValue = 10; + cout << "Integer: " << data.intValue << endl; + + data.floatValue = 3.14; + cout << "Float: " << data.floatValue << endl; + + data.charValue = 'A'; + cout << "Char: " << data.charValue << endl; + + return 0; +} +``` + +**Output:** +``` +Integer: 10 +Float: 3.14 +Char: A +``` + +#### Differences Between Structures and Unions + +| Feature | Structure | Union | +|--------------------|------------------------------------------------------|------------------------------------------------------| +| Storage | All members have their own storage | All members share the same memory location | +| Size | Sum of the sizes of all members | Size of the largest member | +| Access | All members can be accessed at any time | Only one member can be accessed at a time | +| Use Case | Used for grouping related data together | Used for efficient memory usage | + + +:::tip +- **Structures:** Use structures for grouping related data together. They are helpful for creating records like a student's details or an employee's profile. +- **Unions:** Use unions when you need to store one of several types of data in the same memory location. This can be useful for memory-efficient representations of data that can take multiple forms. +- **Initialization:** Always initialize structures and unions properly to avoid undefined behavior. +- **Nested Structures:** Utilize nested structures to represent complex data relationships. +- **Accessing Members:** When using unions, remember that assigning a new value to one member will overwrite any existing value in the union. +::: \ No newline at end of file diff --git a/courses/C++ /beginner-level/Structure-and-unions/_category_.json b/courses/C++ /beginner-level/Structure-and-unions/_category_.json new file mode 100644 index 000000000..0d75f7963 --- /dev/null +++ b/courses/C++ /beginner-level/Structure-and-unions/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Structures and Unions", + "position": 8, + "link": { + "type": "generated-index", + "description": "Structures and Unions in C++." + } + } \ No newline at end of file diff --git a/courses/C++ /beginner-level/_category_.json b/courses/C++ /beginner-level/_category_.json new file mode 100644 index 000000000..d22b47ef3 --- /dev/null +++ b/courses/C++ /beginner-level/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Beginner Level", + "position": 2, + "link": { + "type": "generated-index", + "description": "Learn Beginner C++ Language Techniques." + } + } \ No newline at end of file diff --git a/courses/C++ /beginner-level/structure/Introduction.md b/courses/C++ /beginner-level/structure/Introduction.md new file mode 100644 index 000000000..e6337cf26 --- /dev/null +++ b/courses/C++ /beginner-level/structure/Introduction.md @@ -0,0 +1,92 @@ +--- +id: lesson-1 +title: "Structure of C++ programming" +sidebar_label: Introduction +sidebar_position: 1 +description: "Structure of C++ programming" +tags: [courses,beginner-level,C++,Introduction] +--- + +A C++ program generally consists of the following parts: + +:::note +- **Preprocessor Directives:** Instructions to the compiler to include files and define constants. +- **Main Function:** The entry point of the program where execution begins. +- **Functions:** Blocks of code that perform specific tasks. +- **Variables:** Containers for storing data values. +:::: + +**Example:** +```cpp +#include // Preprocessor directive to include the standard input/output stream library + +// Main function where program execution begins +int main() { + std::cout << "Hello, World!" << std::endl; // Output "Hello, World!" to the console + return 0; // Return 0 to indicate successful execution +} +``` + +#### Data Types and Variables +Variables are used to store data. Each variable must be declared with a data type. + +:::note +**Common Data Types:** +- **int:** Integer numbers +- **float:** Floating-point numbers +- **double:** Double-precision floating-point numbers +- **char:** Single characters +- **bool:** Boolean values (true or false) +::: + +**Example:** +```cpp +#include + +int main() { + int age = 25; // Integer variable + float height = 5.9; // Floating-point variable + char grade = 'A'; // Character variable + bool isStudent = true; // Boolean variable + + std::cout << "Age: " << age << std::endl; + std::cout << "Height: " << height << std::endl; + std::cout << "Grade: " << grade << std::endl; + std::cout << "Is Student: " << std::boolalpha << isStudent << std::endl; + + return 0; +} +``` + +**Output:** +``` +Age: 25 +Height: 5.9 +Grade: A +Is Student: true +``` + +#### Constants and Literals +Constants are fixed values that cannot be altered during the execution of a program. They can be defined using the `const` keyword or `#define` preprocessor directive. + +**Example:** +```cpp +#include + +#define PI 3.14159 // Define a constant using preprocessor directive + +int main() { + const int DAYS_IN_WEEK = 7; // Define a constant using const keyword + + std::cout << "Value of PI: " << PI << std::endl; + std::cout << "Days in a week: " << DAYS_IN_WEEK << std::endl; + + return 0; +} +``` + +**Output:** +``` +Value of PI: 3.14159 +Days in a week: 7 +``` diff --git a/courses/C++ /beginner-level/structure/_category_.json b/courses/C++ /beginner-level/structure/_category_.json new file mode 100644 index 000000000..3019f110a --- /dev/null +++ b/courses/C++ /beginner-level/structure/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Structure", + "position": 2, + "link": { + "type": "generated-index", + "description": "Structure in C++." + } + } \ No newline at end of file diff --git a/courses/C++ /beginner-level/structure/input-and-output.md b/courses/C++ /beginner-level/structure/input-and-output.md new file mode 100644 index 000000000..97371104c --- /dev/null +++ b/courses/C++ /beginner-level/structure/input-and-output.md @@ -0,0 +1,39 @@ +--- +id: lesson-2 +title: "Input and Output Operations (cin, cout)" +sidebar_label: Input and Output Operations +sidebar_position: 2 +description: "Input and Output Operations (cin, cout)t" +tags: [courses,beginner-level,C++,Introduction] +--- + +C++ uses `cin` and `cout` for input and output operations, respectively. They are part of the iostream library. + +**Example:** +```cpp +#include + +int main() { + int number; + std::cout << "Enter a number: "; // Output a prompt to the console + std::cin >> number; // Input a number from the user + + std::cout << "You entered: " << number << std::endl; // Output the entered number + + return 0; +} +``` + +**Output:** +``` +Enter a number: 42 +You entered: 42 +``` + +:::tip +- **Consistent Indentation:** Keep your code readable by using consistent indentation and spacing. +- **Meaningful Variable Names:** Use descriptive names for your variables to make your code easier to understand. +- **Comment Your Code:** Use comments to explain the purpose of complex code blocks. +- **Practice Regularly:** Write and run small programs to familiarize yourself with the syntax and structure of C++. +- **Refer to Documentation:** Always refer to the official C++ documentation and resources for detailed information and examples. +::: \ No newline at end of file diff --git a/courses/C++ /intermediate-level/Dynamic-memory-allocation/_category_.json b/courses/C++ /intermediate-level/Dynamic-memory-allocation/_category_.json new file mode 100644 index 000000000..c92d3ea13 --- /dev/null +++ b/courses/C++ /intermediate-level/Dynamic-memory-allocation/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Dynamic Memory Allocation", + "position": 2, + "link": { + "type": "generated-index", + "description": "Learn Dynamic Memory Allocation in C++." + } + } \ No newline at end of file diff --git a/courses/C++ /intermediate-level/Dynamic-memory-allocation/intro.md b/courses/C++ /intermediate-level/Dynamic-memory-allocation/intro.md new file mode 100644 index 000000000..061b459e4 --- /dev/null +++ b/courses/C++ /intermediate-level/Dynamic-memory-allocation/intro.md @@ -0,0 +1,93 @@ +--- +id: lesson-1 +title: "Dynamic Memory Allocation" +sidebar_label: Dynamic Memory Allocation +sidebar_position: 1 +description: "Learn Dynamic Memory Allocation" +tags: [courses,intermediate-level,React Native,Introduction] +--- + + +Dynamic memory allocation in C++ allows you to allocate memory at runtime using the `new` and `delete` operators. This is essential for creating objects whose size or quantity may not be known until the program is running. + +### Introduction to Dynamic Memory Allocation + +Dynamic memory allocation enables more flexible and efficient use of memory. Unlike static memory allocation, which is determined at compile-time, dynamic memory allocation occurs at runtime, making it possible to allocate and deallocate memory as needed. + +### Flowchart + +```mermaid +graph TD; + A[Start] --> B[Allocate Memory using new]; + B --> C[Use the Allocated Memory]; + C --> D{Memory no longer needed?}; + D -- Yes --> E[Deallocate Memory using delete]; + E --> F[Set Pointer to nullptr]; + F --> G[End]; + D -- No --> C; +``` + +:::note +**new and delete Operators** + +- **`new` operator**: Allocates memory dynamically on the heap and returns a pointer to the allocated memory. +- **`delete` operator**: Deallocates memory that was previously allocated with `new`. +::: + +##### Example: Allocating and Deallocating a Single Variable +```cpp +#include +using namespace std; + +int main() { + int *p = new int; // Dynamically allocate memory for an integer + *p = 10; // Assign a value to the allocated memory + + cout << "Value: " << *p << endl; // Output: Value: 10 + + delete p; // Deallocate the memory + p = nullptr; // Avoid dangling pointer + + return 0; +} +``` + +**Output:** +``` +Value: 10 +``` + +##### Example: Allocating and Deallocating an Array +```cpp +#include +using namespace std; + +int main() { + int size; + cout << "Enter the size of the array: "; + cin >> size; + + int *arr = new int[size]; // Dynamically allocate memory for an array + + for (int i = 0; i < size; ++i) { + arr[i] = i + 1; // Initialize array + } + + cout << "Array elements: "; + for (int i = 0; i < size; ++i) { + cout << arr[i] << " "; + } + cout << endl; + + delete[] arr; // Deallocate the memory for the array + arr = nullptr; // Avoid dangling pointer + + return 0; +} +``` + +**Output:** +``` +Enter the size of the array: 5 +Array elements: 1 2 3 4 5 +``` \ No newline at end of file diff --git a/courses/C++ /intermediate-level/Dynamic-memory-allocation/memory-mangement.md b/courses/C++ /intermediate-level/Dynamic-memory-allocation/memory-mangement.md new file mode 100644 index 000000000..e694aa406 --- /dev/null +++ b/courses/C++ /intermediate-level/Dynamic-memory-allocation/memory-mangement.md @@ -0,0 +1,72 @@ +--- +id: lesson-2 +title: "Memory Management Techniques" +sidebar_label: Memory Management Techniques +sidebar_position: 2 +description: "Learn Memory Management Techniques" +tags: [courses,intermediate-level,React Native,Introduction] +--- + + +Proper memory management involves: + +- **Allocating memory** only when needed. +- **Deallocating memory** when it is no longer needed to avoid memory leaks. +- **Setting pointers to nullptr** after deletion to avoid dangling pointers. + +#### Common Memory-Related Issues + +- **Memory Leaks**: Occur when allocated memory is not deallocated, leading to wasted memory. +- **Dangling Pointers**: Pointers that reference memory that has been deallocated. +- **Double Deletion**: Deallocating the same memory more than once, which can cause program crashes or undefined behavior. + +##### Example: Memory Leak +```cpp +#include +using namespace std; + +void createMemoryLeak() { + int *p = new int[10]; // Memory is allocated but never deallocated +} + +int main() { + createMemoryLeak(); + // Memory leak occurs here because the allocated memory is not deallocated + return 0; +} +``` + +#### Preventing Memory Leaks and Dangling Pointers + +- Always pair `new` with `delete` and `new[]` with `delete[]`. +- Set pointers to `nullptr` after deleting. +- Use smart pointers (like `std::unique_ptr` and `std::shared_ptr` in C++11 and later) to manage memory automatically. + +##### Example: Using Smart Pointers +```cpp +#include +#include +using namespace std; + +int main() { + unique_ptr p(new int(10)); // Automatically manages memory + + cout << "Value: " << *p << endl; // Output: Value: 10 + + // No need to manually delete, smart pointer takes care of it + + return 0; +} +``` + +**Output:** +``` +Value: 10 +``` + +:::tip +- **Always Deallocate Memory**: Ensure that every `new` is paired with a corresponding `delete` to prevent memory leaks. +- **Avoid Dangling Pointers**: Set pointers to `nullptr` after deleting the allocated memory. +- **Use Smart Pointers**: Consider using smart pointers (`std::unique_ptr`, `std::shared_ptr`) to manage memory automatically and avoid common pitfalls associated with manual memory management. +- **Check for nullptr**: Before using a pointer, always check if it is `nullptr` to prevent dereferencing invalid memory. +::: \ No newline at end of file diff --git a/courses/C++ /intermediate-level/Exception-handling/_category_.json b/courses/C++ /intermediate-level/Exception-handling/_category_.json new file mode 100644 index 000000000..61bcaf5f2 --- /dev/null +++ b/courses/C++ /intermediate-level/Exception-handling/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Exception Handling", + "position": 5, + "link": { + "type": "generated-index", + "description": "Learn Exception Handling in C++." + } + } \ No newline at end of file diff --git a/courses/C++ /intermediate-level/Exception-handling/custom-handling.md b/courses/C++ /intermediate-level/Exception-handling/custom-handling.md new file mode 100644 index 000000000..b2ef07502 --- /dev/null +++ b/courses/C++ /intermediate-level/Exception-handling/custom-handling.md @@ -0,0 +1,86 @@ +--- +id: lesson-2 +title: "Creating Custom Exceptions" +sidebar_label: Creating Custom Exceptions +sidebar_position: 2 +description: "Learn Creating Custom Exceptions" +tags: [courses,intermediate-level,React Native,Introduction] +--- + +Custom exceptions can be created by inheriting from the `std::exception` class. + +##### Example: Custom Exception + +```cpp +#include +#include +using namespace std; + +class MyException : public exception { +public: + const char* what() const throw() { + return "Custom Exception Occurred"; + } +}; + +int main() { + try { + throw MyException(); + } catch (MyException& e) { + cout << e.what() << endl; + } + return 0; +} +``` + +**Output:** +``` +Custom Exception Occurred +``` + +:::important +1. **Use Exceptions for Exceptional Conditions**: Only use exceptions for conditions that are truly exceptional and not for regular control flow. +2. **Catch by Reference**: Catch exceptions by reference to avoid slicing and unnecessary copying. +3. **Be Specific**: Catch specific exceptions before catching more general exceptions. +4. **Cleanup Resources**: Ensure that all resources are properly cleaned up in case of an exception. This can be achieved using RAII (Resource Acquisition Is Initialization) principles. +5. **Avoid Overuse**: Do not overuse exceptions; use them judiciously. +::: + + +##### Example + +```cpp +#include +#include +using namespace std; + +int main() { + try { + int a = 10; + int b = 0; + if (b == 0) { + throw runtime_error("Runtime Error: Division by zero!"); + } + cout << a / b << endl; + } catch (const runtime_error& e) { + cerr << "Caught a runtime_error: " << e.what() << endl; + } catch (const exception& e) { + cerr << "Caught an exception: " << e.what() << endl; + } catch (...) { + cerr << "Caught an unknown exception" << endl; + } + return 0; +} +``` + +**Output:** +``` +Caught a runtime_error: Runtime Error: Division by zero! +``` + +:::tip +- **Handle Exceptions at Appropriate Levels**: Exceptions should be handled at levels where recovery is possible. +- **Use Standard Exceptions**: Leverage standard exceptions provided by the C++ library to avoid redundancy. +- **Provide Useful Error Messages**: Ensure that exceptions provide meaningful messages to help diagnose the problem. +- **Test Exception Handling Paths**: Regularly test your exception handling code to ensure it works as expected. +::: \ No newline at end of file diff --git a/courses/C++ /intermediate-level/Exception-handling/intro.md b/courses/C++ /intermediate-level/Exception-handling/intro.md new file mode 100644 index 000000000..f7a7daecc --- /dev/null +++ b/courses/C++ /intermediate-level/Exception-handling/intro.md @@ -0,0 +1,78 @@ +--- +id: lesson-1 +title: "Exception Handling in C++" +sidebar_label: Intro +sidebar_position: 1 +description: "Learn Exception Handling in C++" +tags: [courses,intermediate-level,React Native,Introduction] +--- + + +Exception handling in C++ provides a way to handle runtime errors, ensuring that the program can manage unexpected situations gracefully. + +#### Introduction to Exception Handling + +Exception handling involves using the `try`, `catch`, and `throw` keywords to handle errors and exceptional conditions in a controlled manner. + +### Flowchart + +```mermaid +graph TD; + A[Start] --> B[try block]; + B --> C{Exception thrown?}; + C -- No --> D[Continue program]; + C -- Yes --> E[catch block]; + E --> F{Specific exception caught?}; + F -- Yes --> G[Handle exception]; + F -- No --> H{Any other exception caught?}; + H -- Yes --> I[Handle general exception]; + H -- No --> J[Terminate program]; + G --> D; + I --> D; + J --> K[End]; + D --> K; +``` + + +#### Basic Syntax + +The basic structure for exception handling in C++ is: + +```cpp +try { + // Code that may throw an exception +} catch (exceptionType1 e1) { + // Code to handle exception of type exceptionType1 +} catch (exceptionType2 e2) { + // Code to handle exception of type exceptionType2 + // ... +} catch (...) { + // Code to handle any exception type +} +``` + +#### Example: Basic Exception Handling + +```cpp +#include +using namespace std; + +int main() { + try { + int a = 10; + int b = 0; + if (b == 0) { + throw "Division by zero!"; + } + cout << a / b << endl; + } catch (const char* msg) { + cerr << "Error: " << msg << endl; + } + return 0; +} +``` + +**Output:** +``` +Error: Division by zero! +``` diff --git a/courses/C++ /intermediate-level/File-Handling/Intro.md b/courses/C++ /intermediate-level/File-Handling/Intro.md new file mode 100644 index 000000000..bc1ff4a42 --- /dev/null +++ b/courses/C++ /intermediate-level/File-Handling/Intro.md @@ -0,0 +1,113 @@ +--- +id: lesson-1 +title: "File Handling" +sidebar_label: File Handling +sidebar_position: 1 +description: "Learn File Handling" +tags: [courses,intermediate-level,React Native,Introduction] +--- + + +File handling in C++ is essential for performing operations such as reading from and writing to files. This allows programs to persist data between executions and manage large amounts of information. + +### Introduction to File Handling + +File handling in C++ involves using the file stream classes provided in the `` header: `ifstream` for reading files, `ofstream` for writing files, and `fstream` for both reading and writing. + + +### Flowchart + +```mermaid +graph TD; + A[Start] --> B[Open file]; + B --> C{File opened successfully?}; + C -- Yes --> D[Perform file operations =>read/write]; + D --> E[Close file]; + E --> F[End]; + C -- No --> G[Display error]; + G --> F; +``` + +#### File Operations (Opening, Closing, Reading, Writing) + +- **Opening a file**: To open a file, you need to create an object of `ifstream` or `ofstream` and use the `open` method, or you can open a file directly using the constructor. +- **Closing a file**: Always close a file after performing operations using the `close` method to ensure all data is written and resources are freed. +- **Reading from a file**: Use `ifstream` and various input operations (e.g., `>>`, `getline`). +- **Writing to a file**: Use `ofstream` and output operations (e.g., `<<`). + +##### Example: Basic File Operations +```cpp +#include +#include +using namespace std; + +int main() { + // Writing to a file + ofstream outFile("example.txt"); + if (outFile.is_open()) { + outFile << "Hello, World!" << endl; + outFile << "Writing to a file in C++." << endl; + outFile.close(); // Close the file + } else { + cout << "Unable to open file for writing" << endl; + } + + // Reading from a file + ifstream inFile("example.txt"); + if (inFile.is_open()) { + string line; + while (getline(inFile, line)) { + cout << line << endl; // Output each line + } + inFile.close(); // Close the file + } else { + cout << "Unable to open file for reading" << endl; + } + + return 0; +} +``` + +**Output:** +``` +Hello, World! +Writing to a file in C++. +``` + +#### File Pointers and File Modes + +- **File Pointers**: `ifstream`, `ofstream`, and `fstream` objects have internal pointers that determine where to read or write in the file. You can manipulate these pointers using methods like `seekg`, `seekp`, `tellg`, and `tellp`. +- **File Modes**: Specify the mode in which a file is opened (e.g., `ios::in`, `ios::out`, `ios::app`, `ios::binary`). Multiple modes can be combined using the bitwise OR operator (`|`). + +##### Example: Using File Modes +```cpp +#include +#include +using namespace std; + +int main() { + ofstream outFile("example.txt", ios::app); // Open in append mode + if (outFile.is_open()) { + outFile << "Appending a new line." << endl; + outFile.close(); + } + + ifstream inFile("example.txt", ios::in); // Open in read mode + if (inFile.is_open()) { + string line; + while (getline(inFile, line)) { + cout << line << endl; + } + inFile.close(); + } + + return 0; +} +``` + +**Output:** +``` +Hello, World! +Writing to a file in C++. +Appending a new line. +``` diff --git a/courses/C++ /intermediate-level/File-Handling/_category_.json b/courses/C++ /intermediate-level/File-Handling/_category_.json new file mode 100644 index 000000000..6488716a0 --- /dev/null +++ b/courses/C++ /intermediate-level/File-Handling/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "File Handling", + "position": 3, + "link": { + "type": "generated-index", + "description": "Learn File Handling in C++." + } + } \ No newline at end of file diff --git a/courses/C++ /intermediate-level/File-Handling/working-with-binary.md b/courses/C++ /intermediate-level/File-Handling/working-with-binary.md new file mode 100644 index 000000000..1b71c1711 --- /dev/null +++ b/courses/C++ /intermediate-level/File-Handling/working-with-binary.md @@ -0,0 +1,52 @@ +--- +id: lesson-2 +title: "Working with Binary Files" +sidebar_label: Working with Binary Files +sidebar_position: 2 +description: "Learn Working with Binary Filesg" +tags: [courses,intermediate-level,React Native,Introduction] +--- + + +Binary files store data in a binary format, which is more efficient and compact. Use `ios::binary` mode to read/write binary files. + +##### Example: Binary File Operations +```cpp +#include +#include +using namespace std; + +int main() { + // Writing to a binary file + ofstream outFile("example.bin", ios::binary); + if (outFile.is_open()) { + int num = 12345; + outFile.write(reinterpret_cast(&num), sizeof(num)); + outFile.close(); + } + + // Reading from a binary file + ifstream inFile("example.bin", ios::binary); + if (inFile.is_open()) { + int num; + inFile.read(reinterpret_cast(&num), sizeof(num)); + cout << "Number read from file: " << num << endl; + inFile.close(); + } + + return 0; +} +``` + +**Output:** +``` +Number read from file: 12345 +``` + + +:::tip +- **Always Check File Open Status**: Before performing any file operations, check if the file was successfully opened. +- **Close Files Properly**: Ensure files are closed after operations to avoid data loss and free system resources. +- **Use File Modes Appropriately**: Choose the correct file mode for your operations to prevent unintended behavior. +- **Error Handling**: Implement proper error handling for file operations to manage issues like file not found or access denied. +::: \ No newline at end of file diff --git a/courses/C++ /intermediate-level/OOPS/Intro-and-concepts.md b/courses/C++ /intermediate-level/OOPS/Intro-and-concepts.md new file mode 100644 index 000000000..cd2f6db38 --- /dev/null +++ b/courses/C++ /intermediate-level/OOPS/Intro-and-concepts.md @@ -0,0 +1,293 @@ +--- +id: lesson-1 +title: "Object-Oriented Programming(OOP)" +sidebar_label: Introduction & Concept +sidebar_position: 1 +description: "Learn Object-Oriented Programming" +tags: [courses,intermediate-level,React Native,Introduction] +--- + + + +#### Introduction to OOP +Object-Oriented Programming (OOP) is a programming paradigm that uses "objects" to design applications and programs. It is based on several key concepts, including: + +- **Encapsulation**: Bundling data and methods that operate on the data within one unit, such as a class. +- **Inheritance**: Mechanism to create a new class using the properties and methods of an existing class. +- **Polymorphism**: Ability to process objects differently based on their data type or class. +- **Abstraction**: Hiding the complex implementation details and showing only the necessary features of an object. + +### Flowchart +```mermaid +graph TD; + A[Start] --> B[Define Class]; + B --> C{Member Functions}; + C --> D[Constructors]; + C --> E[Destructors]; + C --> F[Overloading]; + C --> G[Inheritance]; + C --> H[Polymorphism]; + D --> I[Create Object]; + E --> I; + F --> I; + G --> I; + H --> I; + I --> J[Use Member Functions]; + J --> K[End]; +``` + +#### Classes and Objects + +A **class** is a blueprint for creating objects, providing initial values for state (member variables) and implementations of behavior (member functions or methods). + +An **object** is an instance of a class. + +```cpp +#include +using namespace std; + +class Car { +public: + // Member variables + string brand; + string model; + int year; + + // Member functions + void displayInfo() { + cout << "Brand: " << brand << endl; + cout << "Model: " << model << endl; + cout << "Year: " << year << endl; + } +}; + +int main() { + // Creating an object of Car class + Car car1; + car1.brand = "Toyota"; + car1.model = "Corolla"; + car1.year = 2020; + + // Accessing member function + car1.displayInfo(); + + return 0; +} +``` + +**Output:** +``` +Brand: Toyota +Model: Corolla +Year: 2020 +``` + +#### Constructors and Destructors + +A **constructor** is a special member function that is called when an object is instantiated. A **destructor** is called when an object is destroyed. + +```cpp +#include +using namespace std; + +class Car { +public: + string brand; + string model; + int year; + + // Constructor + Car(string b, string m, int y) { + brand = b; + model = m; + year = y; + } + + // Destructor + ~Car() { + cout << "Car object destroyed" << endl; + } + + void displayInfo() { + cout << "Brand: " << brand << endl; + cout << "Model: " << model << endl; + cout << "Year: " << year << endl; + } +}; + +int main() { + // Creating an object of Car class + Car car1("Toyota", "Corolla", 2020); + car1.displayInfo(); + + return 0; +} +``` + +**Output:** +``` +Brand: Toyota +Model: Corolla +Year: 2020 +Car object destroyed +``` + +#### Member Functions + +Member functions are functions defined inside a class and used to perform operations on the member variables of the class. + +```cpp +class Car { +public: + string brand; + string model; + int year; + + // Member function to set car details + void setDetails(string b, string m, int y) { + brand = b; + model = m; + year = y; + } + + // Member function to display car details + void displayInfo() { + cout << "Brand: " << brand << endl; + cout << "Model: " << model << endl; + cout << "Year: " << year << endl; + } +}; +``` + +#### Inheritance + +Inheritance allows a class (derived class) to inherit attributes and methods from another class (base class). + +```cpp +class Vehicle { +public: + string brand; + void honk() { + cout << "Beep beep!" << endl; + } +}; + +class Car : public Vehicle { +public: + string model; + int year; +}; + +int main() { + Car car1; + car1.brand = "Toyota"; + car1.model = "Corolla"; + car1.year = 2020; + car1.honk(); + return 0; +} +``` + +**Output:** +``` +Beep beep! +``` + +#### Polymorphism + +Polymorphism allows methods to do different things based on the object it is acting upon. + +**Function Overloading**: Multiple functions can have the same name with different parameters. + +```cpp +class Print { +public: + void display(int i) { + cout << "Integer: " << i << endl; + } + + void display(double d) { + cout << "Double: " << d << endl; + } + + void display(string s) { + cout << "String: " << s << endl; + } +}; +``` + +**Operator Overloading**: Giving additional meaning to C++ operators. + +```cpp +class Complex { +private: + float real; + float imag; + +public: + Complex() : real(0), imag(0) {} + Complex(float r, float i) : real(r), imag(i) {} + + Complex operator + (const Complex& obj) { + Complex temp; + temp.real = real + obj.real; + temp.imag = imag + obj.imag; + return temp; + } + + void display() { + cout << "Real: " << real << " Imaginary: " << imag << endl; + } +}; + +int main() { + Complex c1(3.5, 2.5), c2(1.5, 1.5); + Complex c3 = c1 + c2; // Using overloaded operator + c3.display(); + return 0; +} +``` + +**Output:** +``` +Real: 5 Imaginary: 4 +``` + +**Virtual Functions**: Functions that are defined in the base class and overridden in the derived class. + +```cpp +class Base { +public: + virtual void display() { + cout << "Base class display function" << endl; + } +}; + +class Derived : public Base { +public: + void display() override { + cout << "Derived class display function" << endl; + } +}; + +int main() { + Base* basePtr; + Derived d; + basePtr = &d; + basePtr->display(); // Calls Derived class display function + return 0; +} +``` + +**Output:** +``` +Derived class display function +``` + +:::tip +- **Encapsulation**: Use encapsulation to protect the integrity of your data by hiding internal implementation details and exposing only necessary functionalities. +- **Inheritance**: Inheritance helps in reusing existing code and extending functionalities. Use it to create a hierarchy of classes. +- **Polymorphism**: Polymorphism provides flexibility by allowing methods to operate differently based on the objects they act upon. +- **Constructors and Destructors**: Always initialize objects properly using constructors and clean up resources using destructors to avoid memory leaks. +- **Practice**: Regularly practice writing and refactoring OOP code to better understand and utilize these concepts effectively. +::: \ No newline at end of file diff --git a/courses/C++ /intermediate-level/OOPS/_category_.json b/courses/C++ /intermediate-level/OOPS/_category_.json new file mode 100644 index 000000000..dd886fe66 --- /dev/null +++ b/courses/C++ /intermediate-level/OOPS/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "OOPS", + "position": 1, + "link": { + "type": "generated-index", + "description": "Learn OOPS concept in C++." + } + } \ No newline at end of file diff --git a/courses/C++ /intermediate-level/Templates/_category_.json b/courses/C++ /intermediate-level/Templates/_category_.json new file mode 100644 index 000000000..1d6616e60 --- /dev/null +++ b/courses/C++ /intermediate-level/Templates/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Templates", + "position": 4, + "link": { + "type": "generated-index", + "description": "Learn Templates in C++." + } + } \ No newline at end of file diff --git a/courses/C++ /intermediate-level/Templates/intro.md b/courses/C++ /intermediate-level/Templates/intro.md new file mode 100644 index 000000000..e4194a908 --- /dev/null +++ b/courses/C++ /intermediate-level/Templates/intro.md @@ -0,0 +1,92 @@ +--- +id: lesson-1 +title: "Templates in C++" +sidebar_label: Templates +sidebar_position: 1 +description: "Learn Templates in C++" +tags: [courses,intermediate-level,React Native,Introduction] +--- + + +Templates allow writing generic and reusable code that works with any data type. This is a powerful feature in C++ for creating flexible and type-safe functions and classes. + +#### Introduction to Templates + +Templates are used to create functions or classes that work with any data type. They are defined with the `template` keyword. + +#### Flowchart +```mermaid +graph TD; + A[Start] --> B[Define template]; + B --> C{Function or Class?}; + C -- Function --> D[Define function template]; + C -- Class --> E[Define class template]; + D --> F[Use function template]; + E --> G[Use class template]; + F --> H[Specialize template if needed]; + G --> H; + H --> I[End]; +``` + +#### Function Templates + +Function templates enable creating a single function that can operate on different data types. + +##### Example: Function Template +```cpp +#include +using namespace std; + +template +T add(T a, T b) { + return a + b; +} + +int main() { + cout << "Addition of integers: " << add(3, 4) << endl; + cout << "Addition of doubles: " << add(3.5, 4.5) << endl; + return 0; +} +``` + +**Output:** +``` +Addition of integers: 7 +Addition of doubles: 8 +``` + +#### Class Templates + +Class templates allow defining a blueprint for classes that can operate on any data type. + +##### Example: Class Template +```cpp +#include +using namespace std; + +template +class Box { +private: + T value; +public: + Box(T v) : value(v) {} + T getValue() { + return value; + } +}; + +int main() { + Box intBox(123); + Box strBox("Hello"); + + cout << "Integer value: " << intBox.getValue() << endl; + cout << "String value: " << strBox.getValue() << endl; + return 0; +} +``` + +**Output:** +``` +Integer value: 123 +String value: Hello +``` \ No newline at end of file diff --git a/courses/C++ /intermediate-level/Templates/specification.md b/courses/C++ /intermediate-level/Templates/specification.md new file mode 100644 index 000000000..c7fd5fe53 --- /dev/null +++ b/courses/C++ /intermediate-level/Templates/specification.md @@ -0,0 +1,62 @@ +--- +id: lesson-2 +title: "Template Specialization" +sidebar_label: Template Specialization +sidebar_position: 2 +description: "Learn Template Specialization in C++" +tags: [courses,intermediate-level,React Native,Introduction] +--- + + +Template specialization allows customizing the behavior of a template for a specific data type. + +##### Example: Template Specialization +```cpp +#include +using namespace std; + +template +class Box { +private: + T value; +public: + Box(T v) : value(v) {} + T getValue() { + return value; + } +}; + +// Specialization for string type +template <> +class Box { +private: + string value; +public: + Box(string v) : value(v) {} + string getValue() { + return "String value: " + value; + } +}; + +int main() { + Box intBox(123); + Box strBox("Hello"); + + cout << "Integer value: " << intBox.getValue() << endl; + cout << strBox.getValue() << endl; + return 0; +} +``` + +**Output:** +``` +Integer value: 123 +String value: Hello +``` + +:::tip +- **Use Templates for Reusability**: Templates are ideal for creating functions and classes that can work with any data type. +- **Template Specialization**: Use template specialization to handle specific data types differently if needed. +- **Type Safety**: Templates provide type safety, ensuring that the operations performed are valid for the data type. +- **Compile-Time Errors**: Many template-related errors are caught at compile time, reducing runtime errors. +::: \ No newline at end of file diff --git a/courses/C++ /intermediate-level/_category_.json b/courses/C++ /intermediate-level/_category_.json new file mode 100644 index 000000000..a7471a0cc --- /dev/null +++ b/courses/C++ /intermediate-level/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "Intermediate Level", + "position": 3, + "link": { + "type": "generated-index", + "description": "Learn Intermediate C++ Language Techniques." + } + } \ No newline at end of file diff --git a/courses/C++/Overview.md b/courses/C++/Overview.md new file mode 100644 index 000000000..e5d2f1970 --- /dev/null +++ b/courses/C++/Overview.md @@ -0,0 +1,84 @@ +--- +title: C++ Language Course Outline +sidebar_label: Course Overview +sidebar_position: 1 +description: C++ Language Course Outline. +tags: [courses,C++,Overview] +--- + +#### Beginner Level + +**1. Introduction to C Programming** + - History of C + - Setting up the development environment + +**2. Basic Syntax and Structure** + - Structure of a C program + - Input and output operations + +**3. Operators and Expressions** + - operators + +**4. Control Flow** + - Conditional statements (if, if-else, nested if,switch) + - Loops (for, while, do-while) + +**5. Functions** + - Defining and declaring functions + - Recursion & Scope and lifetime of variables + +**6. Arrays and Strings** + - Introduction to arrays + - String handling and manipulation + +**7. Pointers** + - Introduction to pointers + - Pointer to pointer + +**8. Structures and Unions** + - Defining and using structures + - Introduction to unions + +#### Intermediate Level + +**1. Object-Oriented Programming (OOP)** + - Introduction to OOP & Concepts + +**2. Dynamic Memory Allocation** + - Introduction to dynamic memory allocation + - Memory management techniques + +**3. File Handling** + - Introduction to file handling + - Working with binary files + +**4. Templates** + - Introduction to templates + - Template specialization + +**5. Exception Handling** + - Introduction to exception handling + - Creating custom exceptions + +#### Advanced Level + +**1. Advanced OOP Concepts** + - Abstract classes and interfaces + - RTTI (Run-Time Type Information) + +**2. Advanced Memory Management** + - Memory pools + - Custom allocators + +**3. Multithreading and Concurrency** + - Introduction to multithreading + - Avoiding race conditions and deadlocks + +**4. Network Programming** + - Introduction to network programming + - Basic TCP/IP communication + +**5. Advanced File Handling** + - File locking mechanisms + - Working with memory-mapped files + \ No newline at end of file diff --git a/courses/C++/_category_.json b/courses/C++/_category_.json new file mode 100644 index 000000000..f3510a3aa --- /dev/null +++ b/courses/C++/_category_.json @@ -0,0 +1,8 @@ +{ + "label": "C++ Language", + "position": 13, + "link": { + "type": "generated-index", + "description": "Learn C++ Language." + } + } \ No newline at end of file diff --git a/src/data/courses/index.tsx b/src/data/courses/index.tsx index 01618d7b2..62e434705 100644 --- a/src/data/courses/index.tsx +++ b/src/data/courses/index.tsx @@ -355,13 +355,13 @@ const courses = [ "link": "/courses/category/c-language" }, { - "id": 41, + "id": 41, "title": "React Native", "description": "This course is for absolute beginners who want to learn React Native.", "category": "react-native", "imageUrl": "/img/svg/developer_activity.svg", "author": "Ajay Dhangar", - "link": "/courses/category/react-native" + "link": "/courses/category/react-native" } ];