Easy programming and better way to learn the programming . if you like the scorce code do like like share and subscribe the chennel.
Search This Blog
Tuesday, 22 December 2020
function overloading
Hierarchical Inheritance Example.
👇👆👆👆👆👇👇👇👇👇
#include<iostream>
using namespace std;
class Shape
{
protected:
float width, height;
public:
void set_data (float a, float b)
{
width = a;
height = b;
}
};
//inheriting Shape class
class Rectangle: public Shape
{
public:
float area ()
{
return (width * height);
}
};
//inheriting Shape class
class Triangle: public Shape
{
public:
float area ()
{
return (width * height / 2);
}
};
int main ()
{
Rectangle rect;
Triangle tri;
rect.set_data (5,3);
tri.set_data (2,5);
cout <<"Area of Rectangle : " <<rect.area() << endl;
cout <<"Area of Triangle : "<< tri.area() << endl;
return 0;
}
Hybrid Inheritance Example.
Merge singly linked list.
method of overloading
//program to show how method overloading works
# include<iostream>
using namespace std;
//area method with one parameter
int area(int side)
{
return side*side;
}
//area method with two parameter
int area(int l , int b)
{
return l*b;
}
int main()
{
int (*para1)(int);
int (*para2)(int,int);
para1=area;
para2=area;
cout<<"Address of area(int) : "<<(unsigned int)para1<<endl;
cout<<"Address of area(int,int) : "<<(unsigned int)para2<<endl;
cout<<"Invoking area(int) via para1 : "<<para1(20)<<endl;
cout<<"Invoking area(int,int) via para2 : "<<para2(10,20);
}
Monday, 21 December 2020
Minus Operator overloading
#include<iostream>
using namespace std;
class MinusOperatorOverloading
{
int x,y,z;
public:
void get_data(int a,int b,int c)
{
x = a;
y = b;
z = c;
}
void operator -()
{
x = x - 10;
y = y - 10;
z = z - 10;
}
void display()
{
cout<<"\nx: "<<x;
cout<<"\ny: "<<y;
cout<<"\nz: "<<z;
}
};
int main()
{
MinusOperatorOverloading oo;
oo.get_data(53,73,93);
cout<<"Before overloading:";
oo.display();
-oo;
cout<<"\n\n";
cout<<"After overloading:";
oo.display();
return 0;
}
Multilevel Inheritance Example.
. Multiple Inheritance Example.
#include <iostream>
using namespace std;
class Area
{
public:
float area_calc(float l,float b)
{
return l*b;
}
};
class Perimeter
{
public:
float peri_calc(float l,float b)
{
return 2*(l+b);
}
};
//Rectangle class is derived from classes Area and Perimeter.
class Rectangle : private Area, private Perimeter
{
private:
float length, breadth;
public:
Rectangle() : length(0.0), breadth(0.0) { }
void get_data( )
{
cout<<"Enter length: ";
cin>>length;
cout<<"Enter breadth: ";
cin>>breadth;
}
float area_calc()
{
//Calls area_calc() of class Area and returns it.
return Area::area_calc(length,breadth);
}
float peri_calc()
{
//Calls peri_calc() function of class Perimeter and returns it.
return Perimeter::peri_calc(length,breadth);
}
};
int main()
{
Rectangle r;
r.get_data();
cout<<"\n\n";
cout<<"Area = "<<r.area_calc();
cout<<"\nPerimeter = "<<r.peri_calc();
return 0;
}
Arithematic ooprations using class
using namespace std;
//define class
class operations
{
//member variables
public:
int num1,num2;
//member function or methods
public:
void add()
{
cout<<"enter two number for addition : ";
cin>>num1>>num2;
cout<<"addition = "<<num1+num2;
cout<<"\n";
}
void sub()
{
cout<<"enter two number for subtraction : ";
cin>>num1>>num2;
cout<<"addition = "<<num1-num2;
cout<<"\n";
}
void mul()
{
cout<<"enter two number for multiplication : ";
cin>>num1>>num2;
cout<<"addition = "<<num1*num2;
cout<<"\n";
}
void div()
{
cout<<"enter two number for division : ";
cin>>num1>>num2;
cout<<"addition = "<<(float)num1/num2;
cout<<"\n";
}
};
int main()
{
//creation of object
operations op1;
op1.add();
op1.sub();
op1.mul();
op1.div();
return 0;
}
if you have more source code in simle way join this blog also do like and get the subsciption of tha blog on dnyaneshwarchakotkar.blolgspot.comm
also share the blog link to your friebnd for study,.....!!!!!
Search This Blog
Contact Form
Popular Posts
-
#include<iostream> using namespace std; int main() { int i; char ch[30]; cout<<"Enter the string "; cin.getli...
-
Title: Min max without using if else Program: #include <iostream> #include <math.h> using namespace std ; int main () { ...
-
#include<iostream> #include<conio.h> using namespace std; class xyz; class abc { int a; public: void getA() { cou...