Posts

MultiLevel

#include<iostream> using namespace std ; //A->B->C->Main class A{ public : int Anumber = 123 ; } ; class B: public A { public : int Bnumber = 456 ; void displayB(){ cout<< "Class A=" <<Anumber<<endl ; } } ; class C:B { public : int Cnumber = 789 ; void displayC(){ displayB() ; cout<< "Class A=" <<Anumber<<endl ; cout<< "Class B=" << Bnumber <<endl ; cout<< "Class C=" << Cnumber <<endl ; } } ; int main(){ C obj ; obj.displayC() ; return 0 ; }

Inheritance With Constructor

  #include<iostream> using namespace std ; class A{ public : int abc = 123 ; A (){ cout<< "Counstructor A " <<endl ; } ~ A (){ cout<< "Destructor A " <<endl ; } void display (){ cout<< "Display A" ; } } ; class B: public A{ public : int xyz = 123 ; B(){ display () ; cout<< "Counstructor B " <<endl ; } ~B(){ cout<< "Destructor B you \' r " <<endl ; } void display (){ cout<< "Display B" ; } } ; int main(){ B obj ; cout<< "Sum=" <<(obj. abc +obj.xyz) ; return 0 ; }

Multiple Inheritance

  #include<iostream> using namespace std ; //base class A{ int a , b ; public : int Add(){ cout<< "Input a and b: \n " ; cin>>a>>b ; cout<< "Sum=" <<(a+b) ; return (a+b) ; } void Sub(){ cout<< " \n Input a and b: \n " ; cin>>a>>b ; cout<< "Sum=" <<(a-b) ; } } ; //Child class B { protected : int abc= 123 ; public : void per(int total){ //Sub 1=50 Mark //Sub 2=50 Mark //(total mark *sub_Total)/100; float p=(float) (total* 100 )/ 100 ; cout<< "Per=" <<p<< "%" <<endl ; cout<< "Change Vaue abc=888" <<endl ; } void Simple_int(){ } } ; class C : public A ,public B { public : void ReadM_Cal_per(){ int total=Add() ; per(total) ; cout<<abc ; } } ; //===========Main===...

Single Inheritance:

  #include<iostream> using namespace std ; //base class A{ int a , b ; public : void Add(){ cout<< "Input a and b: \n " ; cin>>a>>b ; cout<< "Sum=" <<(a+b) ; } void Sub(){ cout<< " \n Input a and b: \n " ; cin>>a>>b ; cout<< "Sum=" <<(a-b) ; } } ; //Child class B: public A { public : void XYZ(){ // // Add(); } } ; //===========Main======= int main(){ B obj ; obj.Add() ; return 0 ; }

Copy constructor another Class

  #include<iostream> #include<string.h> using namespace std ; // class Car2{ public : char fule[ 10 ] ; char color[ 10 ] ; Car2(char* f , char* c){ strcpy(color , c) ; strcpy(fule , f) ; } } ; class Car{ int number ; char name[ 10 ] ; char fule[ 10 ] ; char color[ 10 ] ; public : Car(char* n , char* f , char* c , int num){ strcpy(name , n) ; strcpy(fule , f) ; strcpy(color , c) ; number=num ; } Car(char* n , int num , Car &obj){ strcpy(name , n) ; strcpy(fule , obj.fule) ; strcpy(color , obj.color) ; number=num ; } Car(char* n , int num , Car2 &obj){ strcpy(name , n) ; strcpy(fule , obj.fule) ; strcpy(color , obj.color) ; number=num ; } void displayValue(){ cout<< " \n Number=" <<number<<endl ; cout<< " \n Color=" <<color<<endl ; cout<< " \n Fule=" <<fule<<endl ; co...

Copy Constructor

   #include<iostream> #include< string .h> using namespace std ; // class Car{ int number ; char name [ 10 ] ; char fule [ 10 ] ; char color [ 10 ] ; public : Car( char * n , char * f , char * c , int num ){ strcpy (name , n) ; strcpy (fule , f) ; strcpy (color , c) ; number =num ; } Car(char* n , int num , Car &obj){ strcpy( name , n ) ; strcpy(fule , obj. fule ) ; strcpy( color , obj. color ) ; number =num ; } //=======Default== Car(Car &obj){ strcpy( name , obj. name ) ; strcpy(fule , obj. fule ) ; strcpy( color , obj. color ) ; number =obj. number ; } Car (){ } void displayValue(){ cout<< " \n Number=" << number <<endl ; cout<< " \n Color=" << color <<endl ; cout<< " \n Fule=" <<fule<<endl ; cout<< " \n Name=" << name <<endl ; } } ; int main (){ //==========...

Constructor Overloading

  #include <iostream> using namespace std; class Car{ int number; public: Car(){ cout<<"\nConstructor Car()"< <endl ; } Car(int n){ cout<<"\nConstructor Car(int n)"< <endl ; number=n; } Car(int a,int b){ cout<<"\nConstructor Car(int a,int b)"< <endl ; cout<<"Sum="<<(a+b); } void displayValue(){ cout<<"Number="< <number ; } }; int main(){ Car a,b,c(12); a.displayValue(); b.displayValue(); c.displayValue(); return 0;     }