0% found this document useful (0 votes)
14 views73 pages

Lecture 1-2

Lecture 1-2

Uploaded by

omaishmalik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views73 pages

Lecture 1-2

Lecture 1-2

Uploaded by

omaishmalik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPSX, PDF, TXT or read online on Scribd
You are on page 1/ 73

NATIONAL UNIVERSITY

of Computer & Emerging Sciences


Chiniot-Faisalabad Campus

Object-Oriented
Programming
Lecture 1

Department of Electrical Engineering


Outline
• Introduction
• Introduction to the course
• Importance of this course
• Review of Decision-Making Structures
• Review of Iterative Structures (for Loop)

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 2


Why to Learn Object Oriented
Programming?
• To complete the degree 
• It is a pre-requisite for another course named Data Structures and Algorithms
• Coding skills are essential to survive in the era of IT, IoT, AI, Automation, and Robotics
• OOP is essential as it has several advantages like:
• Code Re-Usability
• Data Redundancy
• Code Maintenance
• Security
• Design Benefits
• Better Productivity
• Easy Troubleshooting and Debugging
• Polymorphism Flexibility
• Better Problem Solving

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 3


Introduction to the Course
• CS1004 – Object Oriented Programming
• 3 + 1 Credit Hours
• 3 hours of theory and 3 hours of lab every week
• Total 32 Lectures of 1.5 hours each
• Total 16 labs of 3 hours each

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 4


Course Objective
• The core objective of this course is to understand the object-oriented
programming paradigm. At the end of this course, a student should be
able to analyze the problem, identify the objects involved, and
implement it using object-oriented programming methods. C++ will
be used as a programming language in this course.

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 5


Course Learning Outcomes
No. Course Learning Outcome (CLO) Statements Domain Taxonomy PLO
Level
Write C++ programs that employ the use of pointers, and structures
1 (records). Cognitive C3 5

Apply the basic concepts of Object-Oriented Programming (class, object,


2 attributes, data hiding, constructors, destructor, static, constant, object as Cognitive C3 5
argument, array of objects) to write C++ programs by using
single/multiple objects.

Use the concepts of operator overloading, inheritance, aggregation,


3 friend function, virtual function, and polymorphism to write C++ Cognitive C3 5
programs.

4 Use the concept of file handling to read/write the data from binary and Cognitive C3 5
text files and write codes by using templates and exception handling.

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 6


Marks Distribution
• Mid I 15%
• Mid II 15%
• Quizzes (5-7) 10%
• Assignments (4) 05%
• Project (1) 05%
• Final 50%

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 7


Grading Scheme
• Absolute Grading scheme will be applied. Grades will be assigned
according to the following table.
Percentage Marks Grade GPA Percentage Marks Grade GPA
More than 90 A+ 4.00 66 – 70 C+ 2.33
86 – 90 A 4.00 62 – 66 C 2.00
82 – 86 A- 3.67 58 – 62 C- 1.67
78 – 82 B+ 3.33 54 – 58 D+ 1.33
74 – 78 B 3.00 50 – 54 D 1.00
70 – 74 B- 2.67 Less than 50 F 0

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 8


Attendance Policy and General
Rules
• 80% Attendance is a must
• It is a 3-credit hour course, so a maximum of 6 absents are allowed
• There will be zero tolerance on attendance

• Partially or fully copied assignments/reports will be marked as ZERO

• There will be no extension in deadlines

• We need to maintain discipline in the classroom and the use of cell


phones is not allowed during the class
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 9
How to Get a Good Grade?
• Don’t Think that Coding is Useless
• Don’t Skip the Classes
• Be Attentive in Class
• DO NOT Copy Assignments
• Code the Practice Problems at least Once
• Maintain Discipline in Class

• Follow the above points and you will definitely get a good grade 

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 10


C++ in this Course: Why?
Advantages Disadvantages
• Portability • Use of Pointers
• Object-oriented • Security Issue
• Multi-paradigm • No Garbage Collector
• Low-level Manipulation • Errors and Accuracy
• Memory Management • Slow Development
• Fast execution of programs • Depth of Knowledge required
Engineers mostly use programming for
• Embedded Systems Considering these applications
• Network Programming C++ is an excellent choice for
• Devices Interfacing
• AI, ML and IoT
Engineers at initial stage
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 11
NATIONAL UNIVERSITY
of Computer & Emerging Sciences
Chiniot-Faisalabad Campus

