# Software

# C++ Variables, Literals and Constants

In this tutorial, we will learn about variables, literals, and constants in C++ with the help of examples.

*Content from [https://www.programiz.com/cpp-programming/variables-literals.](https://www.programiz.com/cpp-programming/variables-literals)*

## C++ Variables

In programming, a variable is a container (storage area) to hold data.

To indicate the storage area, each variable should be given a unique name (identifier). For example,

```
int age = 14;

```

Here, <var>age</var> is a variable of the `int` data type, and we have assigned an integer value 14 to it.

**Note:** The `int` data type suggests that the variable can only hold integers. Similarly, we can use the `double` data type if we have to store decimals and exponentials.

We will learn about all the data types in detail in the next tutorial.

The value of a variable can be changed, hence the name **variable**.

```
int age = 14;   // age is 14
age = 17;       // age is 17

```

<div class="node node-cpp-tutorial clearfix" id="bkmrk-"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>### Rules for naming a variable

<div class="node node-cpp-tutorial clearfix" id="bkmrk-a-variable-name-can-"><div class="node node-cpp-tutorial clearfix"><div class="content">- A variable name can only have alphabets, numbers, and the underscore `_`.
- A variable name cannot begin with a number.
- It is a preferred practice to begin variable names with a lowercase character. For example, <var>name</var> is preferable to <var>Name</var>.
- A variable name cannot be a [keyword](https://www.programiz.com/cpp-programming/keywords-identifiers). For example, `int` is a keyword that is used to denote integers.
- A variable name can start with an underscore. However, it's not considered a good practice.

</div></div></div>**Note:** We should try to give meaningful names to variables. For example, <var>first\_name</var> is a better variable name than <var>fn</var>.

<div class="node node-cpp-tutorial clearfix" id="bkmrk--0"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>## C++ Literals

Literals are data used for representing fixed values. They can be used directly in the code. For example: `1`, `2.5`, `'c'` etc.

Here, `1`, `2.5` and `'c'` are literals. Why? You cannot assign different values to these terms.

Here's a list of different literals in C++ programming.

<div class="node node-cpp-tutorial clearfix" id="bkmrk--1"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>### Integers

An integer is a numeric literal(associated with numbers) without any fractional or exponential part. There are three types of integer literals in C programming:

<div class="node node-cpp-tutorial clearfix" id="bkmrk-decimal-%28base-10%29-oc"><div class="node node-cpp-tutorial clearfix"><div class="content">- decimal (base 10)
- octal (base 8)
- hexadecimal (base 16)

</div></div></div>For example:

```
Decimal: 0, -9, 22 etc
Octal: 021, 077, 033 etc
Hexadecimal: 0x7f, 0x2a, 0x521 etc
```

In C++ programming, octal starts with a `0`, and hexadecimal starts with a `0x`.

<div class="node node-cpp-tutorial clearfix" id="bkmrk--2"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>### Floating-point Literals

A floating-point literal is a numeric literal that has either a fractional form or an exponent form. For example:

<div class="node node-cpp-tutorial clearfix" id="bkmrk--4"><div class="node node-cpp-tutorial clearfix"><div class="content"><div class="block-inject block-inject-1" id="bkmrk--8"><div class="pgAdWrapper"><div id="bkmrk--9"><div id="bkmrk--10"></div></div></div></div><div class="clearfix">  
</div></div></div></div>`-2.0`

`0.0000234`

`-0.22E-5`

**Note:** `E-5 = 10<sup>-5</sup>`

<div class="node node-cpp-tutorial clearfix" id="bkmrk--5"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>### Characters

A character literal is created by enclosing a single character inside single quotation marks. For example: `'a'`, `'m'`, `'F'`, `'2'`, `'}'` etc.

<div class="node node-cpp-tutorial clearfix" id="bkmrk--6"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>### Escape Sequences

Sometimes, it is necessary to use characters that cannot be typed or has special meaning in C++ programming. For example, newline (enter), tab, question mark, etc.

In order to use these characters, escape sequences are used.

<div class="node node-cpp-tutorial clearfix" id="bkmrk-escape-sequences-cha"><div class="node node-cpp-tutorial clearfix"><div class="content"><div class="table-responsive"><table><tbody><tr><th>Escape Sequences</th><th>Characters</th></tr><tr><td>`\b`</td><td>Backspace</td></tr><tr><td>`\f`</td><td>Form feed</td></tr><tr><td>`\n`</td><td>Newline</td></tr><tr><td>`\r`</td><td>Return</td></tr><tr><td>`\t`</td><td>Horizontal tab</td></tr><tr><td>`\v`</td><td>Vertical tab</td></tr><tr><td>`\\`</td><td>Backslash</td></tr><tr><td>`\'`</td><td>Single quotation mark</td></tr><tr><td>`\"`</td><td>Double quotation mark</td></tr><tr><td>`\?`</td><td>Question mark</td></tr><tr><td>`\0`</td><td>Null Character</td></tr></tbody></table>

</div>---

</div></div></div>### String Literals

A string literal is a sequence of characters enclosed in double-quote marks. For example:

<div class="node node-cpp-tutorial clearfix" id="bkmrk-%22good%22-string-consta"><div class="node node-cpp-tutorial clearfix"><div class="content"><div class="table-responsive"><table><tbody><tr><td>`"good"`</td><td>string constant</td></tr><tr><td>`""`</td><td>null string constant</td></tr><tr><td>`" "`</td><td>string constant of six white space</td></tr><tr><td>`"x"`</td><td>string constant having a single character</td></tr><tr><td>`"Earth is round\n"`</td><td>prints string with a newline</td></tr></tbody></table>

</div></div></div></div>We will learn about strings in detail in the C++ string tutorial.

<div class="node node-cpp-tutorial clearfix" id="bkmrk--7"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>## C++ Constants

In C++, we can create variables whose value cannot be changed. For that, we use the `const` keyword. Here's an example:

```
const int LIGHT_SPEED = 299792458;
LIGHT_SPEED = 2500 // Error! LIGHT_SPEED is a constant.

```

Here, we have used the keyword `const` to declare a constant named `LIGHT_SPEED`. If we try to change the value of `LIGHT_SPEED`, we will get an error.

A constant can also be created using the `#define` preprocessor directive. We will learn about it in detail in the C++ Macros tutorial.

# C++ Data Types

In this tutorial, we will learn about basic data types such as int, float, char, etc. in C++ programming with the help of examples.

In C++, data types are declarations for variables. This determines the type and size of data associated with variables. For example,

```C++
int age = 13;
```

Here, <var>age</var> is a variable of type `int`. Meaning, the variable can only store integers of either 2 or 4 bytes.

<div class="node node-cpp-tutorial clearfix" id="bkmrk-"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>## C++ Fundamental Data Types

The table below shows the fundamental data types, their meaning, and their sizes (in bytes):

<div class="node node-cpp-tutorial clearfix" id="bkmrk-data-type-meaning-si"><div class="node node-cpp-tutorial clearfix"><div class="content"><div class="table-responsive"><table><tbody><tr><th>Data Type</th><th>Meaning</th><th>Size (in Bytes)</th></tr><tr><td>`int`</td><td>Integer</td><td>2 or 4</td></tr><tr><td>`float`</td><td>Floating-point</td><td>4</td></tr><tr><td>`double`</td><td>Double Floating-point</td><td>8</td></tr><tr><td>`char`</td><td>Character</td><td>1</td></tr><tr><td>`wchar_t`</td><td>Wide Character</td><td>2</td></tr><tr><td>`bool`</td><td>Boolean</td><td>1</td></tr><tr><td>`void`</td><td>Empty</td><td>0</td></tr></tbody></table>

</div></div></div></div>Now, let us discuss these fundamental data types in more detail.

<div class="node node-cpp-tutorial clearfix" id="bkmrk--0"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>### 1. C++ int

<div class="node node-cpp-tutorial clearfix" id="bkmrk-the%C2%A0int%C2%A0keyword-is-u"><div class="node node-cpp-tutorial clearfix"><div class="node node-cpp-tutorial clearfix"><div class="content">- The `int` keyword is used to indicate integers.
- Its size is usually 4 bytes. Meaning, it can store values from **-2147483648 to 2147483647**.
- For example,

</div></div></div></div>```C++
int salary = 85000;
```

<div class="node node-cpp-tutorial clearfix" id="bkmrk--1"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>### 2. C++ float and double

<div class="node node-cpp-tutorial clearfix" id="bkmrk-float%C2%A0and%C2%A0double%C2%A0are"><div class="node node-cpp-tutorial clearfix"><div class="node node-cpp-tutorial clearfix"><div class="content">- `float` and `double` are used to store floating-point numbers (decimals and exponentials).
- The size of `float` is 4 bytes and the size of `double` is 8 bytes. Hence, `double` has two times the precision of `float`. To learn more, visit C++ float and double.
- For example,

</div></div></div></div>```C++
float area = 64.74;
double volume = 134.64534;
```

As mentioned above, these two data types are also used for exponentials. For example,

```C++
double distance = 45E12    // 45E12 is equal to 45*10^12
```

<div class="node node-cpp-tutorial clearfix" id="bkmrk--2"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>### 3. C++ char

<div class="node node-cpp-tutorial clearfix" id="bkmrk-keyword%C2%A0char%C2%A0is-used"><div class="node node-cpp-tutorial clearfix"><div class="node node-cpp-tutorial clearfix"><div class="content">- Keyword `char` is used for characters.
- Its size is 1 byte.
- Characters in C++ are enclosed inside single quotes `' '`.
- For example,

</div></div></div></div>```C++
char test = 'h';
```

**Note:** In C++, an integer value is stored in a `char` variable rather than the character itself. To learn more, visit [C++ characters](https://www.programiz.com/cpp-programming/char-type).

<div class="node node-cpp-tutorial clearfix" id="bkmrk--3"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>### 4. C++ wchar\_t

<div class="node node-cpp-tutorial clearfix" id="bkmrk-wide-character%C2%A0wchar"><div class="node node-cpp-tutorial clearfix"><div class="node node-cpp-tutorial clearfix"><div class="content">- Wide character `wchar_t` is similar to the `char` data type, except its size is 2 bytes instead of 1.
- It is used to represent characters that require more memory to represent them than a single `char`.
- For example,

</div></div></div></div>```C++
wchar_t test = L'ם'  // storing Hebrew character;
```

Notice the letter L before the quotation marks.

<div class="node node-cpp-tutorial clearfix" id="bkmrk--5"><div class="node node-cpp-tutorial clearfix"><div class="content"><div class="block-inject block-inject-1" id="bkmrk--12"><div class="pgAdWrapper"><div id="bkmrk--13"><div id="bkmrk--14"></div></div></div></div><div class="clearfix">  
</div></div></div></div>**Note:** There are also two other fixed-size character types `char16_t` and `char32_t` introduced in C++11.

<div class="node node-cpp-tutorial clearfix" id="bkmrk--6"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>### 5. C++ bool

<div class="node node-cpp-tutorial clearfix" id="bkmrk-the%C2%A0bool%C2%A0data-type-h"><div class="node node-cpp-tutorial clearfix"><div class="node node-cpp-tutorial clearfix"><div class="content">- The `bool` data type has one of two possible values: `true` or `false`.
- Booleans are used in conditional statements and loops (which we will learn in later chapters).
- For example,

</div></div></div></div>```C++
bool cond = false;
```

<div class="node node-cpp-tutorial clearfix" id="bkmrk--7"><div class="node node-cpp-tutorial clearfix"><div class="content"><iframe height="500" src="https://www.youtube.com/embed/zB9RI8_wExo" width="100%"></iframe>

---

</div></div></div>### 6. C++ void

<div class="node node-cpp-tutorial clearfix" id="bkmrk-the%C2%A0void%C2%A0keyword-ind"><div class="node node-cpp-tutorial clearfix"><div class="content">- The `void` keyword indicates an absence of data. It means "nothing" or "no value".
- We will use void when we learn about functions and pointers.

</div></div></div>**Note:** We cannot declare variables of the `void` type.

<div class="node node-cpp-tutorial clearfix" id="bkmrk--8"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>#### Putting it all together

Run the following repl to see its results. Looking at the `main.cpp` file, a range of variables of different data types are declared at the top.

`cout` is used with the `+` operator to output the sum of two integers. `cout` is also used to display a message that includes the contents of the string variables, and lastly an if statement is used to present a message based on which letter is stored in the char variable.

##### Try doing each of the following, running the between each change:

1. Change the string variables to reflect your name
2. Change the values of the integers
3. Change the operator used in the output to `*`
4. Change the letter stored in the char variable to a grade you would like to receive
5. Change the integer variables to float, and assign decimal values.

<iframe height="500" src="https://replit.com/@ChesterWhitwell/C-variables-and-operators?lite=true" style="border:0;" width="100%"></iframe>

<div class="content" id="bkmrk--10">---

</div>## C++ Type Modifiers

We can further modify some of the fundamental data types by using type modifiers. There are 4 type modifiers in C++. They are:

<div class="node node-cpp-tutorial clearfix" id="bkmrk-signed-unsigned-shor"><div class="node node-cpp-tutorial clearfix"><div class="content">1. `signed`
2. `unsigned`
3. `short`
4. `long`

</div></div></div>We can modify the following data types with the above modifiers:

<div class="node node-cpp-tutorial clearfix" id="bkmrk-int-double-char"><div class="node node-cpp-tutorial clearfix"><div class="content">- `int`
- `double`
- `char`

---

</div></div></div>### C++ Modified Data Types List

<div class="node node-cpp-tutorial clearfix" id="bkmrk-data-type-size-%28in-b"><div class="node node-cpp-tutorial clearfix"><div class="content"><div class="table-responsive"><table><tbody><tr><th>Data Type</th><th>Size (in Bytes)</th><th>Meaning</th></tr><tr><td>`signed int`</td><td>4</td><td>used for integers (equivalent to `int`)</td></tr><tr><td>`unsigned int`</td><td>4</td><td>can only store positive integers</td></tr><tr><td>`short`</td><td>2</td><td>used for small integers (range **-32768 to 32767**)</td></tr><tr><td>`unsigned short`</td><td>2</td><td>used for small positive integers (range **0 to 65,535**)</td></tr><tr><td>`long`</td><td>at least 4</td><td>used for large integers (equivalent to `long int`)</td></tr><tr><td>`unsigned long`</td><td>4</td><td>used for large positive integers or 0 (equivalent to `unsigned` `long int`)</td></tr><tr><td>`long long`</td><td>8</td><td>used for very large integers (equivalent to `long long int`).</td></tr><tr><td>`unsigned long long`</td><td>8</td><td>used for very large positive integers or 0 (equivalent to `unsigned long long int`)</td></tr><tr><td>`long double`</td><td>12</td><td>used for large floating-point numbers</td></tr><tr><td>`signed char`</td><td>1</td><td>used for characters (guaranteed range **-127 to 127**)</td></tr><tr><td>`unsigned char`</td><td>1</td><td>used for characters (range **0 to 255**)</td></tr></tbody></table>

</div></div></div></div>Let's see a few examples.

```C++
long b = 4523232;
long int c = 2345342;
long double d = 233434.56343;
short d = 3434233; // Error! out of range
unsigned int a = -5;    // Error! can only store positive numbers or 0
```

<div class="node node-cpp-tutorial clearfix" id="bkmrk--11"><div class="node node-cpp-tutorial clearfix"><div class="content">---

</div></div></div>## Derived Data Types

Data types that are derived from fundamental data types are derived types. For example: arrays, pointers, function types, structures, etc.

We will learn about these derived data types in later tutorials.

# data science topis

**Topic : Introduction to data science**

- <div>Data scientist skills</div>
- <div>Data scientist responsibilities </div>
- <div>data vs information</div>

**Topic : Presenting data science projects**

- Planning
- performing
- Data visualization
- Data analytics

**Topic : Ethics of data science**

- Code of ethics
- Privacy, transparency and security
- Consent
- Fairness and Algorithms

**Topic : Data manipulation**

- What is data manipulation?
- Tools
- Techniques

**Topic : Artifical intelegence**

- AI history
- Three phases of AI
- Learning processes
- Strong AI vs. weak AI
- AI ethics
- Case studies
    
    
    - business
    - education
    - healthcare
    - finance

**Topic : Machine Learning**

- Mathematics for machine learning
    
    
    - Linear algebra and discrete mathematics
    - Multivariate calculus
    - Statistics
- Machine learning algorithms
- Machine learning pipeline
- Optimisation for machine learning

**Topic : Deep learning**

- Deep learning vs machine learning
- Natural language processing (NLP)
- Self learning
    
    
    - Self-learning agents in games

# Python Strings

<iframe height="400" src="https://replit.com/@ChesterWhitwell/String-methods?lite=true" width="100%"></iframe>

<iframe height="356" src="https://trinket.io/embed/python3/142855fbe8?toggleCode=true&showInstructions=true" style="border:0;" width="100%"></iframe>

<iframe height="356" src="https://trinket.io/embed/python/d4301ef9ac" style="border:0;" width="100%"></iframe>