Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] : Add 3-day Data types added #86

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 115 additions & 0 deletions docs/day-03/Basic_syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
---
sidebar_position: 1
title: "Basic C++ Syntax Explanation and Examples"
sidebar_label: "Basic C++ Syntax"
slug: Basic C++ Syntax Explanation and Examples
---


## 1. Comments:

Comments are used to document code for better understanding. They are ignored by the compiler.

### Examples:

```cpp
// This is a single-line comment

/*
This is a multi-line comment
*/

```
## 2. Main Function:

The `main()` function is the entry point of any C++ program. It's where the execution of the program begins.

### Example:
```cpp
#include <iostream>

int main() {
std::cout << "Hello, World!";
return 0;
}

```

## 3. Data Types:

C++ supports various data types for different kinds of values.

### Example:

```cpp
int age = 25; // Integer
float pi = 3.14; // Floating point number
char grade = 'A'; // Character
bool isTrue = true; // Boolean (true/false)


```

## 4. Variables:

Variables are used to store data values.

### Example:

```cpp
int x = 5; // Declare and initialize an integer variable
float y = 3.14; // Declare and initialize a floating point variable
```

## 5. Control Structures:

Control structures help in controlling the flow of the program.

### Example:

```cpp
if (x > 0) {
// Code block executed if condition is true
} else {
// Code block executed if condition is false
}

while (x > 0) {
// Code block executed repeatedly while condition is true
}

for (int i = 0; i < 5; i++) {
// Code block executed repeatedly with incrementing i from 0 to 4
}

```
## 6. Functions:

Functions are blocks of code that perform a specific task.

### Example:

```cpp
int add(int a, int b) {
return a + b;
}

```
## 7. Classes:

Classes are user-defined data types that contain data members and member functions.

### Example:

```cpp
class Rectangle {
public:
int width;
int height;

int area() {
return width * height;
}
};

```
35 changes: 35 additions & 0 deletions docs/day-03/Comments_in_C++.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
sidebar_position: 3
title: "Comments in C++"
sidebar_label: "Comments in C++"
slug: Comments in C++
---

# Comments in C++

Comments in C++ are essential for documenting code and making it more understandable. There are two types of comments in C++:

## Single-line comments

These comments begin with `//` and continue until the end of the line. They are often used for short, inline explanations.

```cpp
// This is a single-line comment
int x = 5; // This is also a single-line comment
```
# Multi-line Comments in C++

Multi-line comments in C++ begin with `/*` and end with `*/`. They can span multiple lines and are often used for longer explanations or for temporarily disabling blocks of code.

```cpp
/* This is a multi-line comment
It can span multiple lines */
int y = 10;

/*
This is another example of a multi-line comment
that spans multiple lines
*/
```

Comments are ignored by the compiler and do not affect the execution of the program. They are purely for the benefit of developers to understand the code better. It's good practice to include comments to explain complex logic, algorithmic steps, or to provide context for future maintainers of the code.
59 changes: 59 additions & 0 deletions docs/day-03/Structure_of_a_C++ Program.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
sidebar_position: 2
title: "Structure of a C++ Program"
sidebar_label: "Structure of a C++ Program"
slug: Structure of a C++ Program
---


# Structure of a C++ Program

A typical C++ program consists of several parts:

## Preprocessor Directives

These are commands to the compiler and are preceded by a `#` symbol. Common preprocessor directives include `#include` for including header files and `#define` for defining constants.

## Main Function

Every C++ program must have a `main()` function, which serves as the entry point of the program. Execution of the program begins from here.

## Function Definitions

Additional functions may be defined to perform specific tasks within the program. These functions can be defined before or after the `main()` function.

## Header Files

C++ programs often use header files to declare functions, classes, and constants. These header files are included at the beginning of the program using the `#include` directive.

## Namespace

Namespace is used to avoid naming conflicts and to organize code into logical groups. Standard library elements are typically in the `std` namespace.

## Comments

Comments are used to document the code and improve its readability. They can be single-line (`//`) or multi-line (`/* */`).

# Example C++ Program

Here's an example of a simple C++ program that calculates the factorial of a number:

```cpp
#include <iostream>

// Function to calculate factorial
int factorial(int n) {
if (n == 0 || n == 1)
return 1;
else
return n * factorial(n - 1);
}

int main() {
int num;
std::cout << "Enter a number: ";
std::cin >> num;
std::cout << "Factorial of " << num << " is: " << factorial(num) << std::endl;
return 0;
}
```
11 changes: 6 additions & 5 deletions docs/day-03/_category_.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"label": "Day 03",
"position": 4,
"link": {
"type": "generated-index"
"label": "Day 03",
"position": 4,
"link": {
"type": "generated-index"
}
}
}
95 changes: 0 additions & 95 deletions docs/day-03/cpp-type-modifiers.md

This file was deleted.

Loading