Now Let’s Start the


Course

Department of Electrical Engineering


Decision Making in C++
• Sometimes programs need to make some one-time decisions
• Decision causes a onetime jump to a different part of the program,
depending on the value of an expression
• Decisions can be made in C++ in several ways. The most important is
with the conditional structure (if – else if – else)
• We can use the conditional statement as:
• single if
• if-else
• if - else if - else

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 13


Conditional Structures (1/5)
• if statement
• Single entry/single exit statement
• The if statement lets you do something if a condition is true. If it isn’t
true, nothing happens

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 14


Conditional Structures (2/5)
• if .. else statement
• Can be used to execute some other instruction if
condition in “if” is not matched
• Why don’t we use two ifs instead of if-else?
• it is inefficient, because the compiler will be checking two
conditions instead of one

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 15


Conditional Structures (3/5)
• Nested if .. else statements
• We can have more ifs inside an if-else structure
• But it is important to match the else with correct if
• See the example code for possible errors
• Here is the rule: An else is matched with the last if that doesn’t have its own else
• It is better to use curly brackets for clarity and avoiding possible logical errors

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 16


Conditional Structures (4/5)
• else if statement
• Can be used for multiple comparisons and executions

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 17


Conditional Structure (5/5)
• While using if..else if..else statements keep the following points in
mind
• An if can have zero or one else's and it must come after any else if's
• An if can have zero to many else if's and they must come before the else
• Once an else if succeeds, none of the remaining else if's or else's will be
tested

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 18


Logical OR & AND Operators in
C++
• Logical OR is coded as || in C++
• Logical AND is coded as && in C++
• || and && operators are used to implement multiple conditions
inside if or else if statement
• For example, if we want to make a decision when the value of variable
is between 4 and 8, then we need to used || or && operator

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 19


Decision Making with Non-
Integer Numbers
• What will be the output of following program?
• If the user enters 4.00 gpa, it will print A grade
• If the user enters 3.67 or 3.33, it will print F grade
• It is due to insufficient number of bits to convert 3.67 or
3.33 to binary equivalent
• Hence, we will always use double data type for decision
making in non-integer numbers.

Correct Output

Incorrect Output

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 20


Example 1
• Write a C++ program which should take a year as an input and tells
the user either it is a leap year or not

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 21


Example 2
• Write a code to find out whether the number entered by the user is
vowel or not.

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 22


Example 3
• Write a C++ code which should ask the user to enter an integer and then
tells that either the number is a multiple of 5, 9 or both of them.

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 23


Example 4
• Write a C++ program which should ask
the user to enter a character and tells
that, either it is an upper case, lower
case, number or a special character.

Type ASCII Range


Digits (0 – 9) 48 – 57
Upper Case Letters (A – Z) 65 – 90
Lower Case Letters (a – z) 97 – 122
Special Characters 0-47, 58-64, 91-96,
123-127

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 24


Practice Problem 1
• Write a C++ program to compute and display the roots of a quadratic
equation entered by the user.

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 25


Iterative Structures
• Iterative structures are used to run the code/part of code for several
times
• Some iterative structures available in C++ are:
• For
• While
• Do-while
• All above have same purpose but used in different scopes

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 26


Essentials of Counter Controlled
Repetition
• Counter-controlled repetition requires
1. The name of a control variable (or loop counter)
2. The initial value of the control variable
3. The loop-continuation condition that tests for the final value of the control
variable (i.e., whether looping should continue)
4. The increment (or decrement) by which the control variable is modified
each time through the loop

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 27


for Loop
• The “for” loop executes a section of code for
a fixed number of times
• It’s usually (although not always) used when
you know, before entering the loop, how
many times you want to execute the code

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 28


Syntax of a “for” Loop
• The syntax of a “for” loop is given below

• If we want to print first 10 integers then the loop will look like this
Required Final value of control
Semicolon variable for which Required
Control variable Separator the condition is true Semicolon
initialization Separator

for keyword

