Beruflich Dokumente
Kultur Dokumente
106
Wednesday September 22, 2010
Objective:Introduction to C++
Arithmetic Operators
Input and Output, Variables and Comments
Integer Division and Modulus
Internal Coding of Integer Numbers
Definition 1: A computer program is a step-by-step
descriptions of the solution to a problem. It is written in
C++ code (i.e., C++ statements).
#inculde <iostream.h>
This is a C++ program.
void main()
{
It has one statement:
cout << “Hello, World”;
cout << “Hello, World”;
}
Storage in RAM
Output Primary Storage
Rules of Thumbs
Hold Program
Permanent With or Without
Storage Power
Hard Disks: Secondary Storage
#include <iostream.h>
void main()
{
cout << “Hello, World”;
}
This is a text file that will be stored into the hard disk of
your computer.
#include <iostream.h>
void main()
{
cout << “************\n”;
cout << “Hello, World\n”;
cout << “************”;
}
************
Hello, World
************
#include <iostream.h>
void main()
{
cout << “ *\n”;
cout << “ ***\n”;
cout << “ *****”;
}
*
Screen
*** Output
*****
*******
Screen
******* Output
*******
#include <iostream.h>
void main()
{
cout << “5 + 8 = ”;
cout << 5+8;
}
5 + 8 = 13
#include <iostream.h>
void main() COMPILE
{ Syntax Error
cot << “ *\n”; “cot” not
cout << “ ***\n”; declared
.obj
Program
Processor:
CPU
Addresses Location
1 data
2 data
3 data
4 data
5 data
6 data
.
.
.
+, -, /, *, %, etc
Example
#include <iostream.h>
void main()
{
cout << “6*3 = ” << 6*3 << endl;
cout << “6-3 = ” << 6-3 << endl;
cout << “6/3 = ” << 6/3 << endl;
cout << “6+3 = ” << 6+3 << endl;
}
6*3 = 18
6-3 = 3
6/3 = 2
6+3 = 9
Syntax
Example
cin >> X ;
#include <iostraam.h>
void main ()
{ ;
cout << “8%3 = ” << “8%3” << endl;
cont; << 16-3 = ” << 16-“3” <<\n;;
cout << “9/3 = ” << 9/3 << end;
}
Prof. Jihad Mohamd ALJA'AM 17
Prof. Jihad Mohamd ALJA'AM 18