Posts

Showing posts from February, 2019

Inherteds and template

       Inherteds and template #include<iostream> using namespace std; class par {  public:   virtual void show()=0; }; class child :public par {  public:     void show()   {    cout<<"inside child";   } }; main() {  par p; } #include<iostream> using namespace std; class par {  protected:   int a;  public:   virtual void show()=0;//pure virtual class }; class child:public par {  int x;  public:  child (int a1,int y)  {   x=a1;   a=y;  }  void show()  {   cout<<x<<"  "<<a<<endl;  } }; main() {  par *p;  child c(12,34); // p=&c;  p->show(); } #include<iostream> using namespace std; void count() {  static int v=0;  v++;  cout<<v; } main() {  for(int i=0;i<5;i++)  count()...

C++ example programs

Oops concept and some example #include<iostream> using namespace std; class num { int a,b; public: void set(int y,int x) { a=y;b=x; } void add() { cout<<a+b<<endl; } }; main() { num obj; obj.set(2,4); obj.add(); } NOTE:The above saying that creating absort and making encapulation and accessing throught single interface that is object. #include<iostream> using namespace std; namespace ownname { int a=10; int b=12; }; main() { cout<<ownname::a<<endl; } #include<iostream> #include<math.h> using namespace std; float absolut(float x) { return x; } float absolut(double x,float y,float z) { cout<<"ceil value :"<<x<<" "<<ceil(x)<<endl; cout<<"floor value :"<<y<<" "<<floor(y)<<endl; cout<<"abs value :"<<z<<" "<<fabs(z)<<endl; return ceil(x)+floor(y)+fabs(...