Initial value Termination/continuation condition Updating the control variable

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 29


for Loop (Number of Iterations)
• We can use any valid arithmetic operator in for loop to modify the value of
loop variable
• Have a look at the following expressions and identify the number of
11 iterations (0 is included)
iterations
0 iterations (condition is false in 1st run)
1. for (int i=0; i<=10; i++)
11 iterations (0 is included)
2. for (int i=10; i>20; i--)
3. for (int i=0; i<=100; i+=10) infinite iterations (i will be 0 in each run)

4. for (int i=0; i<=10; i*=2) infinite iterations (condition is always true)
5. for (int i=0; i<50; i--) 0 iterations (condition is false in 1st run)
6. for (int i=10; i<=1; i++) infinite iterations (i will never be updated)
7. for (int i=0; i<=10; i+3)
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 30
NATIONAL UNIVERSITY
of Computer & Emerging Sciences
Chiniot-Faisalabad Campus

Object-Oriented
Programming
Lecture 2

Department of Electrical Engineering


Outline
• Review of continue and break statements
• Review of Iterative Structures (while and do-while loop)
• Review of functions

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 32


continue and break Statements
(1/3)
• break Statement
• We have already discussed earlier that, break statement is used to jump out of the
switch structure
• Similarly, if we write a break statement in a loop, it will terminate the loop (will help to
jump out of the loop)
for (int i = 0; i <= 5; i++)
{
if(i == 2)
{
break;
}
}
• The above code will have only 2 iterations, as if the value of i is equal to 2, it will
terminate the loop.
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 33
continue and break Statements
(2/3)
• continue Statement
• The continue statement is used to skip the current iteration of the loop and
the control of the program goes to the next iteration
for (int i = 0; i < 5; i++)
{
if(i == 2)
{
continue;
}
cout<<i<<endl;
}
• The above code will have four iterations, as if the value of i is equal to 2, it will
skip that iteration.
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 34
continue and break Statements
(3/3)
for (int i = 0; i <= 5; i+ for (int i = 0; i <= 5; i+
+) +)
{ {
if(i == 2) if(i == 2)
{ {
break; continue;
} }
cout<<i<<endl; cout<<i<<endl;
} }
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 35
Variable Visibility in Blocks
• The loop body, which consists of braces determining the boundary of several statements, is
called a block of code
• Predict the output of the following code

for(int i=0; i<10; i++)


{
int num;
num = num + i;
}
cout<<num<<endl;

• The above program will generate an error, because the variables defined inside any block are
invisible to rest of code and cannot be accessed outside that block
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 36
Placing a Semicolon After for
Loop
• If we place a semicolon after a for loop like this:
for(int a = 0; a <= 5; a++);
{
cout<<“Hello”<<endl;
}
• Then it do the followings:
• Repeat six times for (a=0;a<=5;a++)
• do nothing (semicolon)
• Open a new scope for local variables {
• Print "hello"
• Close the scope }
• The operation that gets repeated is ; not the cout
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 37
Review Question 1
Identify the number of iterations and output of the following code.

for(int a=0; a<=5; a++)


{
cout<<"a = "<<a<<endl;
}

6 iterations

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 38


Review Question 2
Identify the number of iterations and output of the following code.

for(int a=0, b=5; b >= 2; a++, b--)


{
cout<<"a = "<<a<<"\tb = "<<b<<endl;
}

4 iterations

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 39


Review Question 3
Identify the number of iterations and output of the following code.

for(int a=0, b=5; a <= 5 && b >= 2; a++, b--)


{
cout<<"a = "<<a<<"\tb = "<<b<<endl;
}

4 iterations

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 40


Review Question 4
Identify the number of iterations and output of the following codes.

Hello will be printed only once

Syntax Error

a = 6 will be displayed

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 41


While Loop
• Identical to a “for” loop
• Will repeat a specific section of code for multiple times
• We use “while loop” when we don’t know exactly that how many
times the code/section of code will repeat

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 42


Syntax of while Loop
Loop variable declaration;
while(loop continuation condition)
{
Statements;
Updating in loop variable;
}

int a = -1;
while(a < 0)
{
cout<<“Enter the value of a: ”;
cin>>a;
}
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 43
continue and break Statements
with “while”
• Break Statement • Continue Statement

