intro to programming week # 2 first program lecture # 3...2016/07/03  · intro to programming week...

17
Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science & Engineering Air University

Upload: others

Post on 26-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

Intro to Programming

Week # 2

First Program

Lecture # 3

By: Saqib Rasheed

Department of Computer Science & Engineering

Air University

Page 2: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 3: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 4: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 5: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 6: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 7: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 8: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 9: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 10: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 11: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 12: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 13: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 14: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 15: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

// 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

Page 16: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

Greeting Output

By Saqib Rasheed 16

Page 17: Intro to Programming Week # 2 First Program Lecture # 3...2016/07/03  · Intro to Programming Week # 2 First Program Lecture # 3 By: Saqib Rasheed Department of Computer Science &

• Reference Chapter # 2:

C++ Programming Basics by

Robert Lafore

• https://sites.google.com/site/saqibrashied/cplusplus

By Saqib Rasheed 17