Upload
others
View
3
Download
0
Embed Size (px)
Citation preview
Intro to Programming
Week # 2
First Program
Lecture # 3
By: Saqib Rasheed
Department of Computer Science & Engineering
Air University
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
By Saqib Rasheed 2
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
Single Line Comments
By Saqib Rasheed 3
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
Function
Single Line Comments
By Saqib Rasheed 4
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
Function
Opening & Closing brackets Every function in C++ has opening closing brackets 5
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
Function
Opening & Closing brackets Every function in C++ has opening closing brackets
Name of the function
6
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
Function
Opening & Closing brackets
Name of the function
Function returning parameters
By Saqib Rasheed 7
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
an object. It is predefined in C++ to correspond to the standard output stream. 8
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
insertion or put to operator In C : left-shift bit-wise operator
an object. It is predefined in C++ to correspond to the standard output stream. 9
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
quotation marks
an object. It is predefined in C++ to correspond to the standard output stream.
insertion or put to operator In C : left-shift bit-wise operator
10
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
quotation marks
an object. It is predefined in C++ to correspond to the standard output stream.
insertion or put to operator In C : left-shift bit-wise operator
string constant
11
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
string constant
quotation marks
an object. It is predefined in C++ to correspond to the standard output stream.
insertion or put to operator In C : left-shift bit-wise operator
Semicolon Used for termination Of a statement
12
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
Preprocessor directive.
Library File
Namespaces
By Saqib Rasheed 13
// First Program
// Author Saqib Rasheed
#include <iostream>
int main()
{
return 0;
}
A First Program - Greeting.cpp
Preprocessor directive.
Library File
To avoid adding std:: dozens of times in programs we use the using directive instead
std::cout<< "Hello world!";
By Saqib Rasheed 14
// First Program
// Author Saqib Rasheed
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!";
return 0;
}
A First Program - Greeting.cpp
By Saqib Rasheed 15
Greeting Output
By Saqib Rasheed 16
• Reference Chapter # 2:
C++ Programming Basics by
Robert Lafore
• https://sites.google.com/site/saqibrashied/cplusplus
By Saqib Rasheed 17