Posts

Showing posts from October, 2024

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;     }  

Constructor

#include<iostream> #include<string. h > using namespace std ; class Car{ char color [ 10 ] ; char name [ 10 ] ; char fule [ 10 ] ; int number ; public : Car( char * c , char * n , char * f , int num = 1001 ){ strcpy (color , c) ; strcpy (name , n) ; strcpy (fule , f) ; number =num ; cout << "Constructor \n " ; } ~Car(){ cout<< " \n Destructor \n " ; } void DisplayValue(){ cout<< "Color=" << color ; cout<< " \n Name=" << name ; cout<< " \n Fule=" <<fule ; cout<< " \n Number=" <<number ; } } ; int main(){ char color [ 10 ] ; char name [ 10 ] ; char fule[ 10 ] ; int number ; int i ; for ( i = 0 ; i < 2 ; i ++){ cout<< "Input Color" <<endl ; cin>> color ; cout<< "Input Name" <<endl ; ci...

Constructor and Destructor

#include<iostream> using namespace std ; class Car{ int number ; //4GB public : Car(int price){ number=price ; cout<< "Constructor Call \n " ; } ~Car(){ cout<< "Destructor Call" ; } void DisplayValue(){ cout<< "Number" <<number<<endl ; } } ; int main(){ Car carobj=Car( 50000 ) ; //Constructor Call init //Destructor Call //Number=50000 carobj.DisplayValue() ; return 0 ; }  

Class Main Part 2

  #include<iostream> #include< string .h> #include "sabir.h" ; using namespace std ; int main(){ char color[ 10 ] ; char name[ 10 ] ; char fuletype[ 10 ] ; int number ; Car carObj ; cout<< "Input Color: \n " ; cin>>color ; cout<< "Input Name: \n " ; cin>> name ; cout<< "Input Fuletype: \n " ; cin>>fuletype ; cout<< "Input Number: \n " ; cin>>number ; carObj.SetValue(color , name , fuletype , number) ; carObj.DisplayValue() ; return 0 ; }

Class Car Part 1

    #include<iostream> #include<string.h> using namespace std ; class Car{ //Data Member char color[ 10 ] ; char name[ 10 ] ; char fuletype[ 10 ] ; int number ; //Member Func public : void SetValue(char* c , char* n , char* f , int num){ strcpy(color , c) ; strcpy (name , n) ; strcpy (fuletype , f) ; number=num ; } void DisplayValue(){ cout<< "Color=" <<color<<endl ; cout<< "Name=" <<name<<endl ; cout<< "FuleType=" <<fuletype<<endl ; cout<< "Number=" <<number<<endl ; } } ;

4 Types of Function

#include <iostream> using namespace std ; /* //Witout return without Par void Sum(){ //input //proccess /output int a,b,c; cout<<"Please Input 2 Number:\n"; cin>>a>>b; c=a+b; cout<<"Result="<<c; } int main(){ //=====1=== Sum();//Call } */ //====================2================ /* //Witout return with Par void Sum(int a,int b){ //procces //output int c; c=a+b; cout<<"Result="<<c; } int main(){ //Input int a,b; cout<<"Please Input 2 Number:\n"; cin>>a>>b; //=====2=== Sum(a,b);//Call } */ //=============3============ //with return without par /* int Sum(){ //input int a,b,c; cout<<"Please Input 2 number\n"; cin>>a>>b; //proccess c=a+b; return c; } int main(){ //output int c; c=Sum(); cout<<"Result="<<c; } */ //=============4====...

Function Types

 #include <iostream> using namespace std; /* //Witout return without Par void Sum(){ int a,b,c; cout<<"Please Input 2 Number:\n"; cin>>a>>b; c=a+b; cout<<"Result="<<c; } int main(){ //=====1=== Sum();//Call } */ //Witout return with Par void Sum(int a,int  b){ int c; c=a+b; cout<<"Result="<<c; } int main(){ int a,b; cout<<"Please Input 2 Number:\n"; cin>>a>>b; //=====2=== Sum(a,b);//Call }

FUnction

 #include<iostream> using namespace std; class Car{ char color[]; char name[]; int number; char fuletype[]; }; ///=============================== //without return without par //without return with par //with return with par //with return without par //without return without par void ABC(){ cout<<"ABC Call"; } //without return with par void PrintName(char* name){ cout<<"Name="<<name; } //with return with par int  Sum(int a,int b){ return (a+b); } // int Sub(){ int a,b; cout<<"Please Input 2 Number"<<endl; cin>>a>>b; return (a-b); } //================================= int main(){ char namabc[10]; int c; cout<<"Computer"<<endl; cout<<"ABC Call"<<endl; ABC();//call //========2====== cout<<"\nInput Name"<<endl; cin>>namabc; PrintName(namabc); //========3==== c= Sum(40,50); cout<<...