This document discusses object-oriented programming concepts in C++ including objects as function parameters and return types, friend classes and functions. It provides examples of passing an object as a parameter to a function, returning an object from a function, and declaring friend classes and functions to access private members. The examples demonstrate how to add values of object data members when an object is passed as a parameter or returned.
This is the object oriented lecture nmbr 3rd , if you want lecture 2 or 1 u can check it my account , this is the programing tutorial, please follow me and thank you
2nd puc computer science chapter 8 function overloading ,types of function overloading ,syntax function overloading ,example function overloading
inline function, friend function ,
Classes and Objects
Classes in C++
Declaring Objects
Access Specifiers and their Scope
Defining Member Function
Overloading Member Function
Nested class
Constructors and Destructors
Introduction
Characteristics of Constructor and Destructor
Application with Constructor
Constructor with Arguments (parameterized Constructors)
Destructors
This is the object oriented lecture nmbr 3rd , if you want lecture 2 or 1 u can check it my account , this is the programing tutorial, please follow me and thank you
2nd puc computer science chapter 8 function overloading ,types of function overloading ,syntax function overloading ,example function overloading
inline function, friend function ,
Classes and Objects
Classes in C++
Declaring Objects
Access Specifiers and their Scope
Defining Member Function
Overloading Member Function
Nested class
Constructors and Destructors
Introduction
Characteristics of Constructor and Destructor
Application with Constructor
Constructor with Arguments (parameterized Constructors)
Destructors
Introduction to AI for Nonprofits with Tapp NetworkTechSoup
Dive into the world of AI! Experts Jon Hill and Tareq Monaur will guide you through AI's role in enhancing nonprofit websites and basic marketing strategies, making it easy to understand and apply.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
Macroeconomics- Movie Location
This will be used as part of your Personal Professional Portfolio once graded.
Objective:
Prepare a presentation or a paper using research, basic comparative analysis, data organization and application of economic information. You will make an informed assessment of an economic climate outside of the United States to accomplish an entertainment industry objective.
Acetabularia Information For Class 9 .docxvaibhavrinwa19
Acetabularia acetabulum is a single-celled green alga that in its vegetative state is morphologically differentiated into a basal rhizoid and an axially elongated stalk, which bears whorls of branching hairs. The single diploid nucleus resides in the rhizoid.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
Francesca Gottschalk - How can education support child empowerment.pptxEduSkills OECD
Francesca Gottschalk from the OECD’s Centre for Educational Research and Innovation presents at the Ask an Expert Webinar: How can education support child empowerment?
1. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Women University of Azad Jammu and Kashmir Bagh
Department of Computer Sciences and Information Technology, Women University of Azad Jammu and Kashmir Bagh
www.wuajk.edu.pk
Object Oriented Programming
CS-3201
Dr. Anees Qumar Abbasi
aneesabbasi.wuajk@gmail.com
2. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Objects as Function Parameters
& Return Type
Friend Classes & Functions
3. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Object as Function Parameters
• Objects can also be passed as parameters to member functions.
• The method of passing objects to a functions as parameters is as
passing other simple variables.
• It will easily be understand by following example.
4. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Example: Object as Parameter
void add(Travel p)
{
Travel t;
t.km=km+p.km;
t.hr=hr+p.hr;
cout<<“Total traveling
is ”<<t.km<<“ kilometers
in
”<<t.hr<<“ hours”<<endl;
}
};
void main()
{
Travel my, your;
my.get();
my.show();
your.get();
your.show();
my.add(your);
getch();
}
class Travel
{
private:
int km, hr;
public:
Travel()
{
km=hr=0;
}
void get()
{
cout<<“Enter Kilometers
traveled”;cin>>km;
cout<<“Enter Hours
traveled”;cin>>hr;
}
void show() {
cout<<“You traveled
”<<km<<“ in ”<<hr<<“
hours”<<endl;
}
5. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
How Program Works
void add(Travel p) {
Travel t;
t.km = km + p.km;
t.hr = hr + p.hr;
}
• Data members of temporary object t
• Data members of temporary object my
• Data members of temporary object p
• The above program declares to objects of class Travel and inputs data in both objects.
• The add() function accepts an object of type Travel as parameter.
• It adds the values of data members of the parameter object and the values of calling object’s data members
and displays the result.
• The working of member function add() is as follows:
Function call in main
my.add(your);
6. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Returning Objects from Member Function
• The method of returning an object from member function is same as
returning a simple variable.
• If a member function returns an object, its return type should be the
same as the type of object to be returned.
7. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Example: Object as Parameter
Travel add(Travel p)
{
Travel t;
t.km=km+p.km;
t.hr=hr+p.hr;
return t;
}
};
void main()
{
Travel my, your, r;
my.get();
my.show();
your.get();
your.show();
r = my.add(your);
cout<<“Total travelling is as
follow:n”;
r.show();
getch();
}
class Travel
{
private:
int km, hr;
public:
Travel()
{
km=hr=0;
}
void get()
{
cout<<“Enter Kilometers
traveled”;cin>>km;
cout<<“Enter Hours
traveled”;cin>>hr;
}
void show() {
Cout<<“You traveled
”<<km<<“ in ”<<hr<<“
hours”<<endl;
}
8. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
• The add() function in the above program accepts a parameter object
of type Travel.
• It adds the contents of parameter and calling object and stores the
result in a temporary object.
• The function then returns the whole object back to main() function
that is stored in r.
• The program finally displays the result using r.show() statement.
How Program Works
9. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Friend Classes
A friend class can access private and protected members of other classes in
which it is declared as a friend. It is sometimes useful to allow a particular
class to access private and protected members of other classes.
We can declare a friend class in C++ by using the friend keyword.
friend class class_name; // declared in the base class
10. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Example: Friend Class
class GFG {
private:
int private_variable;
protected:
int protected_variable;
public:
GFG()
{
private_variable = 10;
protected_variable = 99;
}
// friend class declaration
friend class F;
};
// Here, class F is declared as a
friend inside class GFG. Therefore,
F is a friend of class GFG. Class F
can access the private members of
class GFG.
class F {
public:
void display(GFG& t)
{
cout << "The value of Private Variable
= "<< t.private_variable << endl;
cout << "The value of Protected
Variable = "<< t.protected_variable;
}
};
// Driver code
int main()
{
GFG g;
F fri;
fri.display(g);
return 0;
} Output:
The value of Private Variable = 10
The value of Protected Variable = 99
11. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Friend Function
Like a friend class, a friend function can be granted special access to private and
protected members of a class in C++. They are the non-member functions that can
access and manipulate the private and protected members of the class for they are
declared as friends.
A friend function can be:
1. A global function
2. A member function of another class
12. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Friend Function
Syntax:
friend return_type function_name (arguments); // for a global function
or friend return_type
class_name::function_name (arguments);// for a member function of other class
13. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Example: Friend Function
1. Global Function as Friend Function
class base {
private:
int private_variable;
protected:
int protected_variable;
public:
base()
{
private_variable = 10;
protected_variable = 99;
}
// friend function declaration
friend void friendFunction(base&
obj);
};
// friend function definition
void friendFunction(base& obj)
{
cout << "Private Variable:" <<
obj.private_variable<< endl;
cout << "Protected Variable:" <<
obj.protected_variable;
}
int main()
{
base object1;
friendFunction(object1);
return 0;
}
Output:
Private Variable: 10
Protected Variable: 99
14. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Example: Friend Function
2. Member Function of Another Class a Friend Function
class anotherClass {
public:
void memberFunction();
};
// base class for which friend is
declared
class base {
private:
int private_variable;
protected:
int protected_variable;
public:
base()
{ private_variable = 10;
protected_variable = 99; }
// friend function declaration
friend void
anotherClass::memberFunction();
};
// friend function definition
void anotherClass::memberFunction(base&
obj)
{
cout << "Private Variable: " <<
obj.private_variable<< endl;
cout << "Protected Variable: " <<
obj.protected_variable;
}
Void main()
{
base object1;
anotherClass object2;
object2.memberFunction(object1);
}
Output:
Private Variable: 10
Protected Variable: 99
15. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Features of Friend Functions
q A friend function is a special function in C++ that in spite of not being a member
function of a class has the privilege to access the private and protected data of a
class.
q A friend function is a non-member function or ordinary function of a class, which is
declared as a friend using the keyword “friend” inside the class. By declaring a
function as a friend, all the access permissions are given to the function.
q The keyword “friend” is placed only in the function declaration of the friend function
and not in the function definition or call.
q A friend function is called like an ordinary function. It cannot be called using the
object name and dot operator. However, it may accept the object as an argument
whose value it wants to access.
q A friend function can be declared in any section of the class i.e. public or private or
protected.
16. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Friend Functions
Advantages of Friend Functions
• A friend function is able to access members without the need of inheriting the
class.
• The friend function acts as a bridge between two classes by accessing their
private data.
• It can be used to increase the versatility of overloaded operators.
• It can be declared either in the public or private or protected part of the class.
Disadvantages of Friend Functions
• Friend functions have access to private members of a class from outside the class
which violates the law of data hiding.
• Friend functions cannot do any run-time polymorphism in their members.
17. Department of Computer Sciences & Information Technology
Dr. Anees Qumar Abbasi- Object-Oriented Programming
Friend Functions & Classes
v Friends should be used only for limited purposes. Too many functions or external
classes are declared as friends of a class with protected or private data access
lessens the value of encapsulation of separate classes in object-oriented
programming.
v Friendship is not mutual. If class A is a friend of B, then B doesn’t become a friend of
A automatically.
v Friendship is not inherited.
v The concept of friends is not in Java.