Sunday 8 April 2018

Destructor execution in Inheritance

Destructor in Inheritance

As we know destructor are used to free memory which is occupied by the object. A we have seen , the constructor are executed from base class to the derived class. In contrast the destructor are executed in the reverse order that is from most derived class to the base class.

#include<iostream.h>  
#include<conio.h>
 class A
 {
 public:
 ~A( )
 {
 cout<<"\n\n\t Hi I am from---> A";
}
  };
  class B:public A
  {
public:
  ~B( )
  {
  cout<<"\n\n\t Hi I am from---> B";
}
  };
  class C:public B
  {
  public:
  ~C( )
  {
  cout<<"\n\n\t Hi I am from---> C";
  }
  };
  void main( )
  {
  //clrscr( );
  C c1;  
getch( );
  }
 

Output:-
 Hi I am from---> A
 
Hi I am from---> B
 
Hi I am from---> C

Constructor execution in Inheritance

We know that constructor are used to initialize object. In the inheritance without initializing the base class members we can not derive the members of the base class to its derive class.

Therefore base class constructor are executed and then derive class constructor is executed. We must note here that if the base class constructor does not take any parameters then it is not necessary for the derived class to have a constructor.

In such situation , the base class constructor is called first and then the derived class constructor is executed.

#include<iostream.h>
#include<conio.h>
class A
{
public:
A( )
{
cout<<"\n\n\t Hi I am from A";
}
};
class B:public A
{
public:
B( )
{
cout<<"\n\n\t Hi I am from B";
}
};
class C:public B
{
public:
C( )
{
cout<<"\n\n\t Hi I am from C";
}
};
void main( )
{
clrscr( );
C c1;
getch( );
}

Output:-
Hi I am from A

Hi I am from B

Hi I am from C

Use for Heading and Paragraph

This is used for give a heading and paragraph of Website design.

Syntax:-
<h> This is Heading 1  </h>    This is a heading tag.
<p> This is a Paragraph1 </p>  This is a Paragraph tag.

Example:-
<html>

<head>

<title>Irawen </title>

</head>

<body>

<h1>Heading1</h1>

<h2>Heading2</h2>

<h3>Heading3</h3>

<h4>Heading4</h4>

<p>This is a first Paragraph</p>

<p>This is a second Paragraph</p>

<p>This is a third Paragraph</p>

<p>This is a fourth Paragraph</p>

</body>

</html>

Output:-
 

Introduction of HTML

What is HTML? 
    HTML stands for Hypertext  Markup Language , Which is used to design HTML Web pages or Templates.

Why it is called Markup Language? 
    Because it is set of markup  tags .These tags are surrounded by angle brackets.

Requirements to design HTML page?
   Browser + Text editor

How to use a HTML?

  • HTML program is always save as Filename.html
  • It is written as a notepad and notepad++.
Example:-
  <html>      //This is open tag.
  <head>
  <tittle> Welcome </tittle>     //This is write a Tittle of Website.
  </head>
  </html>  This is a closed tag.

—>This is a simple code of html.

Virtual Base Class

Consider a situation where multilevel multiple and hierarchical all the three kinds are inherited.



In the above figure the base class is inherited by both Derived1 and Derived2. Derived 3 directly inherits both Derived and Derived2.

All the public and protected member of base are inherited into Derived3 twice through both Derived 1 and Derived2.

Therefore Derived3 would have duplicate sets of members inherited. This causes ambiguity when member of base is used by Derived.

To Resolve this ambiguity, cpp includes a mechanism by which only one copy of base will be included in derived3. And this feature is called as virtual base class.

When a class is made virtual, cpp takes necessary care to inherit only only one copy of the class.

The keyword virtual precedes the base class access specifiers when it is inherited by derived class.

Ex:
Class Base
{

};
Class Derived1 : virtual public Base
{

};
Class Derived2 : virtual  public Base
{

};
Class Derived3 : public Derived1, public Derived2
{

};

