Topic 1: Intro to C++
</> by: Aly Soliman
What is C++?
C++ and C# are child languages originated from the C language.
C language Family:
C : lower level, more complex
C++ : updated version
C# : Higher level, simpler to read
Why c++?
GAME DEVELOPMENT
BANKING APPLICATIONS
COMPANY MANAGEMENT SYSTEMS
Important Terms
Syntax:
set of rules that defines what the different combinations of symbols mean.
Compiler:
What is an IDE? (Integrated Development Environment)
Terminal:
File Types:
How to view extensions
s
.1
.2
filename extensions
Installation
Let’s get started :)
Hello world:
Basic Syntax:
This are the basics that will always be typed in any program.
This is the space where you’ll write your code
(Input-output stream)
Basic library used for standard inputting and outputting .
2.using namespace std;
Redacts the need to add std:: before every function obtained from the <iostream> library
3.int main(){ …… }
4.cout << "Hello world“ << endl;
5.return 0;
How to run your code
Topic 2:�Input/Output
</> by: Aly Soliman
What is a library?
cout :
cin :
endl vs \n
#include <iostream>
using namespace std;
�int main(){
cout << "Hello world\n";
cout << "Hello world" << endl;
}
Variables:
Arithmetic operators:� ( +, -, *, /, % ,++,--)
Write your own code :)
Topic 3:�If statements
</> by: Aly Soliman
If statement:
If the condition between the brackets is true, the functions between curly brackets is executed.
Relational and equality operators
== | Equal to |
!= | Not equal to |
> , < | Less and Greater than |
>= | Greater than or equal to |
<= | Less than or equal to |
Logical operators:
&& | Logical and | Returns true if both statements are true | x < 5 && x < 10 |
|| | Logical or | Returns true if one of the statements is true | x < 5 || x < 4 |
! | Logical not | Reverse the result, returns false if the result is true | !(x < 5) |
Relational VS Arithmetic operators
Else statement:
Use the else statement to specify a block of code to be executed if the condition of the if statement is false.
Write your own code :)
Switch statement:
int x = 9;
switch (x)
{
case 2:
cout << "x equals 2";
break;
case 3:
cout << "x equals 3";
break;
case 9:
cout << "x equals 9";
break;
default:
break;
}
Switch block
Simpler If & Else statements:
int x = 10, y = 2, val;
int main(){
x > y ? val = x : val = y;
}//val will be equal 10
Comments:
int main(){
cout << "Hello world"; //This will output Hello world
}
int main(){
cout << "Hello world"; /*This will output Hello world*/
}
Write your own code :)
Topic 4:�loops
</> by: Aly Soliman
While loops:
If the condition between the brackets is true, the functions between curly brackets is executed repeatedly until the condition is false.
For loops:
When you know exactly how many times you want to loop through a block of code, use the for loop instead of a while loop.
for (int i = 0; i < 20; i++)
Topic 5:�Arrays[]
</> by: Aly Soliman
What are arrays?
Used to store multiple values in a single variable.
string cars[4] = {"Volvo", "BMW", "Ford", "Mazda"};
This is the index, the number of values in an array is entered between square brackets.
The values are placed between curly brackets. Each value is separated from the other by a comma.
Topic #:�Modifying Strings
</> by: Aly Soliman
Library for strings:
Manipulating strings
Adding strings:
You can join two or more strings together by adding a “+” sign between them.
string firstName = "John ";
string lastName = "Doe";
string fullName = firstName + lastName;
cout << fullName;
C++ Numbers And Strings:
int x = 10;
int y = 20;
int z = x + y; // z will be 30 (a integer)
string x = "10";
string y = "20";
string z = x + y; // z will be 1020 (a string)
string x = "10";
int y = 20;
string z = x + y; //error
.toupper();
It is added after the string name and gets the number of characters in the string.
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt string is: " << txt.length();
This will output: “The length of the txt string is: 26”
separating strings:
This will output: “H”
.length();
It is added after the string name and gets the number of characters in the string.
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt string is: " << txt.length();
This will output: “The length of the txt string is: 26”
Break and Continue
Global vs Local variables
endl �vs �\n
#include <iostream>
using namespace std;
�int main(){
cout << "Hello world\n";
cout << "Hello world" << endl;
}