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

Addition content in day1 and day2 #54

Closed
wants to merge 1 commit into from
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
39 changes: 39 additions & 0 deletions docs/day-01/getting-started-with-cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,50 @@ slug: getting-started-with-cpp

import CustomTag from '@site/src/components/TagsComponents/CustomTag';

C++ is a general-purpose programming language and is widely used nowadays for competitive programming. It has imperative, object-oriented, and generic programming features.
C++ runs on lots of platforms like Windows, Linux, Unix, Mac, etc. Before we start programming with C++. We will need an environment to be set up on our local computer to compile and run our C++ programs successfully. If you do not want to set up a local environment you can also use online IDEs for compiling your program.

TASK:

1. Installation Process Step By Step

## Windows:
### Visual Studio:
If you’re using Windows, you can install Visual Studio, which provides a powerful IDE for C++ development. Follow these steps:
- Make sure your computer meets the system requirements for Visual Studio 2022.
- Apply the latest Windows updates.Free up space on your system drive.
- Download the Visual Studio bootstrapper file from the Visual Studio download page.
### MinGW (Minimalist GNU for Windows):
- Alternatively, you can use MinGW to install GCC (GNU Compiler Collection) for C++ development. Here’s how:
- Download MinGW from the official website.
- Install MinGW and choose the components you need (e.g., g++, gdb).Set up the path environment variable to include the MinGW bin folder
## Mac OS:
To install GCC on Mac OS, follow these steps:
- Open Terminal.
- Install Xcode Command Line Tools (if not already installed) by running: xcode-select --install.
- Install Homebrew (a package manager for Mac) by following the instructions on the Homebrew website.
- Install GCC using Homebrew: brew install gcc.
## Linux:
On Linux, you can easily install GCC using your package manager. For example:
- On Ubuntu/Debian: sudo apt-get install g++
- On Fedora: sudo dnf install gcc-c++
- On CentOS/RHEL: sudo yum install gcc-c++
2. How to run a CPP program
### Write Your C++ Code:
Open a text editor (such as Notepad, Visual Studio Code, or any other code editor).
Write your C++ code. Make sure it has the .cpp extension (e.g., my_program.cpp).
3. How to compile a CPP program
### Visual Studio Code (VS Code):
If you’re using VS Code, you can set up your C++ environment as follows:
- Install the C/C++ extension for VS Code by searching for “C++” in the Extensions view and selecting Install.
- Make sure you have a C++ compiler installed. You can use MinGW on Windows, GCC on Linux, or Clang on macOS.
Write your C++ code in a .cpp file.
- Open a terminal in VS Code and navigate to the directory containing your .cpp file.
#### Compile your code using the appropriate compiler command:
- For MinGW: g++ -o my_program my_program.cpp
- For GCC: g++ -o my_program my_program.cpp
- For Clang: clang++ -o my_program my_program.cpp
- Run your compiled program: ./my_program1.

IMAGE FILE:
![30-days-of-cpp-introduction](../../static/img/day-01/get-started-with-cpp.png)
6 changes: 4 additions & 2 deletions docs/day-01/history-of-cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ slug: /history-of-cpp

## History of CPP

Welcome to the world of C++ programming! C++ is a powerful and versatile programming language widely used for developing various applications, ranging from system software, games, and embedded systems to high-performance applications.
The C++ language is an object-oriented programming language & is a combination of both low-level & high-level language – a Middle-Level Language. The programming language was created, designed & developed by a Danish Computer Scientist – Bjarne Stroustrup at Bell Telephone Laboratories (now known as Nokia Bell Labs) in Murray Hill, New Jersey. As he wanted a flexible & a dynamic language which was similar to C with all its features, but with additionality of active type checking, basic inheritance, default functioning argument, classes, inlining, etc. and hence C with Classes (C++) was launched.

C++ was initially known as “C with classes, ” and was renamed C++ in 1983. ++ is shorthand for adding one to variety in programming; therefore C++ roughly means that “one higher than C.”

## What is C++?

C++ is an extension of the C programming language with added features such as object-oriented programming (OOP) capabilities. It provides a robust set of tools and allows low-level memory manipulation while also supporting high-level abstractions. Known for its efficiency and performance, C++ is often chosen for applications that require speed and resource management.
C++ is an extension of the C programming language with added features such as object-oriented programming (OOP) capabilities. It provides a robust set of tools and allows low-level memory manipulation while also supporting high-level abstractions. Known for its efficiency and performance, C++ is often chosen for applications that require speed and resource management.This language allows developers to write clean and efficient code for large applications and software development, game development, and operating system programming. It is an expansion of the C programming language to include Object Oriented Programming(OOPs) and is used to develop programs for computers. This C++ Tutorial will cover all the basic to advanced topics of C++ like C++ basics, C++ functions, C++ classes, OOPs and STL concepts.

![30-days-of-cpp-introduction](../../static/img/day-01/history-of-cpp.png)

Expand Down
15 changes: 11 additions & 4 deletions docs/day-01/introduction-to-cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,20 @@ import CustomTag from '@site/src/components/TagsComponents/CustomTag';