int a = 0; int a = 0;
while(a < 5) while(a < 5)
{ {
if(a == 2) if(a == 2)
{ {
break; continue;
} }
cout<<"a = "<<a<<endl; cout<<"a = "<<a<<endl;
a++; a++;
} }

• The loop terminates, once the break statement is • Will result in infinite iterations, as “a” will not exceed
executed. from 2

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 44


Variable Visibility in While Loop
• The variables declared inside the while loop cannot be used outside the loop.

int a = 0;
int a = 0;
while(a <= 5) int b = 5;
{

Output = 20
while(a <= 5)
int b = 5; {
b = b + a; b = b + a;
a++;
a++;
}
} cout<<b<<endl;
cout<<b<<endl;

• The above code will generate a syntax error, as we are using the local variable
outside its scope.
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 45
Placing a Semicolon after While
Loop
• Placing a semicolon after the while loop, will result in infinite
iterations
• Because the loop body never executes, and the compiler will keep on
checking the loop condition

int a = 0;
while(a <= 5);
{
cout<<“a = ”<<a<<endl;
a++;
}
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 46
do-while Loop
• Do-while loop will also repeat the specific section of code
multiple times.
• Do-while loop is used when we want to make sure at least one
iteration
• The syntax of a do-while loop is given below

do
{
Statements;
}
while(condition);

• The above loop will keep on iterating until the condition is true
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 47
Comparison of “for”, “while”
and “do” loop
• for loop
• Used when we know that how many times the code/section of code will
repeat
• Runs for fixed number of times and minimum iterations are 0
• while loop
• Used when we don’t know that how many time the code will repeat
• Loop condition is evaluated at the start loop will iterate minimum 0 times
• do-while loop
• Used to repeat a code until the user wants
• Condition is evaluated at the end of loop loop will iterate at least 1 time

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 48


Function
• A function is a group of statements that together perform a specific
task and often returns a value
• Every C++ program has at least one function, which is main()
• You can divide up your code into pieces by separate functions
• How you divide up your code among different functions is up to you,
but logically the division usually is so each function performs a
specific task

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 49


Types of Functions
• Function in C++ are of two types
• Built-in functions
• The functions which comes with the library are built-in functions
• log(x), pow(), sqrt(), etc
• User defined functions
• The functions which are coded by the users for specific tasks are called user defined
functions
• The function made to print a line etc

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 50


User Defined Functions
• We can directly use the built-in functions by direct calling them
• For user defined functions we can use the function in following
sequence
• Declare Define Call (use)

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 51


Function Declaration
• A function declaration is made by declaring
• Return type of the function
• Name of the function (Any valid identifier)
• Data types of the parameters

Return_type function_name(parameter list);

int max(int x, int y);


• Function declaration is optional
• If we are defining the functions in the end, then we need to declare the
functions first
• Otherwise there is no need to declare a function
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 52
Function Definition
• A function definition provides the actual body of the function. Parts of a
function’s definition are:
• Return Type
• A function may return a value. The return_type is the data type of the value the function returns.
For example void, int or float
• Function Name
• This is just an identifier
• Parameters
• A parameter is like a placeholder. When a function is invoked, you pass a value to the parameter.
This value is referred to as actual parameter or argument. The parameter list refers to the type,
order, and number of the parameters of a function. Parameters are optional; that is, a function
may contain no parameters.
• Function Body
• The function body contains a collection of statements that define what the function does.
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 53
Function Definition– Example
Return_type function_name(parameter list)
{
Body of the function;
}

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 54


Calling a Function
• To use a function we need to invoke the function in our main program
• To call a function we simply need to pass the required parameters
along with function name and return type
• When a program calls a function, program control is transferred to the
called function. A called function performs defined task and when its
return statement is executed or when its function-ending closing
brace is reached, it returns program control back to the main program

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 55


Example of User Defined
Function

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 56


Function Arguments
• If a function is to use arguments, it must declare variables that accept
the values of the arguments. These variables are called the formal
parameters of the function
• The formal parameters behave like other local variables inside the
function and are created upon entry into the function and destroyed
upon exit

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 57


