Posts

. Assign Cookies

  class Solution { public:    int findContentChildren(vector<int>& g, vector<int>& s) {         sort(g.begin(), g.end());         sort(s.begin(), s.end());                int count = 0;                for(int j = 0; count < g.size() && j < s.size(); ++j){             if(g[count] <= s[j]) count++;         }             return count;     } };

constructor with default arguments

Image
 constructor  with default arguments //constructor  with default arguments #include<iostream> using namespace std; class Simple {     int data1 ;     int data2;     public :         Simple(int a,int b)         {             data1=a;             data2=b;         }         void printData();     };         void Simple :: printData()         {             cout<<"the value of data is "<<data1<<" and "<<data2<<endl;         } int main() { Simple s( 12, 54); s.printData(); return 0; } 

constructor overloading in c++ programming

Image
  constructor overloading in c++ programming #include<iostream> using namespace std; class complex {     int a ,b;     public:     complex()     {     a=0;     b=0;     }     complex(int x,int y)     {     a=x;     b=y;     }     complex(int x)     {     a=x;     b=0;     }     void printNumber ()     {     cout<<"Your number is "<<a<<" i"<<endl;     } }; int main() { complex c1(4 , 6); c1.printNumber(); complex c2(5); c2.printNumber(); complex c3(65); c3.printNumber(); return 0; } 

static member function in c++ program declared.

Image
//static member function   #include<iostream> using namespace std; class Employee {     int Id;     static int count;     public:         void setData(void)         {             cout<<"Enter the Id  "<<endl;;            cin>>Id;         count++;         }         void getData(void)         {           cout<<"This Id of this employee is  "<<Id<<"  and this employee number "<<count<<endl; } static void getcount(void){     cout<<"The value of  count is "<<count<<endl; } }; int Employee :: count;//default vaalueis 0 int main() {     Employee harry, rohan ,lovish;     harry.setData();        harry.getData();     Employee::getcount()    ; rohan.setData();    rohan.getData(); Employee::getcount()    ;        lovish.setData();        lovish.getData();             Employee::getcount()    ;          return 0; }     output----

static variable(static data member) in C++

Image
 / /static data member    static variable(static data member) in C++ #include<iostream> using namespace std; class Employee {     int Id;     static int count;     public:         void setData(void)         {             cout<<"Enter the Id"<<endl;;             cin>>Id;         count++;         }         void getData(void)         {            cout<<"This Id of this employee is "<<Id<<"and this employee number "<<count<<endl; } }; int Employee :: count;//default vaalueis 0 int main() {     Employee harry, rohan ,lovish;     harry.setData();         harry.getData();     rohan.setData();     rohan.getData();         lovish.setData();         lovish.getData();         return 0; }  output----  

class with array in c++ (memory allocatin & using array in classes)

Image
  class with array in c++ (memory allocatin & using array in classes) #include<iostream> using namespace std; class shop {     int itemId[100];     int itemprice[100];     int counter;     public:     void initcounter(void){counter=0;}     void setprice(void);     void displayprice(void); }; void shop::setprice(void){  cout<<"Enter Id your item no "<<counter+1<<endl;  cin>>itemId[counter];   cout<<"Enter price your item"<<endl;   cin>>itemprice[counter];    counter++; } void shop::displayprice(void){     for(int i=0;i<counter;i++)     { cout<<"the price of item with Id "<< itemId[i]  <<" is "<<itemprice[i]<<endl;        } } int main() {     shop dukan;     dukan.initcounter();     dukan.setprice();     dukan.setprice();     dukan.setprice();     dukan.setprice();     dukan.setprice();     dukan.setprice();     dukan.setprice();     dukan.setprice();     dukan.set

access the private and public in c++.

Image
 access the private and public in c++.   #include<iostream> using namespace std; class Employee {     private:     int  a,b,c; public:     int d,e,f;     void setData(int a1,int b1,int c1);     void getData(){     cout<<"The value of a is= "<<a<<"\n";     cout<<"The value of b is= "<<b<<"\n";     cout<<"The value of c is= "<<c<<"\n";     cout<<"The value of d is= "<<d<<"\n";     cout<<"The value of e is= "<<e<<"\n";             cout<<"The value of f is= "<<f<<"\n";             } };    void Employee::setData(int a1 ,int b1, int c1){     a=a1;     b=b1;     c=c1; }     int main() { Employee rajukumar; //rajukumar.a=134; this is private   rajukumar.d=55;   rajukumar.e=878;   rajukumar.f=54;   rajukumar.setData(3,4,66);   rajukumar.getData();   return 0;     }