## Introduction to C++

Welcome to the world of C++ <CustomTag bgcolor="#e9eaff">programming </CustomTag> programming! C++ is a powerful and versatile programming language widely used for developing various applications, ranging from system software, games, and embedded systems to high-performance applications.
C++ is a general-purpose programming language that was developed as an enhancement of the C language to include object-oriented paradigm. It is an imperative and a compiled language.C++ is a powerful and versatile programming language that is widely used for a range of applications and is well-suited for both low-level system programming and high-level application development.C++ is a middle-level language rendering it the advantage of programming low-level (drivers, kernels) and even higher-level applications (games, GUI, desktop apps etc.). The basic syntax and code structure of both C and C++ are the same.

![30-days-of-cpp-introduction](../../static/img/day-01/introduction-to-cpp.png)
#### Some of the key points to note about the programming language are as follows:

## What is C++?
- Simple: It is a simple language in the sense that programs can be broken down into logical units and parts, has a rich library support and a variety of data-types.
- Machine Independent but Platform Dependent: A C++ executable is not platform-independent (compiled programs on Linux won’t run on Windows), however they are machine independent.
- Mid-level language: It is a mid-level language as we can do both systems-programming (drivers, kernels, networking etc.) and build large-scale user applications (Media Players, Photoshop, Game Engines etc.)
- Rich library support: Has a rich library support (Both standard ~ built-in data structures, algorithms etc.) as well 3rd party libraries (e.g. Boost libraries) for fast and rapid development.
- Speed of execution: C++ programs excel in execution speed. Since, it is a compiled language, and also hugely procedural. Newer languages have extra in-built default features such as garbage-collection, dynamic typing etc. which slow the execution of the program overall. Since there is no additional processing overhead like this in C++, it is blazing fast.
- Pointer and direct Memory-Access: C++ provides pointer support which aids users to directly manipulate storage address. This helps in doing low-level programming (where one might need to have explicit control on the storage of variables).
- Object-Oriented: One of the strongest points of the language which sets it apart from C. Object-Oriented support helps C++ to make maintainable and extensible programs. i.e. Large-scale applications can be built. Procedural code becomes difficult to maintain as code-size grows.
- Compiled Language: C++ is a compiled language, contributing to its speed.

C++ is an extension of the C programming language with added features such as object-oriented programming (OOP) capabilities. It provides a robust set of tools and allows low-level memory manipulation while also supporting high-level abstractions. Known for its efficiency and performance, C++ is often chosen for applications that require speed and resource management.
![30-days-of-cpp-introduction](../../static/img/day-01/introduction-to-cpp.png)

## Key Features of C++

Expand Down
48 changes: 47 additions & 1 deletion docs/day-02/comments-in-cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,58 @@ slug: comment-in-cpp
TASK:

1. What is Comment in C++?
- A comment in C++ is a programmer-readable note that is inserted directly into the source code of a program.
- Comments are ignored by the compiler and are meant for the programmer’s use only.
- They serve as a form of in-code documentation, helping developers understand the purpose, logic, or explanation behind specific code lines
2. Why do we use comments in C++?
Comments serve several purposes:
- Explanation: They explain the code, making it more readable and understandable for other programmers.
- Debugging: Comments can be useful for debugging by providing context or temporarily disabling code segments.
- Documentation: They document algorithms, variable purposes, or clarify unclear code segments.
- Collaboration: Comments help other developers understand your code when collaborating on projects-
3. Write a simple program to demonstrate the use of comments in C++.
```cpp
#include <iostream>
using namespace std;

int main() {
// This is a single-line comment
cout << "Hello, World!"; // Another single-line comment
return 0;
}
```
In this program, we use both single-line comments (//) to explain the code and prevent execution of those comment lines
4. Types of comments in C++
i. Single Line Comment
- Starts with // and applies to a single line only.
- Compiler ignores any text after //.
Example:
```
// This is a single-line comment
```
ii. Multi Line Comment
- Starts with /* and ends with */.
- Can span multiple lines but cannot be nested.
- Any text between /* and */ is ignored by the compiler.
Example:
```
/* This is a multi-line comment
spanning multiple lines */
```
iii. Documentation Comment

- Used for documenting functions, classes, and their parameters.
- Typically starts with /** and ends with */.
- Contains additional information for tools like Doxygen.
- Example (not standard C++):
```
/**
* @param x integer value to add
* @param y integer value to add
* @return addition of these two parameters
*/
int add(int x, int y) {
return x + y;
}
```
IMAGE FILE:
![comment-in-cpp](../../static/img/day-02/comment-in-cpp.png)
30 changes: 26 additions & 4 deletions docs/day-02/first-cpp-program.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,32 @@ slug: first-cpp-program

TASK:

1. Write a simple "Hello, World!" program in C++.
2. Output of the program.
3. Explain the code line by line.
4. Explain Basic Structure of C++ Program.
### 1. Write a simple "Hello, World!" program in C++.
```cpp
#include <iostream>

int main() {
std::cout << "Hello, World!";
return 0;
}
```
### 2. Output of the program.
When you run this program, it will display the following output:
```
Hello, World!
```
### 3. Explain the code line by line.
- #include <iostream>: This line includes the standard input/output stream library (iostream). It allows us to use the std::cout (output) and std::cin (input) streams.
- int main(): This is the main function where program execution begins. It has an integer return type (int) because it returns an exit status to the operating system (usually 0 for successful execution).
- {}: The curly braces define the scope of the main function. Everything inside these braces belongs to the main function.
- std::cout << "Hello, World!";: This line uses the std::cout stream to print the text “Hello, World!” to the console. The << operator is used for output.
- return 0;: The return statement indicates that the program has completed successfully. The value 0 is returned to the operating system.
### 4. Explain Basic Structure of C++ Program.
- Preprocessor Directives: These lines start with # and include necessary libraries or perform other preprocessing tasks (e.g., #include).
- Function Definitions: The main function is the entry point of the program. Other functions can be defined as needed.
- Statements: Inside functions, we write statements (like the std::cout line) that perform actions.
- Comments: Comments (single-line or multi-line) help explain the code to other programmers.


IMAGE FILE:
![first-programme-in-cpp](../../static/img/day-02/first-program.png)
85 changes: 78 additions & 7 deletions docs/day-02/keywords-identifiers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,84 @@ slug: keywords-and-identifiers-in-cpp

TASK:

1. What is Keywords and Identifiers in C++?
2. Why do we use Keywords and Identifiers in C++?
3. Write a simple program to demonstrate the use of Keywords and Identifiers in C++.
4. List of Keywords in C++
5. Rules for defining Identifiers in C++
6. Examples of Identifiers in C++
7. Difference between Keywords and Identifiers in C++
### 1. What is Keywords and Identifiers in C++?
## Keywords:
- Keywords are predefined words that have special meanings to the C++ compiler.
- They are part of the language syntax and serve specific purposes.
- For example, int, if, while, and class are keywords.
- Keywords cannot be used as identifiers (variable names, function names, etc.) because they already have predefined meanings12.
## Identifiers:
- Identifiers are unique names given to variables, functions, classes, and other entities by the programmer.
- They help us create meaningful and descriptive names for program elements.
- Examples of identifiers: money, accountBalance, studentAge, and calculateSum.
### Rules for naming identifiers:
- Can consist of letters (A-Z or a-z), digits (0-9), and underscores (_).
- Must begin with a letter or an underscore.
- Are case-sensitive (e.g., Num and num are different).
- Cannot use reserved keywords as identifiers.
- Must be unique within their namespace (e.g., no two variables with the same name in the same scope)31.
### 2. Why do we use Keywords and Identifiers in C++?
#### we use keywords:
- Syntax: Keywords define the syntax and structure of the language. They help the compiler understand the code.
- Reserved Meanings: Each keyword has a reserved purpose (e.g., if for conditional statements, while for loops, class for defining classes).
- Consistency: Using keywords ensures consistency across different C++ programs.
- Efficiency: Keywords allow the compiler to optimize code execution.
- Readability: They make the code more readable and self-explanatory.
#### we use identifiers:
- Descriptive Names: Identifiers give meaningful names to program entities (e.g., totalAmount, calculateAverage).
- Readability: Well-chosen identifiers enhance code readability for both programmers and collaborators.
- Avoid Magic Numbers: Instead of using raw numbers (e.g., 42), we use identifiers (e.g., MAX_SCORE) to make the code self-documenting.
- Modularity: Identifiers help organize code into logical units (functions, classes, etc.).
- Avoid Confusion: Descriptive identifiers prevent confusion and improve maintainability.

### 3. Write a simple program to demonstrate the use of Keywords and Identifiers in C++.
```cpp
#include <iostream>
using namespace std;

// Example of identifiers
class Car_24 {
string Brand;
string model;
int year;
};

void calculateSum(int a, int b) {
int _sum = a + b;
cout << "The sum is: " << _sum << endl;
}

int main() {
// Identifiers used as variable names
int studentAge = 20;
double accountBalance = 1000.50;
string student_Name = "Karan";

calculateSum(2, 10);
return 0;
}
```
```
The sum is: 12
```
### 4. List of Keywords in C++
Here are some commonly used C++ keywords:

if, else, while, for, switch, return, class, int, double, void, const, static, public, private, and many more
### 5. Rules for defining Identifiers in C++
Remember these rules when defining identifiers:

- Begin with a letter or an underscore.
- Consist of letters, digits, and underscores.
- Avoid using reserved keywords as identifiers.
- Be case-sensitive (e.g., myVar and MyVar are different).
### 6. Examples of Identifiers in C++
- Valid Identifiers: totalPoints, list_1, floatNumber
- Invalid Identifiers: 1list, n_float, float (because it’s a keyword)
### 7. Difference between Keywords and Identifiers in C++
- Keywords are predefined words with specific meanings in the language.
- Identifiers are user-defined names for program elements.
- Keywords cannot be used as identifiers

IMAGE FILE:
![keywords-and-identifiers-in-cpp](../../static/img/day-02/keywords-in-cpp.png)