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...
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. Students take a practical approach to learning the fundamental topics in programming, including, data types and algorithms, functions, control structures, arrays, GUI, files, as well as the mechanics of running, testing, and debugging.
Size: 973.08 KB
Language: en
Added: Jun 06, 2024
Slides: 26 pages
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
•What are Reserve Words?
•Difference between initializationand
assignment?
•rvalueand lvalue?
–Assignment rule according to rvalueand lvalue?
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
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";
}