APznzaZkmb-kUZ4l6kBr4KiljHkZbgRJ-CE0UrfFTiDbqmDWIG7V3w1LoSuo933888-Arg_FpAn4DR4ryW2bj3OJ1KBYge7hLh2Ozd_fcuJYm9Nu6xTcrKQte09EkDB4aH7ekmVDhtmNP00lKOcw79ugbVhSiEM3GINEOQy8EuYQy-R1J5J-bxR4O7PrjTVTpqIiaWkWHHF-VJjSsL0A1.pdf

zohaib247331 9 views 26 slides Jun 06, 2024
Slide 1
Slide 1 of 26
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26

About This Presentation

introduction to Applied Programming is designed for students who are enrolled in the Bachelor of Information Technology. The course introduces the fundamental concepts of procedural and event driven programming, with a focus on approaches to programming relevant for IT, including scripting languages...


Slide Content

Applied Programming
(CS 4002)
School of Computing National University of Computer & Emerging Sciences
Islamabad Campus

1. Fundamentals of Programming

C++ Compilation Steps
C++
Preprocessor
First.cpp
C++ Compiler Linker First.exe
C++ Header
Files
Object code for
library function

Preprocessor Directives
#include<iostream>
#is a preprocessor directive.

Namespaces
What is usingdirective?
brings namespaces or its sub-items into current
scope
Example:
#include<iostream>
using namespace std;

Naming Variables
●AREA
●2D
●Last Chance
●x_yt3
●Num-2
●Grade***
●area_under_the_curve
●_Marks
●#values
●areaoFCirCLe
●%done
●return

Naming Variables
•What are Reserve Words?
•Difference between initializationand
assignment?
•rvalueand lvalue?
–Assignment rule according to rvalueand lvalue?

Special characters
•Text string special characters (Escape Sequences)
\n
\r
\t
\"
\?
\\
\'•Examples:
cout << "Hello\t" << "I\’m Ali\n";
cout << "123\nabc “;

What is Variables Scope ?
•Different levels ofscope:
1.Function scope
2.block scope
3.File scope
4.Class scope
Local variables ??
Global variables ??

Visibility and Lifetime of Variables
??????
Avariableisvisiblewithinitsscope,and
invisibleorhiddenoutsideit.
??????
Thelifetimeofavariableistheintervalof
timeinwhichstorageisboundtothevariable.

What is Integer and Real Division ?
floatresult=5/2;//
??????
resultequalto2
floatresult=5.0/2;//
??????
resultequalto2.5
⮚If anyof the operandis a real value (float or
double) the divisionwill be performedas “Real
Division”

Increment and Decrement Operators
int var = 7;
cout<<++var;
cout<<var++;
cout<<--var;
cout<<var--;
cout<<var;

Examples…

Implicit Type Conversion in C++

Explicit Type Conversion in C++
Three Styles:
int c = (int)a % (int)b; //C-style cast
int c = int(a)% int(b); // Functional notation
int c = static_cast<int>(a) % static_cast<int>(b);
Wideningvs Narrowingtype casting ?

C++ Operators
•Logical Operators
•Conditional Operator
•Bitwise Operators

Logical Operators

C++ Bitwise Operators

Conditional operator

Precedence Rules -Example
8 * 3 / 2 + 3 -1
24 / 2 + 3 -1
12 + 3 -1
15 -1
14
8 / 3 * 2 + 3 -1
2 * 2 + 3 -1
4 + 3 -1
7 -1
6

C++ Selection Structures

Matching the “else”
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cout<<“Enter three numbers, a, b, and c:\n”;
cin >> a >> b >> c;
if( a==b )
if( b==c )
cout << “a, b, and c are the same\n”;
else
cout << “a and b are different\n”;
return 0;
}
else
cout << “b and c are different\n”;
if( a==b )
{
if( b==c )
cout<< “a, b, and c are the same\n”;
}
else
cout<< “a and b are different\n”;

Switch –Example
int day;
cout<<“Enter day number“; cin>>day;
switch (day)
{
case 1 :
case 7 : cout<< "This is a weekend day";
break;
case 2 :
case 3 :
case 4 :
case 5 :
case 6 : cout<< "This is a weekday"; break;
default : cout<< "Not a legal day";
}

Examples…

Loop constructs

26
for loop -Syntax
for (int j=0;j<10;j++)
cout << j * j <<endl;
?
?
?
cout << j*2 <<endl;
cout << j*j*j <<endl;