Академический Документы
Профессиональный Документы
Культура Документы
Hello World!
That comment ended!
Other example of comment
/************************************************************
Program: Hello World
File: Hello.cpp
Function: Main (complete program listing in this file)
Description: Prints the words "Hello world" to the screen
Author: Jesse Liberty (jl)
Environment: Turbo C++ version 4, 486/66 32mb RAM,
Windows 3.1
DOS 6.0. EasyWin module.
Notes: This is an introductory, sample program.
Revisions: 1.00 10/1/94 (jl) First release 1.01 10/2/94 (jl)
Capitalized
"World"
************************************************************/
Identifiers (constant and
variables) cont..
3. Variables
In C++ a variable is a place to store information. A
variable is a location in your computer's memory in
which you can store a value and from which you can
later retrieve that value.
Variables types
Example 2
main ()
{
int Width;
int Length;
float Area;
Area = Width * Length; }
A demonstration of the use of variables.
1: // Demonstration of variables
2: #include <iostream.h>
3:
4: int main()
5: {
6: int Width = 5, Length;
7: Length = 10;
8:
9: // create integer of area and initialize with result
10: // of multiplying Width by Length
11: int Area = Width * Length;
12:
13: cout << "Width:" << Width << "\n";
14: cout << "Length: " << Length << endl;
15: cout << "Area: " << Area << endl;
16: return 0;
17: }
OUTPUT
Width:5
Length: 10
Area: 50
QUIZ 1
Q. What is the difference between // comments and /*
style comments?
2. What punctuation is used to signal the beginning and end of code blocks?
A. { }
B. -> and <-
C. BEGIN and END
D. ( and )
2. What punctuation is used to signal the beginning and end of code blocks?
A. { }
B. -> and <-
C. BEGIN and END
D. ( and )
Start:
Process:
1.Input 5 test mark, m1, m2, m3,
m4, m5
2.Total = m1 + m2 + m3 + m4 + m5
3.Ave = Total / 5
4.Print Total, Ave
End:
Flowchart
Start
Total = m1 + m2 +
m3 + m4 + m5
Ave = Total / 5
Print Total,
Ave
End
Code Statement
#include <iostream.h>
void main ()
{
int m1,m2,m3,m4,m5;
int total;
float ave;
cout<<Please enter your marks<<endl;
cout<<Mark 1:<<endl;
cin>>m1;
cout<<Mark 2:<<endl;
cin>>m2;
cout<<Mark 3:<<endl;
cin>>m3;
cout<<Mark 4:<<endl;
cin>>m4;
cout<<Mark 5<<endl;;
cin>>m5;
total=m1+m2+m3+m4+m5;
Ave=total/5;
cout<<Total:<<total<<endl;
Cout<<Average:<<ave<<endl;
return 0;
}