#include<iostream.h>
#include<conio.h>
class student
{
protected:
int rollno;
public:
void getrollno(int n)
{
rollno=n;
}
void display1( )
{
cout<<"\n\n\tRoll no is--->"<<rollno;
}
};
class test:virtual public student
{
protected:
int cpp;
int rdbms;
public:
void getmarks(int c, int r)
{
cpp=c;
rdbms=r;
}
void display2( )
{
cout<<"\n\n\tMarks of cpp is--->"<<cpp;
cout<<"\n\n\tMarks of rdbms is--->"<<rdbms;
}
};
class spots:virtual public student
{
protected:
int sportwt;
public:
void getsportmark(int s)
{
sportwt=s;
}
void display3( )
{
cout<<"\n\n\tSport Marks is--->"<<sportwt;
}
};
class rest:public test,public sport
{
protected:
int total;
public:
void calresult( )
{
total=cpp+rdbms+sportwt;
}
void display( )
{
display1( );
display2( );
display3( );
cout<<"\n\n\tTotal Result is--->"<<total;
}
};
void main( )
{
result R;
clrscr( );
R.getrollno(101);
R.getmarks(78,87)
R.getsportmark(10);
R.calresult( );
R.display( );
getch( );
}

Output:-
Roll no is--->101
Marks of cpp is--->78
Marks of rdbms is--->87
Sport Marks is--->10
Total Result is--->175

Types of Inheritance

1. Single level Inheritance
2. Multilevel Inheritance
3. Multiple Inheritance
4. Hierarchical Inheritance
5. Hybrid Inheritance

Single level Inheritance
  A derived class with only one base class is called as single level inheritance.


Here 'A' is superclass or base class.From the class 'A' , the class 'B' is derived so class 'B' is called as subclass of class 'A'.
Identify the type of inheritance and implement it by writing a program for the following figure. Assume suitable member function.



#include<conio.h>
#include<iostream.h>
class student
{
int roll_no;
char name[20];
public:
void accept( )
{
cout<<"\n\tEnter Roll No of Student";
cin>>roll_no;
cout<<"\n\tEnter Name of the student";
cin>>name;
}
void display( )
{
cout<<"\n\tRollNo is--->"<<roll_no;
cout<<"\n\tName is--->"<<name;
}
};
class Eng_student : public student
{
char branch[20];
public:
void accept1( )
{
cout<<"\n\tEnter Branch of student";
cin>>branch;
}
void display( )
{
cout<<"\n\tBranch is--->"<<branch;
}
};
void main( )
{
Eng_student est;
clrscr( );
est.accept( );
est.accept1( );
est.display( );
est.display1( );
getch( );
}

Output:-
Enter Roll NO of Student 101
Enter Name of the student Irawen
Enter Branch of student CS

RollNO is--->101
Name is--->Irawen
Branch is--->CS 


Multilevel Inheritance
   
  The mechanism of deriving a new class from another "derived class" is known as multilevel Inheritance.


The above figure shows multilevel inheritance. The class A serves as a base class for the derived class B which in turn serves as a base class for the derived class C.

The class B is known as inheritance base class since it provides a link for the inheritance between A and C.

Multilevel Inheritance is declared as
Class A
{

};

Class B :public A
{

};

Class C :public B
{

};

The derived class after inheritance would contain its own data members and member function plus members from inheritance base class in addition with members from base class.


Ex:

#include<conio.h>
#include<iostream.h>
class student
{
protected:
int rollno;
public:
void getno(int a);
void putno( );
};
void student::getno(int a)
{
rollno = a;
}
void student::putno( )
{
cout<<"\n\tRollno is--->"<<rollno;
}
class test : public student
{
protected:
float sub1;
float sub2;
public:
void getmarks(float s1, float s2)
{
sub1 = s1;
sub2 = s2;
 }
void putmarks( );
{
cout<<"\n\tMarks of subject1--->"<<sub1<<"\n";
cout<<"\n\tMarks of subject2--->"<<sub2<<"\n";
}
};
class result : public test
{
float total;
public:
void display( )
{
total = sub1 + sub2;
putno( );
putmarks( );
cout<<"\n\tTotal Marks is--->"<<total<<"\n";
}
};
void main( )
{
result st1;
clrscr( );
st1.getno(101);
st1.getmarks(78,56);
st1.display( );
getch( );
}

Output:-
Rollno is--->101
Marks of subject--->78

Marks of subject2--->56

Total Marks is--->134


Multiple Inheritance

  A derived class with the several base class is class is called as multiple inheritance.



Multiple inheritance allows us to combine the features of several existing classes such as starting point for defining new classes.

Syntax:-
Class D : visibility B1, visibility B2 ................visibility Bn
{
//Body of D
};

Ex:
Class B1
{
//Body of B1;
};
Class B2
{
//Body of B2;
};
Class D : public B1 , public B2
{
 //Body of D
}; 

