Skip to content

Commit 2be982c

Browse files
Merge pull request #1 from The-Young-Programmer/main
c/c++ Tutorial
2 parents 109265f + 4ba0e19 commit 2be982c

File tree

1 file changed

+186
-46
lines changed

1 file changed

+186
-46
lines changed

README.md

Lines changed: 186 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</h1>
99

1010
<p align="center">
11-
<img src="https://img.shields.io/badge/C%2B%2B-00599C?style=for-the-badge&logo=c%2B%2B&logoColor=white">
12-
<img src="https://img.shields.io/badge/C-00599C?style=for-the-badge&logo=c&logoColor=white"><br><br>
11+
<img src="https://img.shields.io/badge/C%2B%2B-00599C?style=flat&logo=c%2B%2B&logoColor=white">
12+
<img src="https://img.shields.io/badge/C-00599C?style=flat&logo=c&logoColor=white"><br><br>
1313
<a href="#">
1414
<img src="https://travis-ci.org/github/github.svg" alt="Build Status">
1515
</a>
@@ -35,31 +35,31 @@
3535

3636
<details><summary>Introduction</summary>
3737

38-
- [Introduction to C++](#-introduction-to-c++-)
38+
- [Introduction to C++](#introduction-to-c++)
3939

40-
- [Introduction to C](#-introducion-to-c-)
40+
- [Introduction to C](#introducion-to-c)
4141

42-
- [Differences](#differences-)
42+
- [Differences](#differences)
4343

44-
- [Compiler](#compiler-)
44+
- [Compiler](#compiler)
4545

4646
</details>
4747

4848
<details><summary>C++ Basics</summary>
4949

50-
- [Syntax](#syntax-)
50+
- [Syntax](#syntax)
5151

52-
- [Comments](#comments-)
52+
- [Comments](#comments)
5353

54-
- [Variables](#variables-)
54+
- [Variables](#variables)
5555

56-
- [User Input](#user-input-)
56+
- [User Input](#user-input)
5757

58-
- [Data Types](#data-types-)
58+
- [Data Types](#data-types)
5959

60-
- [Operators](#operators-)
60+
- [Operators](#operators)
6161

62-
- [Loop Types](#loop-types-)
62+
- [Loop Types](#loop-types)
6363

6464

6565

@@ -69,65 +69,66 @@
6969

7070
<details><summary>Simple Projects</summary>
7171

72-
- [Bank Management system ](#-bank-management-system-)
72+
- [Bank Management system ](https://github.com/The-Young-Programmer/C-CPP-Programming-Project/tree/main/Bank%20Management%20System)
7373

74-
- [Basic Calculator (GUI)](#-basic-calculator-)
74+
- [Basic Calculator (GUI)](https://github.com/The-Young-Programmer/C-CPP-Programming-Project/tree/main/Basic%20Calculator%20(GUI))
7575

76-
- [Hotel Management System](#-hotel-management-system-)
76+
- [Hotel Management System](https://github.com/The-Young-Programmer/C-CPP-Programming-Project/tree/main/Hotel%20Management%20System)
7777

78-
- [Sci. Calculator (GUI)](#-sci.-calculator-)
78+
- [Sci. Calculator (GUI)](https://github.com/The-Young-Programmer/C-CPP-Programming-Project/tree/main/Sci.%20Calculator%20(GUI))
7979

80-
- [Tic-Tac-Toe game](#-tic-tac-toe-game-)
80+
- [Tic-Tac-Toe game](https://github.com/The-Young-Programmer/C-CPP-Programming-Project/tree/main/Tic-Tac-Toe%20game)
8181

8282
</details>
8383

8484

85-
- [How To Contribute](#-how-to-contribute-)
86-
- Contributors
87-
- Info
85+
- [How To Contribute](#-how-to-contribute-)
86+
- Contributors
87+
- Info
8888

8989

9090

91+
<a id="introduction-to-c++"></a>
92+
<br><br><br><br>
93+
<img src="https://img.shields.io/badge/C%2B%2B-00599C?style=flat&logo=c%2B%2B&logoColor=white">
94+
95+
## Introduction to C++
9196

92-
93-
## Introduction to C++ [](#-introduction-to-c++-)
94-
95-
<img src="https://img.shields.io/badge/C%2B%2B-00599C?style=for-the-badge&logo=c%2B%2B&logoColor=white">
9697
<p><b>What is C++ Programming Language ?</b>
9798

98-
C++ is a cross-platform language that can be used to create high-performance applications.
99+
* C++ is a cross-platform language that can be used to create high-performance applications.
99100

100-
C++ was developed by Bjarne Stroustrup, as an extension to the C language.
101+
* C++ was developed by Bjarne Stroustrup, as an extension to the C language.
101102

102-
The language was updated 4 major times in 2011, 2014, 2017, and 2020 to C++11, C++14, C++17, C++20.
103+
* The language was updated 4 major times in 2011, 2014, 2017, and 2020 to C++11, C++14, C++17, C++20.
103104

104-
C++ is fun and easy to learn!
105+
* C++ is fun and easy to learn!
105106

106-
As C++ is close to C# and Java, it makes it easy for programmers to switch to C++ or vice versa.
107+
* As C++ is close to C# and Java, it makes it easy for programmers to switch to C++ or vice versa.
107108
</p>
108109

109-
<h2> C++ compiler /IDE </h2>
110+
### C++ compiler /IDE
110111

111112
<p>
112-
To start using C++, you need two things:
113+
To start using C++, you need two things:
113114

114115
- A text editor, like Notepad, to write C++ code
115116
- A compiler, like GCC, to translate the C++ code into a language that the computer will understand
116117

117118
An IDE (Integrated Development Environment) is used to edit AND compile the code.
118119

119120
Popular IDE's include:
120-
Code::Blocks, Eclipse, and Visual Studio.
121+
`Code::Blocks`, `Eclipse`, and `Visual Studio`.
121122
These are all free, and they can be used to both edit and debug C++ code.
122123

123-
I will be using Code::Blocks in this Project, which I believe is a good place to start.
124+
I will be using `Code::Blocks` in this Project, which I believe is a good place to start.
124125

125126
You can find the latest version of Codeblocks at http://www.codeblocks.org/.
126127

127128
Download the `mingw-setup.exe file`, which will install the text editor with a compiler.
128129
</p>
129130

130-
<h4> Quick Start :</h4>
131+
### Quick Start :
131132

132133
<p>
133134

@@ -159,23 +160,25 @@ int main() {
159160

160161
</p>
161162

162-
<hr>
163-
## Introduction to C
163+
<a id="introducion-to-c"></a>
164+
<hr><br><br>
164165

165-
<img src="https://img.shields.io/badge/C-00599C?style=for-the-badge&logo=c&logoColor=white"><br><br>
166+
<img src="https://img.shields.io/badge/C-00599C?style=flat&logo=c&logoColor=white">
167+
168+
## Introduction to C
166169

167170
<p><b>What is C Programming Language ?</b>
168-
C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972.
171+
* C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972.
169172

170-
It is a very popular language, despite being old.
173+
* It is a very popular language, despite being old.
171174

172-
C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
175+
* C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
173176

174177
**NOTE**
175178
C and C++ uses the same compiler and IDE
176179
</p>
177180

178-
<h4> Quick Start :</h4>
181+
### Quick Start :
179182

180183
<p>
181184

@@ -194,14 +197,151 @@ int main() {
194197
return 0;
195198
}
196199
```
200+
201+
<a id="differences"></a>
202+
<hr><br><br>
203+
204+
## Differences between <img src="https://img.shields.io/badge/C-00599C?style=flat&logo=c&logoColor=white"> and <img src="https://img.shields.io/badge/C%2B%2B-00599C?style=flat&logo=c%2B%2B&logoColor=white">
205+
206+
* C++ was developed as an extension of C, and both languages have almost the same syntax.
207+
208+
* The main difference between C and C++ is that C++ support classes and objects, while C does not.
209+
210+
211+
<a id="compiler"></a>
212+
<hr><br><br>
213+
214+
## C++/C Compiler on different OS
215+
216+
217+
<p><b>For Windodws, Linux and MacOS</b><br>
218+
* Install `code::blocks` by going to there oficial website, <a href="www.codeblocks.org/downloads/">Code Blocks</a>
219+
</p>
220+
<p>
221+
<b>For Andriod OS</b><br>
222+
* Install `C4Droid` on playstore, <a href="https://play.google.com/store/apps/details?id=com.n0n3m4.droidc">C4Droid</a>
223+
</p>
224+
<p>
225+
<b>For IOS</b><br>
226+
* Visit Appstore and download <a href="https://apps.apple.com/us/app/c-c-program-compiler/id1160868782">C/C++ Program Compiler</a>
227+
</p>
228+
229+
230+
<hr><br><br>
231+
<h2 align="center">C++ Basic <img src="https://img.shields.io/badge/C%2B%2B-00599C?style=flat&logo=c%2B%2B&logoColor=white"></h2>
232+
233+
<a id="syntax"></a>
234+
## C++ Syntax
235+
236+
1. Let's break up the following code to understand it better:
237+
238+
```
239+
#include <iostream>
240+
using namespace std;
241+
242+
// main() is where program execution begins.
243+
int main() {
244+
cout << "Hello World"; // prints Hello World
245+
return 0;
246+
}
247+
```
248+
249+
<b>Example Explained:</b>
250+
251+
**Line 1:** `#include <iostream>` is a header file library that lets us work with input and output objects, such as cout (used in line 5). Header files add functionality to C++ programs.
252+
253+
**Line 2:** `using namespace std` means that we can use names for objects and variables from the standard library.
254+
255+
**Line 3:** A blank line. C++ ignores white space. But we use it to make the code more readable.
256+
257+
**Line 4:** Another thing that always appear in a C++ program, is `int main()`. This is called a function. Any code inside its curly brackets {} will be executed.
258+
259+
**Line 5:** `cout` (pronounced "see-out") is an object used together with the insertion operator (<<) to output/print text. In our example it will output "Hello World".
197260

198-
## Differences [](#welcome) between <img src="https://img.shields.io/badge/C-00599C?style=for-the-badge&logo=c&logoColor=white"> and <img src="https://img.shields.io/badge/C%2B%2B-00599C?style=for-the-badge&logo=c%2B%2B&logoColor=white">
261+
**Note:** Every C++ statement ends with a semicolon ;.
199262

200-
C++ was developed as an extension of C, and both languages have almost the same syntax.
263+
**Note:** The body of `int main()` could also been written as:
264+
``` int main () { cout << "Hello World! "; return 0; } ```
201265

202-
The main difference between C and C++ is that C++ support classes and objects, while C does not.
266+
**Remember:** The compiler ignores white spaces. However, multiple lines makes the code more readable.
203267

268+
**Line 6:** `return 0` ends the main function.
204269

270+
**Line 7:** Do not forget to add the closing curly bracket `}` to actually end the main function.
271+
272+
<br>
273+
#### Escape Sequence in C++
274+
275+
| Escape Sequence | Description |
276+
| -------------------------- | :-------------------------------------------: |
277+
| \n or endl | To insert a new line or to break lines |
278+
| \n\n | create a blank line |
279+
| \t | Creates a horizontal tab |
280+
| \\ | Inserts a backslash character (\) |
281+
| \" | Inserts a double quote character |
282+
283+
284+
<hr><br><br>
285+
<a id="comment"></a>
286+
287+
## Comment in C++
288+
289+
* Comments can be used to explain C++ code, and to make it more readable.
290+
* It can also be used to prevent execution when testing alternative code.
291+
* Comments can be singled-lined or multi-lined.
292+
293+
1. Single-line comments start with two forward slashes (//).
294+
295+
```
296+
// This is a comment
297+
cout << "Hello World!";
298+
```
299+
300+
2. Multi-line comments start with /* and ends with */.
301+
302+
```
303+
/* The code below will print the words Hello World!
304+
to the screen, and it is amazing */
305+
cout << "Hello World!";
306+
```
307+
308+
<hr><br><br>
309+
<a id="variables"></a>
310+
311+
## Variables in C++
312+
313+
1. Variables are containers for storing data values.
314+
315+
In C++, there are different types of variables (defined with different keywords), for example:
316+
317+
* `int` - stores integers (whole numbers), without decimals, such as 123 or -123
318+
* `double` - stores floating point numbers, with decimals, such as 19.99 or -19.99
319+
* `char` - stores single characters, such as 'a' or 'B'. Char values are surrounded by single quotes
320+
* `string` - stores text, such as "Hello World". String values are surrounded by double quotes
321+
* `bool` - stores values with two states: true or false
322+
323+
2. To create a variable, specify the type and assign it a value:
324+
`type variableName = value;`
325+
326+
**Note:** Where `type` is one of C++ types (such as `int`), and `variableName` is the name of the variable (such as x or myName). The equal sign is used to assign values to the variable.
327+
328+
3. Variable Declaration:
329+
*
330+
331+
332+
333+
334+
335+
336+
337+
338+
339+
340+
341+
342+
343+
344+
205345

206346

207347

@@ -210,8 +350,8 @@ The main difference between C and C++ is that C++ support classes and objects, w
210350

211351

212352

353+
<hr><br><br><br>
213354

214-
<br><br><br>
215355
<p align="center">Join our <a href="https://github.com/TYP-Coding-Class/community/issues/new?assignees=&labels=github-invitation&template=invitation.yml&title=Please+invite+me+to+the+community">GitHub Organization :octocat:</a> and continue to contribute to our Open Source Software ✨</p>
216356
<img src="https://user-images.githubusercontent.com/73097560/115834477-dbab4500-a447-11eb-908a-139a6edaec5c.gif">
217357

0 commit comments

Comments
 (0)