2. WHO ARE WE?
• Ahmed Farag Mohammed
• ahmed.farag1111@gmail.com
• Sara Tarek Ali
• eng.saratarek@gmail.com
Our target :
is to keep a smile on your face while learning new stuff ;)
4. WHY DID YOU JOIN THIS COURSE?
Hwaay you do zes, hwaaay!!??
5. What is a Computer?
• A definition of a computer is an electronic
device that can input data, process data
and output data, accurately and at great
speed.
• Data are any kind of information that can
be codified in some manner (i.e. 0s , 1s)
and input into the computer.
6. What is a Computer? Cont.
Fast Device
with a sequence
of commands
mn el a5er!
Input output
Take 2 numbers
and add them
and output the
result
Example
7, 5 12
7. The Purpose of this course
Fast Device
with a sequence
of commands
Input output
our main concern through out this
course is to write the sequence of
commands that the computer will
perform in high speeds to solve certain
problems of our daily life.
8. Lets play a game
• Type the following instruction, and see
the magic happens ;)
cout << 6 + 7 ;
10. Now, let’s see how this happened
Starting for the very beginning :D
11. Stored Program Computer
• John Von Neumann (Dec. 28, 1903 – Feb.
8, 1957) {
Instruction 1
Instruction 2
Instruction 3
.
.
.
.
Instruction n
}
Program
Counter
12. How can the computer understand us?
• Those instructions that you saw
previously are translated to computer
language (binary [0,1]).
• There are two ways to translate a
program; Interpreting or Compiling.
13. Interpreter
• An interpreter is a program that reads a
high-level program and does what it says.
In effect, it translates the program line-
by-line, alternately reading lines and
carrying out commands.
14.
15. Complier
• A compiler is a program that reads a high-
level program and translates it all at once,
before executing any of the commands.
• Often you compile the program as a
separate step, and then execute the
compiled code later. In this case, the high-
level program is called the source code,
and the translated program is called the
object code or the executable.
18. Computers cannot Think.. People
can!
• Computers are merely machines, made of
silicon, iron, and other stuff.
• What mostly qualifies computers is their
Speed.
• A Pentium 4 computer (2 GHz), can do
addition of two numbers in 0.5 Nanosecond.
• Nanosecond is: ( 1/1,000,000,000 of a
second)
19. Thus, we have this rule..
• If you tell the computer to do something
stupid, the computer accurately and at
great speed does that stupid action!
• Your idea of a computer program not
working or making a mistake is likely
coming from this aspect.
20. Data
• Normally, we think of data as facts and
numbers such as a person’s name and
address or the quantity or cost of an item
purchased. However, data can also be
graphical images, sound files, movies and
more.Characters
ABC
Decimals
8.0023
Sounds Images
Integers
1234
21. Errors
• When a program has an error in it, that
error is often called a “bug.” And the
process of getting all of the errors out of a
program is called debugging.
• Funny story behind it :D
23. Programming Languages
• The computer internally operates on the
binary number system. In the binary
number system, the only valid digits are 0s
and 1s.
• Electronic circuits can either have some
electricity in them or not. 1 means ON, and
0 means OFF.
• No one writes programs in binary, it’s very
tedious.
24.
25. C++
• C++ is the programming language we will
learn in this course
• The instruction that you used at the
beginning of this session is actually C++
statement “cout << 6 + 7;”
26. I/O
• As we said, any program gets input from
user and has an output, so how can we
get input and return output ?
• Let’s see ;)
29. Input
• Let’s get input from user, But where we
will save this data ?!!
30. Variables
• Do you remember when we talked about
“Data” ?
• So, where it will be saved ?!
• We create variables to save data needed
through the program or in files to be
reused again and again (we will talk about
files later)
• Variables shouldn’t begin by a number,
and shouldn’t have any spaces
31. Data types
• Since the variable holds data, so this variable
should have a data type
• Data types in C++ :
– int integer number
– float float numbers
– double big numbers (int OR float)
– char characters
– Adding long more size for a variable
EX: long int
– bool return true or false
– string
32. Declaration and initialization
• int x;
– Here we say that we want to declare x as a
variable from the type int (integer)
• int x = 3;
– Here , x is declared as an integer and also
initialized by the value “3”
• Note: it is a better practice to initialize
your variables.
33. Back to I/O
• Now we can use these variables to take
data from the user.
• But how input actually works?
35. I/O cont’
• So now, let’s take input and save it in
avariable
• We will use cin object , very similar to
cout
• For example :
– Int x;
– cin>>x
• Here the value entered will be saved in
variable x
39. Errors
• There is two types of errors
• Syntax : appears when you complie your
code (error & warning)
• Semantic (by logic) : appears when you
run your program and you don’t get the
desired output.
• Example if you made a program to devide
2 numbers and you gave it 5/0, this
wouldn’t give you the desired output.
42. Special characters
• a : make a sound when the program come
to it
• n : make a new line
• r : make the cursor goes to the beginning of
the line
• t : make the cursor leave to the next tab
• For example :
– Cout<<“n” ; <- prints a new line
– Cout<<“t”; <- prints a tab
• We have also -> , ’ , ”
43. Practice special char.s
• cout << “line1nline2nline3”;
• cout << “row1-col1trow1-col2n”
<< “row2-col1trow2-col2n”;
• cout << “my name is “ahmed””;
• cout << “path is c:folderfile.exe”;
• cout << “maho enta aslan 3ayel teeta”
44. I have a little confession
I was hiding some code from you
45. Simple Program
# include <iostream>
using namespace std;
int main()
{
cout << “Hello World!!" ;
return 0;
}
46. C++ Program
• Wait wait wait a moment !!
• Where will I write my program ? O_o
47. IDE
• IDEs are programs that help us to write
new programs !!
• IDEs as : Eclipse, Netbeans, Visual Studio,
Dev C++ and others
• So let’s open our IDE and write a program
!
49. Libraries cont.
• What are Libraries ?!
• Every thing should extend from a library
in C++ language
• We declare the library on this form
• #include< name of the library.h >
– <> : we should surrounded the library name
with this two brackets
– .h : the extension of the library
51. Namespace cont.
• We always add the line “Using
namespace std;” at the beginning of the
program, what does it means ??
• Why namespaces are useful ?
53. Main cont.
• In C++ any program should have a main from
which the program begin its work
int main(){
// our program
return 0;
}
• So soon we will know the meaning of each
part of these stuff !
• But for now we will write our program inside
the main
54. Simple Program
# include <iostream>
using namespace std;
int main()
{
cout << “Hello World!!" ;
return 0;
}
55. Let’s get interactive with users
# include <iostream>
using namespace std;
int main()
{
int num1, num2;
cout << “Enter first number: " ;
cin >> num1;
cout << “Enter second number: ”;
cin >> num2;
cout << num1 << “+” << num2 << “=“ << num1+num2;
return 0;
}
56. Notes for a good programmer
• Indentation !!!
• Variable names (naming ways)
• Variables are case sensitive
• Spaces and comments
• Comments types (// , /* */)
• initialize your variables
57. Training 1
• Write a program that takes your name
and say:
– Hello “somebody”
58. Training 2
• Write a program that takes from the user
two numbers and calculate:
– Sum
– Difference
– Multiplication
– Division
Notas do Editor
I want a machine that can take a recipe, a sequence of steps that will now act as described in the recipe, so it will change as it’s described in the sequence, it’s the basic part of each computer, this is now an example of stored program computer
We will have a python demo here
There is no Good Programming language and Bad one, but each suitable of specific kind of applications. So, Given a fixed set of primitives, all right, a good programmer can program anything. And by that, I mean anything that can be described in one of these process, you can capture in that set of primitives.
The term originates in the first generation of computers when someone removed a fly that had gotten into the computercircuitry and shorted it out - they were “debugging” the computer. In fact, mostly workingsoftware is a pet peeve of mine.