Write a program to implement multiple inheritance

#include<conio.h>
#include<iostream.h>
class base1
{
protected:
int m;
public:
void getm(int m1)
{
m = m1;
}
};
class base2
{
protected :
int n;
public:
void getn(int n1)
{
n = n1;
}
};
class derived:public base1,public base2
{
public:
void display( )
{
cout<<"\n\tvalue of m is--->"<<m;
cout<<"\n\tvalue of n is--->"<<n;
cout<<"\n\tvalue of (m*n) is--->"<<(m*n);
}
};
void main( )
{
derived d;
clrscr( );
d.getm(10);
d.getn(20);
d.display( );
getch( );
}

Output:-
value of m is--->10
value of n is--->20
value of (m*n) is--->200


Hierarchical Inheritance

  When one class may be inherited by more than one class class is known as hierarchical inheritance.

Programming problems can be cast into a hierarchy where certain features of one level are shared by many others below that level.



Here class 'B' and 'C' are derived from class 'A'. that is 'A' is a super class for both the class 'B' and 'C'.

Write a program to implement inheritance shown below. Assume suitable member function.



#include<conio.h>
#include<iostream.h>
class president
{
protected:
char name_p[15];
public:
void accept( )
{
cout<<"\n\tEnter Name of the president";
cin>>name_p;
}
void display( )
{
cout<<"\n\tName of the President--->"<<name_p;
}
};
class vice_president : public president
{
protected:
char name_vp[20];
public:
void accept1( )
{
cout<<"\n\tEnter Name of the vice president";
cin>>name_vp;
}
void display( )
{
cout<<"\n\tName of the vice president is--->"<<name_vp;
}
};
class secretary : public president
{
protected:
char name_s[20];
public:
void accept2( )
{
cout<<"\n\tEnter Name of the secreatry is--->"<<name_s;
}
};
void main( )
{
clrscr( );
vice_president vp;
vp.accept( );
vp.accept1( );
secretary s;
s.accept( );
vp.display( );
vp.display1( );
s.display2( );
getch( );
}

Output:-
Enter Name of the president Irawen
Enter Name of the vice president Pirawen
Enter Name of the secreatry Ntirawen

Name of the President---> Irawen
Name of the vice president--->Pirawen
Name of the secreatry is--->Ntirawen



Hybrid Inheritance

When more than one type of the inheritance is used in any design , it is called as hybrid inheritance

There could be situation where we need to apply two or more types of inheritance to design a problem.
Ex:


Consider the case of processing the students result, we have to give weightage for sports before finishing the result. Weightage for sports before finishing the result. Weightage for sports is stored on separate class called as sports.

The new inheritance relationship between various classes would be as follows.


Write a program to implement hybrid inheritance

#include<iostream.h>
#include<conio.h>
class student
{
protected:
int rollno;
public:
void getno(int a)
{
rollno = a;
}
void putno( )
{
cout<<"\n\n\tRoll No is--->"<<rollno;
}
};
class test : public student
{
protected:
float part1,part2;
public:
void getmarks(float x, float y)
{
part1 = x;
part2 = y;
}
void putmarks( )
{
cout<<"\n\n\tMarks Obtained:"<<part1<<"\t"<<part2;
}
};
class spots
{
protected:
float score;
public:
void getscore(float s)
{
score s;
}
void putscore( )
{
cout<<"\n\n\tSport Weightage is--->"<<score;
}
};
class result : public test,public sports
{
float total;
public:
void display( )
{
total = part1 + part2 + score;
putno( )
putmarks( );
putscore( );
cout<<"\n\n\tTotal Score is--->"<<total<<"\n";
}
};
void main(  )
{
result s1;
clrscr( );
s1.getno(101);
s1.getmarks(78.12,76.23)
s1.getscore(10.0)
s1.display( );
getch( );
}

Output:-
Roll NO is--->101

Marks Obtained :78.120083      76.23003

Sports Weightage is--->10

Total Score is--->164.350006

Friday 6 April 2018

Inheritance

Inheritance is the process by which object of one class an acquire the properties of another class.

Inheritance helps for software reusability in which new classes are created from existing classes by absorbing  their attributes and behaviors.

If user want data member and member function of existing class, user can inherit data member and member function of old class with the help of inheritance.

The existing class from which new class is derived is known as base class or parent class or super class. The derived class is known as sub class or child class.

The derived class can add data members and member functions of its own so derived class can be larger than its base class.

