![Page 1: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/1.jpg)
CSC1201: PROGRAMMING LANGUAGE 2
Aseel Al Hadlaq
2nd Term 2014
1
![Page 2: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/2.jpg)
OBJECTIVES
• Programming languages Overview
• C++ Overview
• Data Types
• Control Statements
• Function
2
![Page 3: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/3.jpg)
PROGRAMMING LANGUAGES
OVERVIEW
3
![Page 4: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/4.jpg)
4
PROGRAMMING METHODOLOGIES
Structured Programming Ex: C, Pascal, Fortran
Object-Oriented Programming(OOP) Ex: C++, Java
4
![Page 5: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/5.jpg)
5
STRUCTURED PROGRAMMING
Dividing a problem into smaller sub problems.
Each sub problem is solved.
Combine all the sub solutions to solve the overall problem.
5
![Page 6: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/6.jpg)
6
OBJECT-ORIENTED PROGRAMMING
1. Identify components called objects, which form the basis of the solution.
Ex.: Suppose you want to write a program that automates the book rental process for a local book store.
The two main objects in this problem are book and customer.
6
![Page 7: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/7.jpg)
7
OBJECT-ORIENTED PROGRAMMING
2. Determine how these objects interact with one another.
Specify for each object:
Relevant data
Ex: title, author, publisher, retail cost
Operations to be performed on that data.
Ex: Checking the title of the book.
Reducing the number of copies in stock by one after a copy is rented.
7
![Page 8: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/8.jpg)
OBJECT-ORIENTED PROGRAMMING
• This illustrates that each object consists of data and operations on that data.
• An object combines data and operations on the data into a single unit.
• In OOD, the final program is a collection of interacting objects.
8
![Page 9: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/9.jpg)
9
OO FEATURES
• Allow you to organize your program more effectively
By decomposing a problem into its essential parts.
Each component becomes a self contained object that contains its own instructions and data related to that object.
• All object oriented programming languages have three things in common:
encapsulation
polymorphism
Inheritance
.
9
![Page 10: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/10.jpg)
C++ OVERVIE
W
10
![Page 11: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/11.jpg)
FIRST C++ PROGRAM
• A program can contain one or many functions
• Must always have a function called “main”.
• The main function is the starting point of all C++ programs
• The compiler will not compile the code unless it finds a function called “main” within the program.
Function declaration:
FuncType FuncName(Type arg1, Type arg2, Type argN)
{ function body }
11
![Page 12: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/12.jpg)
“HELLO WORLD” PROGRAM
#include <iostream>
using namespace std;
int main ()
{
cout << “Hello World\n”;
Return 0;
}
• include information from standard input/output library iostream.
• The instruction is more properly called a “pre-processor” instruction
• The # hash character starts the line to denote a pre-processor instruction
• Library name must be enclosed by < and > angled brackets.
12
![Page 13: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/13.jpg)
DATA T
YPES
13
![Page 14: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/14.jpg)
DATA TYPES
14
![Page 15: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/15.jpg)
KEYWORDS
• They cannot be used as variables or other user-defined elements like functions
15
![Page 16: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/16.jpg)
ESCAPE SEQUENCES
16
The name reflects the fact that the backslash causes an “escape” from the normal way the character is interpreted.
![Page 17: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/17.jpg)
DECLARING AND INITIALIZING VARIABLES
To declare variables for example
int first, second;
char ch;
double x;
bool flag;
To declare and initialize variables for example
int first = 13, second = 10;
char ch = ‘A’;
double x = 12.6;
bool flag = true;
17
![Page 18: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/18.jpg)
INPUT (READ) STATEMENT
The syntax of cin together with >> is:
cin >> variable>> variable;
18
![Page 19: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/19.jpg)
OUTPUT
• The syntax of cout together with << is:
• cout << expression << expression;
• The expression is evaluated and its value is printed at the current insertion point on the output device.
19
![Page 20: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/20.jpg)
EXAMPLE
20
![Page 21: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/21.jpg)
WORKING WITH STRING
The C++ <string> class provides methods to manipulate strings of text.
This is an example of Declaring and initializing a string variable
#include <string>
#include <iostream>
using namespace std;
int main( )
{
string str = "C++ is fun”;
}
21
![Page 22: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/22.jpg)
N O U F A L J A F F A N ( C ) 2 0 1 2 - C S C 1 2 0 1 C O U R S E AT K S U
CONTROL STA
TEMENTS
22
![Page 23: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/23.jpg)
IF STATEMENT
23
![Page 24: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/24.jpg)
24
IF .. ELSE STATEMENT
![Page 25: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/25.jpg)
EXAMPLE : IF..ELSE STATEMENT
25
![Page 26: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/26.jpg)
SW
ITC
H S
TR
UC
TU
RE
S
26
![Page 27: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/27.jpg)
SW
ITC
H S
TR
UC
TU
RE
S
27
![Page 28: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/28.jpg)
EXAMPLE: SWITCH STRUCTURES
}
28
char letter;
cout << "Enter any a-z character: "; cin >> letter;
switch(letter) { case 'a' :
cout << "Letter \'a\' found\n"; break;
case 'b' : cout << "Letter \'b\' found\n"; break;
case 'c' : cout << "Letter \'c\' found\n"; break;
default : cout << "Letter is not a, b or c\n"; } return 0;
![Page 29: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/29.jpg)
FO
R LO
OP
ST
RU
CT
UR
E
The for loop execute part of the code a fixed number of times
29
![Page 30: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/30.jpg)
EX
AM
PLE
: FO
R LO
OP
#include <iostream>
using namespace std;
int main()
{int i,num;cout<<"enter any number: ";cin>>num;for ( i=1 ; i<=10 ; i++ ){cout << endl << num << "*“ << i << "=“ << num*i <<
endl;}
return 0;
}
30
![Page 31: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/31.jpg)
WH
ILE LO
OP
S
TR
UC
TU
RE
31
![Page 32: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/32.jpg)
EXAMPLE: WHILE LOOP
32
![Page 33: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/33.jpg)
RELATIONAL OPERATORS IN C++
33
![Page 34: CSC1201: PROGRAMMING LANGUAGE 2 Aseel Al Hadlaq 2nd Term 2014 1](https://reader036.vdocuments.mx/reader036/viewer/2022062408/56649f1c5503460f94c32a6a/html5/thumbnails/34.jpg)
LOGICAL OPERATORS IN C++
34