When to use Arguments?
• The arguments are not necessary when:
• The function is performing some independent operation on some fixed data
• User is asked to enter all the required information for specific operation in the
body of the function
• We will use the arguments when:
• The operations performed by the function are depending upon some other
value generated in the main code
• When input is entered by the user before calling the user

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 58


Example 1
• Write a function to print a line of 80 stars (*).

• Here the function is performing some independent task on a fixed data. Hence no
parameters are required.

void print_line()
{
for(int i=0; i<80; i++)
{
cout<<“*”;
}
}
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 59
Example 1 (Modification 1)
• Write a function to print a line of 80 characters entered by the user.

• Now the character is not fixed, we need to pass a character as an argument.

void print_line(char ch)


{
for(int i=0; i<80; i++)
{
cout<<ch;
}
}
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 60
Example 1 (Modification 2)
• Write a function to print a line of n (n is an integer) characters entered by the user.

• Now both the number of iterations and the character are not fixed, we need to pass two
arguments (one integer and one character).

void print_line(int n, char ch)


{
for(int i=0; i<n; i++)
{
cout<<ch;
}
}
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 61
Example 1 (Modification 3)
• Write a function to print a line of n (n is an integer) characters entered by the user, at the end return the
value that how many times a character is printed.

• Now both the number of iterations and the character are not fixed, we need to pass two arguments (one
integer and one character).
• In the end we need to return an integer as well.

int print_line(int n, char ch)


{
for(int i=0; i<n; i++)
{
cout<<ch;
}
return n;
}
CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 62
Passing the Arguments
• While calling a function, there are two ways that arguments can be
passed to a function
• Pass by value
• Pass by reference

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 63


Argument Call by Value
• This method copies the actual value of an argument into the formal parameter of the
function.
• Passing arguments in such a way, where the function creates copies of the arguments
passed to it, is called passing by value

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 64


Passing Arguments by
Reference
• Passing by value has some limitations and can be inefficient and slow while passing arrays and
structures
• So, to overcome this problem we use the call by reference method
• The call by reference method of passing arguments to a function copies the reference of an argument
into the formal parameter
• In call by reference, we modify the original argument of function by directly using its address

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 65


Advantages of Pass By
Reference
• It allows a function to change the value of the argument
• Because a copy of the argument is not made, it is fast, even when
used with large structures or classes
• References can be used to return multiple values from a function

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 66


Returning Multiple Values from
Functions
• Functions can only have one return value
• One way to return multiple values is using reference parameters
• As in reference parameters the values are updated on the address,
and that address is passed to the passing argument
• So, we can access the updated value even after the execution of the
function
• In these types of functions, the return type of function is still void
because it is returning nothing, but we are using the updated values
directly by accessing their address

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 67


When to Use which method to
Pass?
• Pass by reference is used:
• When passing structures, large arrays or classes
• When you need the function to modify an argument
• When you need to return more than one values
• Pass by value is used:
• When passing fundamental types

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 68


Example 1
• Write a C++ program to print the following patterns.

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 69


Example 2
• Write a function definition to calculate the electricity bill according to
the following table. There must be no cin and cout statements in the
function definition.
Residential Commercial
Units Consumed Per Unit Cost Units Consumed Per Unit Cost
Less than 100 7/- Less than 100 32/-
100 – 300 12/- 100 – 300 45/-
Greater than 300 25/- Greater than 300 60/-
GST = 17% of total electricity cost GST = 17% of total Electricity cost
Other taxes = 1000/- fix Other taxes = 3000/- fix

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 70


Default Values for Parameters
• When we define a function, we can specify a default value for each of
the last parameters.
• This value will be used if the corresponding argument is left blank
when calling to the function
• This is done by using the assignment operator
• If a value for that parameter is not passed when the function is called,
the default given value is used
• But if a value is specified, this default value is ignored and the passed
value is used instead

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 71


Default Values for Parameters–
Example

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 72


Advantages of Functions
• Functions helps us by
• Making the coding easier and understandable
• Dividing the task so that several programmers can work independently
• Making the part of code reusable to less amount of work required to perform
the same task

CS1004 - OOP Course Instructor: Muhammad Sajid Iqbal 73

You might also like