When a class inherits another , the member of the base class becomes members of the derived class.

The syntax of deriving new class from old class-

class derivedclassname : accessmodifier baseclassname
 {
   //Body of the class
};


 The above syntax contains

1. The keyword class
2. derivedclassname which is user defined name for new class
3. The : (Colon) indicates that the derived class name is derived from the base class.
4. The access modifier is optional. If no access modifier is present, them access modifier is private by default.
5. baseclassname is the existing class name.

Ex:
class base
{
//body of the base class
};
Class derived1:private base   //private Derivation


};
Class derived2:public base     //public Derivation


};
Class derived3:protected base   //protected Derivation
{

};

Public Inheritance

When the access specifier for the a base class is public that is when base class is publicly inherited by a derived class all public member of the base class becomes public members of the derived class and all the protected members of the base class becomes protected members of the derived class.

Base class private elements remain private to the base class an are not accessible by the members of the derived class.

Program for demonstrating public Inheritance:

#include<iostream.h>
#include<conio.h>
class base
{
int i,j;
public:
void set(int a, int b)
{
i = a;
j = b;
}
void show( )
{
cout<<"Value of i is--->"<<i<<"\tValue of j is--->"<<j<<"\n";
}
};
class derived : public base
{
int k;
public:
derived(int x)
{
k = x;
}
void showk( )
{
cout<<"\nValue of k is--->"<<k<<"\n";
}
};
void main( )
{
derived ob(3);
clrscr( );
ob.set(1,2);
ob.show( );
ob.showk( );
getch( );
}

Output:-
Value of i is--->1             Value of k is--->2
Value of k is--->3


Protected Access Specifiers :
   When user declare class members as protected , these class members are private to their own class but can still be inherited and accessed by derived class.

Program  to demonstrate protected access specifies for data members of class.

