PF Lecture 2
PF Lecture 2
Lecture 2
1
Problem Solving
2
Problem Solving
3
Pseudocode
Pseudocode is an informal high-level description of the
operating principle of a computer program or other
algorithm.
4
Pseudocode
Pseudocode for making tea?
Making Tea
5
Pseudocode
Pseudocode for making tea?
Making Tea
6
Pseudocode
Pseudocode for Two Variables?
Algorithm Add_Two
start
input a,b
sum=a + b
output sum
end
7
Evolution of Operating Systems
Batch processing
Do only one job or task at a
time
Operating systems
Manage transitions between
jobs
Increased throughput
Amount of work computers
process
Multiprogramming
Computer resources are
shared by many jobs or
tasks
Timesharing
Computer runs a small
portion of one user’s job then
moves on to service the next
user
8
A Computer Program
A Computer Program is
used to solve problems
using computers.
A Computer program is a
set of instructions (in a
certain programming
language)
9
Types of Programming Languages
Example : wages = rate * hours
Three types of programming
languages
1. Machine languages
Strings of numbers giving
machine specific instructions
Example:
+1300042774
+
+1200274027
2. Assembly languages
English-like abbreviations
representing elementary
computer operations (translated
via assemblers)
Example:
LOAD BASEPAY
ADD OVERPAY
STORE GROSSPAY
10
Machine Languages, Assembly Languages, and
High-level Languages
3. ,
11
C++ and C
C++ is a powerful programming language. It
has its roots in C language.
12
C Language
C is often called a middle-level programming language.
13
C++
C++ is built on top of C and provides capabilities for Object-Oriented
Programming.
14
A Typical C++ Environment
Program is created in the
Phases of C++ Editor Disk
editor and stored on disk.
Link Loader
Execute
..
..
Primary
Memory
15
Once again
16
Introduction to C++ Programming
The C++ language facilitates a structured and disciplined
approach to computer program design.
17
Example
// The first C++ Program
Comments
Written between /* and */ or following a //
#include <iostream> Improve program readability and do not cause the
computer to perform any action
using namespace std;
A namespace tells the compiler the domain that is
being used. In this case, this program is using the
standard C++ namespace. Hence the functions to be
int main() preprocessor
used in this program would directive
be standard ones.
{ Message to the C++ preprocessor
Lines beginning with # are preprocessor directives
cout << “Welcome to C++\n”;
#include <iostream> tells the preprocessor to
return 0; include the contents of the file <iostream>, which
includes input/output operations (such as printing to
} Prints
C++theprograms
the string of characters in double quotes
screen). contain one or more functions, exactly
return is one way to exit a function. one ofThe entire
which line is called a statement. Every
Left brace { begins themust
bodybeofmain
every function and a
statement ends with a semicolon.
return 0, in this case, meansright
thatbrace } ends it used to indicate a function
Parenthesis
the program terminated normally. 18
int means that main "returns" an integer value.
More Explanation
cout
Standard output stream object
Connected to the screen
<<
Stream insertion operator
Value to the right of the operator (right operand) inserted into
output stream (which is connected to the screen)
\
escape character
indicates that a special character is to be output.
19
Escape Sequences
20
C++ Multiple Lines Text
// The first C++ Program
#include <iostream>
using namespace std;
int main()
{
cout << “Welcome\n to C++\n”;
return 0;
}
21
C++ Multiple Lines Text
// The first C++ Program
#include <iostream>
using namespace std;
int main()
{
cout << “Welcome to”;
cout << “ C++”;
return 0;
}
22
C++ Data Types
All high-level programming languages support the concept
of data types.
C++ has basic built-in data types. These are char, int, float,
double, and void. However, C is not a strongly typed
language.
Ex. Adding Integer with a Float in the same expression is
allowed.
23
Data Types
Standard C++ does not define a minimum size or range
for the basic data types. Instead, this size is suggested
by the architecture of the execution environment.
24
Data Types (Incomplete Table)
Type Size in Bits Min. Range
25
Data Types (Incomplete Table)
The term "unsigned" in computer programming indicates
a variable that can hold only positive numbers.
26
Data Types (Incomplete Table)
27
Identifier Names
In C/C++, names of variables, functions, labels, and
other user-defined objects are called identifiers.
28
Identifiers Names
Count Correct
count Correct
1count Wrong
test123 Correct
_test123 Correct
my.name Wrong
student_name Correct
studentname Correct
StudentName Correct
29
Assignment :
1. Write a program to print Your Name on screen.
30