Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Lecture # 4
STRUCTURE OF C++ PROGRAM
(Structure of a Program, Sample Programs)
2
)1 – حال201( حاسب آلي: المقـرر
2. Statement
There are many different kinds of statements in C++. The following are some
of the most common types of simple statements:
1 int x;
2 x = 5;
3 cout << x;
1
)1 – حال201( حاسب آلي: المقـرر
3. Functions
Now that you have a brief understanding of what statements, functions are,
let’s look at a simple hello world program.
1) #include<iostream.h>
2) int main()
3) {
4) Cout<<"Hello World";
5) Return 0;
6) }
Lines 3 and 6 tell the compiler which lines are part of the main function.
5. Comment
A comment is a line (or multiple lines) of text that are inserted into the source
code to explain what the code is doing.
3
)1 – حال201( حاسب آلي: المقـرر
6. Sample programs
#include<iostream.h>
int main()
int x=10;
int y=20;
int C=0;
C=x+y;
Return 0;
#include<iostream.h>
int main()
int x=10;
int y=20;
int C=0;
C=x-y;
4
)1 – حال201( حاسب آلي: المقـرر
Return 0;
Excersice:
#include<iostream.h>
int main()
int a;
int b;
float C;
cin>>a;
cin>>b;
C=(a+b)/2;
Return 0;
whereas cout prints data to the console, cin reads data from the console.