#include<conio.h>
#include<iostream.h>
class base
{
protected:
int i,j;
void set(int a, int b)
{
 i = a;
j = b;
}
void show( )
{
cout<<"\nValue of i is--->"<<i<<"\tValue of j is--->"<<j;
}
};
class derived : public base
{
int k;
public:
void setk( )
{
k = i*j;
}
void showk( )
{
cout<<"\tValue of the k is--->"<<k<<"\n";
}
};
void main( )
{
derived ob;
clrscr( )
{
ob.set(2,3);
ob.show( );
ob.setk( );
ob.showk( );
getch( );
}

Output:-
Value of i is--->2     Value of j is--->3    Value of the k is--->6

Private Inheritance

When the base class is inherited by using the private access specifiers, all public and protected members of the base class becomes private members of the derived class.


Write a program to demonstrate private

#include<conio.h>
#include<iostream.h>
class base
{
int i,j;
public:
void set(int a, int b)
{
i = a;
j = b;
}
void show( )
{
cout<<\nValue of i is--->"<<i<<"Value of j is--->"<<j<<"\";
}
};
class derived : private base
{
int k;
public:
derive(int x)
{
k = x;
}
void showk( )
{
cout<<"Value of k is--->"<<k<<"\n";
}
};
void main( )
{
derived ob(3);
clrscr( );
ob.set(1,2);   //ERROR, can not access set
ob.show( );   //ERROR, can not access set
getch( );
}

Note: The program will not compile because you are typing to access private members of the object.

Protected Inheritance 

It is possible to inherit a base class as protected.

When this is done all public and protected members of the base class becomes protected members of the derived class.

Program to demonstrate Protected Inheritance

#include<conio.h>
#include<iostream.h>
class base
{
protected:
int i,j;
public:
void setij(int a, int b)
{
i = a;
j = b;
}
void showij( )
{
cout<<"Value of i is--->"<<i<<"\tValue of j is--->"<<j<<"\n";
}
};
class derived : protected base
{
int k;
public:
void setk( )
{
setij(10,12)
k = i*j;
}
void showall( )
{
cout<<"Value of k is--->"<<k<<"\n";
showij( );
}
};
void main( )
{
derived ob;
clrscr( );
ob.setk( );
ob.showall( );
//ob.showij( );  //Ellegal not accessible
getch( );
}

Output:-
Value of k is--->120
Value of  i is--->10     Value of j is--->12

Thursday 5 April 2018

Rules for Binary operator

Only existing can be overloaded. New operators can not be created.

The overloaded operator must have at least one operand that is user defined type.

We can not change the basic meaning of operator.

Overloaded operator follows the syntax rules of the original operators. They can not be overridden

There are some operators which can not be overloaded such as

Sizeof----------->Size of Operator

         ----------->Membership Operator

        ------------>Scope Resolution Operator

        ------------>Conditional Operator

We can use friend function to overload operators

Unary operators overloaded means of member function take no explicit argument and return no explicit value.

Binary operators overloaded through a member function take one explicit argument.

When binary operators overloaded through member function then left hand operand must be object of relevant class.

Limitation OR Pitfalls of Operator Overloading

The prefix ++ or - notation (Ex  ++x  or  --x) cause a variable to be updated before its value is used in the expression , where as postfix ++ or -- notation (Ex  x++  or   x--)  Cause it to be updated after its value is used. However , the statement,

++s;
Has exactly the same effect statement
s++;

When ++ and -- operators are overloaded that is there is no distincton between  the prefix and postfix overloaded operator function.

#include<conio.h>
#include<iostream.h>
class increment
{
int x,y,z;
public:
void getdata(int a, int b, int c)
{
 x = a;
y = b;
z = c;
}
void display( )
{
cout<<"\t x="<<x<<"\ty--"<<y<<"\tz--"<<z;
}
increment operator ++( )
{
increment temp;
temp.x = x++;
temp.y = y++;
temp.z = z++;
return temp;
}
};
void main( )
{
increment s1, s2, s3;
clrscr( );
s1.getdata(10, 20, 30);
cout<<"\n\toriginal data--->\n";
s1.display( );
s2 = ++s1;
cout<<"\n\tAfter overloading prefix increment data of object s2 is--->\n";
s2.display( );
getch( );
}

Output:-
original data--->
x=10   y--20    z--30
After overloading prefix increment data of object s2 is--->
x-10    y--20     z--30

--------------------------------------------------------------------------------------------------------------------------
#include<conio.h>
#include<iostream.h>
class increment
{
int x,y,z;
public:
void getdata(int a, int b, int c)
{
 x = a;
y = b;
z = c;
}
void display( )
{
cout<<"\t x="<<x<<"\ty--"<<y<<"\tz--"<<z;
}
increment operator ++( )
{
increment temp;
temp.x = ++x;
temp.y = ++y;
temp.z = ++z;
return temp;
}
};
void main( )
{
increment s1, s2;
clrscr( );
s1.getdata(10, 20, 30);
cout<<"\n\toriginal data--->\n";
s1.display( );
s2 = s1++;
cout<<"\n\tAfter overloading prefix increment data of object s2 is--->\n";
s2.display( );
getch( );
}

Output:-
original data--->
x=10   y--20    z--30
After overloading prefix increment data of object s2 is--->
x-10    y--20     z--30

Overloading Binary Operator

Binary operations are performed which require two operands to perform operations.

To add two numbers generally we use statement like
   C = sum(A,B);      //Functional Notation

This functional Notation can be replaced by natural looking expression
   C = A + B;
             By overloading '+' operator using an operator +( ) function.

The Overloaded function can be invoked by expression such as for binary operators-
   Syntax :
   X op Y;



#include<conio.h>

#include<iostream.h>
class complex 
{
float x;
float y;
public:
complex(double real, double imag)
{
x = real;
y = imag;
}
complex( )
{


}
complex operator+(complex c);
void display( );
};
complex complex ::operator+(complex c)
{
complex temp;
temp.x = x+c.x;
temp.y = y+c.y;
return (temp);
}
void complex::display( )
{
cout<<x<<" +j"<<y;
}
void main( )
{
complex c1(2.5,3.5);
complex c2(1.6,2.7);
complex c3;
clrscr( );
c3 = c1 + c2;
cout<<"\n\n\tc1 is--->"<<"\t";
c1.display( );
cout<<"\n\n\tc2 is--->"<<"\t";
c2.display( );
cout<<"\n\n\tc3 is--->"<<"\t";
c3.display( );
getch( );
}

Output:-
c1 is--->               2.5    +j3.5
c2 is--->               1.6    +j2.7
c3 is--->               4.1    +j6.2

Binary Operator Overloading using friend function

In many cases whether you overload an operator by using a friend or member function makes no functional difference. In those cases it is usually best to overload by using member function. However there is one situation in which overloading by using a friend increase flexibility of an overloaded operator.

We have seen how unary operator is overloaded, similar way we can overload binay operator. Binary operator requires two operands.

The syntax for overloading binary operator using friend function as follows:

friend Return_type operator op(Arguments)
{                      //Body of the operator function

}

WAP to overload binary '+' operator to add two complex numbers using friend function

#include<conio.h>
#include<iostream.h>
class complex
{
double real, ima;
public:
void getdata( )
{
cout<<"\n\tEnter real part of complex no.";
cin>>real;
cout<<"\n\tEnter imaginary part of complex no";
cin>>img;
}
void display( )
{
cout<<"\t"<<real<<"+i"<<img;
}
friend complex operator +(complex,complex);
};

complex operator +(complex c1, complex c2)
{
complex temp;
temp.real = c1.real + c2.real;
temp.img = c1.img + c2.img;
return temp;
}
void main( )
{
complex A,B,C;
clrscr( );
cout<<"\n\tEnter data for first object";
A.getdata( );
cout<<"\n\tEnter Data for second object";
B.getdata( );
C = A + B;
cout<<"\n\tData for first object--->";
A.display( );
cout<<"\n\tData for second object--->";
B.display( );
cout<<"\n\tAddition of two complex no is--->";
C.display( );
getch( );
}

Output:-
Enter data for first object
Enter real part of complex no12

Enter imaginary part of complex no5.6

Enter Data for second object
 Enter real part of complex no5

Enter imaginary part of complex no3.5

Data for first object--->    12+i5.6 
Data for second object--->   5+i3.5
Addition of two complex no is--->      17+i9.1

Overloading Unary Operator

First we consider the unary operator. Let consider unary operator unary minus ( - ) , when it is used, it takes just one operand.

We know that unary minus (-) operator changes the sign of an operand when applied to basic data item.

We have overloaded this operator so that it should be operated to an object in the same way as applied to an int or float variables.

The unary minus when applied to an object should change the sign of each of data item.

Overloaded function can be invoked by expression such as for unary operator

                   Op  x;

                      OR

                   x  op;

#include<conio.h>
#include<iostream.h>
class space
{
int x, y, z;
public:
void getdata(int a, int b, int c)
{
  x = a;
  y = b;
  z = c;
}
void display( );
void operator-( );
};

void space::display( )
{
cout<<"\n\tx is--->"<<x;
cout<<"\n\ty is--->"<<y;
cout<<"\n\tz is--->"<<z;
}
void space::operator-( )
{
x = -x;
y = -y;
z = -z;
}
void main( )
{
space s;
clrscr( );
s.getdata( 10, -20, 30);
cout<<"\n\tBefore Overloading:";
s.display( );
-s;
cout<<"\n\tAfter Overloading:";
s.display( );
getch( );
}

Output:-
Before Overloading:
x is--->10
y is--->-20
z is--->30
After Overloading:
x is--->-10
y is--->20
z is--->-30

Unary Operator overloading using Friend function

We can also use unary operator with the friend function. By using this concept we can use operator function with different classes. The following program illustrates this features.

Note : 
 In the friend function , we are passing argument as the reference . If we pass argument as by value it will not reflect the correct result because we need all the changes outside which are made inside the operator function.

//WAP to overload unary '-' operator to negate different variables using friend function

#include<conio.h>
#include<iostream.h>
class space
{
int x, y, z;
public:
void getdata(int a, int b, int c)
{
z = a;
y = b;
z = c;
}
void display( )
{
cout<<"\n\tData--->";
cout<<"\t"<<x<<"\t"<<y<<"\t"<<z;
}
friend void operator -(space &op);
};
void operator -(space &op)
{
op.x = -op.x;
op.y = -op.y;
op.z = -op.z;
}
void main( )
{
space s;
clrscr( );
s.getdata( 10, -20, 30);
cout<<"\n\tBefore Operator overloading---";
s.display( );
-s;
cout<<"\n\tAfter Operator overloading---";
s.display( );
getch( );
}

Output:-
Before Operator overloading--- 
Data is--->  10   -20   30
After Operator overloading---
Data is--->   -10    20    -30

Popular Posts

Categories

AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (115) C (77) C# (12) C++ (82) Course (62) Coursera (179) coursewra (1) Cybersecurity (22) data management (11) Data Science (91) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (5) flutter (1) FPL (17) Google (19) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (44) Meta (18) MICHIGAN (5) microsoft (3) Pandas (3) PHP (20) Projects (29) Python (747) Python Coding Challenge (207) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses