valentine day heart in c++

#include
#include

using namespace std;

int main()
{
    double x, y, size=10;
    char ch=3;
    string message(" Happy Valentine's Day ");
    int print_line = 4;

    if (message.length() % 2 != 0) message += " ";

    for (x=0;x<size;x++)
    {
        for (y=0;y<=4*size;y++)
        {
            double dist1 = sqrt( pow(x-size,2) + pow(y-size,2) );
            double dist2 = sqrt( pow(x-size,2) + pow(y-3*size,2) );

            if (dist1 < size + 0.5 || dist2 < size + 0.5 ) {
                cout << ch;
            }
            else cout << " ";
        }
        cout<<"\n";
    }

    for (x=1;x<2*size;x++)
    {
        for(y=0;y<x;y++) cout << " ";

        for (y=0; y<4*size + 1 - 2*x; y++)
        {
            if (x >= print_line - 1 && x <= print_line + 1) {
                int idx = y - (4*size - 2*x - message.length()) / 2;
                if (idx = 0) {
                    if (x == print_line) cout<<message[idx];
                    else cout << " ";
                }
                else cout << ch;
            }
            else cout << ch;
        }
        cout<<endl;
    }
    return 0;
}

simple heart

#include
#include
int main()
{
    int x, y, size=8;
    for (x=0; x<size; x++)
    {
        for (y=0; y<=4*size; y++)
        {
            double dist1 = sqrt( pow(x-size,2) + pow(y-size,2) );
            double dist2 = sqrt( pow(x-size,2) + pow(y-3*size,2) );
            if (dist1 < size + 0.5 || dist2 < size + 0.5 )
                 printf("%c",97);
            else
                 printf(" ");
        }
        printf("\n");
    }
    for (x = 1; x <= 2*size; x++)
    {
        for (y=0; y<x; y++)
        printf(" ");
        for (y=0; y<4*size + 1 - 2*x; y++)
            printf("%c",97);
        printf("\n");
    }

    return 0;  
}


#include
using namespace std;
int main (void) {
    int a=10, b=0, c=10;
    char* bits ="TFy!QJu ROo TNn(ROo)SLq SLq ULo+UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^NBELPeHBFHT}TnALVlBLOFAkHFOuFETpHCStHAUFAgcEAelclcn^r^r\\tZvYxXyT|S~Pn SPm SOn TNn ULo0ULo#ULo-WHq!WFs XDt!";
    a = bits[b];
    while (a != 0) {
        a = bits[b];
        b++;
        while (a > 64) {
            a--;
            if (++c == 'Z') {
                c /= 9;
                putchar(c);
            } else {
                putchar(33 ^ (b & 0x01));
            }
        }
    }
 
system("pause");
}

Fundamentals of OOP
Class
Object
Encapsulation
Abstraction
Inheritance
Polymorphism
Reusability
C++ as an OOP language
C++ : C with classes
Multi-paradigm language
As Object oriented language, it offers bottom to top approach
As Procedural language, it offers top to bottom approach
Classes and objects (I)
Class- user defined data type. Fundamental packaging unit of
OOP technology
Class declaration is similar to struct declaration
Keyword ‘class’ followed by class name.
Object is an instance of class
Object combines data and functions
Object is created as a variable of class type using class name
Members of class
Data members / attributes
Member functions / methods
Classes and objects (II)
Structure of C++ program with class
Data members
Data members can be any of the following types
Primary data types : int, float, char, double, bool
Secondary data types : arrays, pointers, class objects etc.
Data members classified into two groups
Regular : every object gets its own copy of data members
Static: all objects share the same copy of data member
Static Data Members
Variable declaration preceded by keyword ‘static’
Only one copy of static variable is created. All the objects share the same
copy
Initialized to zero when first object is created. No other initialization
permitted.
Should be defined outside the class definition after declaring them
inside the class in this way – datatype classname :: varname
They are normally used to maintain values that are common to the
entire class, e.g., to keep a count of number of objects created.
Methods (I)
Function defined inside a class declaration is called as
member function or method
Methods can be defined in two ways - inside the class or
outside the class using scope resolution operator (::)
When defined outside class declaration, function needs to be
declared inside the class
Methods (II)
Method defined inside the
class
Method defined outside
the class
Methods (III)
Types of functions in a class
Regular functions
Overloaded functions
Inline functions
Friend functions
Static functions
Constructors
Destructors
Virtual functions

Virtual Functions (I)
Member function preceded by keyword ‘virtual’ in base class
and overridden in derived class
If object of base class invokes virtual function, then copy of
base class is invoked and if derived class object invokes it,
then copy of derived class is invoked.
Virtual functions are declared to specify late binding.
When base class pointer points at derived class object, c++
determines which copy to be called depending upon the type
of the object at run time
They are resolved at run time not at compile time
Virtual Functions (II)
General rules while defining virtual function:
Must be member of some class
Accessed using object pointers
Can be friend of another class
Prototype of base class and derived class virtual function must
be identical
No need to use keyword ‘virtual’ in definition if its is defined
outside the class
Can not be a static member

EXAMPLES:
EX 1:
#include

class B
{
public:
virtual void display()
{ cout<<"Content of base class.\n"; }
};

class D : public B
{
public:
       void display()
{ cout<<"Content of derived class.\n"; }
};

int main()
{
B *b;
D d;
// b->display();

b = &d;    /* Address of object d in pointer variable */
b->display();
return 0;

}
exp 2:

#include
class B
{
public:
 virtual void display()      /* Virtual function */
{ cout<<"Content of base class.\n"; }
};

class D1 : public B
{
public:
void display()
{ cout<<"Content of first derived class.\n"; }
};

class D2 : public B
{
public:
void display()
{ cout<<"Content of second derived class.\n"; }
};

int main()
{
B *b;
D1 d1;
D2 d2;

/* b->display();  // You cannot use this code here because the function of base class is virtual. */

b = &d1;
b->display();   /* calls display() of class derived D1 */
b = &d2;
b->display();   /* calls display() of class derived D2 */


}
exp 3:
#include
#include
class student
{            protected: int rn;
                public:
                       void getrn(int a)
                       {
                            rn=a;
                       }
                       void showrn()
                       {
                            cout<<"rollno="<<rn<<"\n";
                       }
};
class test:virtual public student
{
      protected:
      float part1,part2;
      public:
             void getmarks(float a,float b)
             {
                  part1=a;
                  part2=b;
                  }
                  void showmarks()
                  {
                       cout<<"marks 1"<<part1<<"marks2"<<part2;
                  }
};
class sports: virtual public student
{
      protected:
      float score;
      public:
             void getscore(float a)
             {
                  score=a;
                  }
                  void showscore()
                  {
                       cout<<"sports="<<score;
                  }
                  };
class result:public test,public sports
                  {
                        float total;
                        public:
                               void display()
                               {
                                    total=part1+part2+score;
                                    showrn();
                                    showmarks();
                                    showscore();
                                    cout<<"total="<<total;
                                    }
                               };
      int main()
      {
          result s;
          s.getrn(10);
          s.getmarks(40,30);
          s.getscore(20);
          s.display();
          getch();
          return 0;
          }









Hierarchical Inheritance - OOP's Concept

What is Hierarchical Inheritance OOP's Concept in C++?

Explanation

Hierarchical Inheritance is a method of inheritance where one or more derived classes is derived from common base class.

Example:

#include
#include
class first
{
      public:
      int a;
};
class sec:public first
{
      public:
      int b;
      void get()
      {
           cin>>a>>b;
           }
      void disp()
      {
           cout<<a*b;
           }
};
      class third:public first
      {
            public:
            int c;
            void get()
            {
                 cin>>a>>c;
                 }
            void disp()
            {
                 cout<<a*c;
                 }
                 };
            
int main()
{
    sec s;
    third t;
    s.get();
    t.get();
    s.disp();
    t.disp();
    getch();
    return 0;
}
exp 2:

#include
#include
class first
{
      int a;
      public:
             void get()
             {
                  cin>>a;
                  }
      int disp()
      {
          return a;
          }
};
class second:public first
{
int b;
public:
       void getsec(){
            get();
            cout<<"enter avlue of b";
            cin>>b;
            }
            void sum()
            {
                 cout<<"sum ="<<disp()+b;
                 }
};
class third:public first
{
int c;
public: void getthird()
{
get();
cout<<"enter value if c";
cin>>c;
}
void sub()
{
     cout<<"sub="<<disp()-c;
     }
     };
     main()
     {
           second s1;
           s1.getsec();
           s1.sum();
           third t1;
           t1.getthird();
           t1.sub();
           getch();
           }

Multiple Inheritance in C++

In C++ programming, a class can be derived from more than one parents. For example: A classRectangle is derived from base classes Area and Circle.
Example of multiple inheritance in C++ programming language

Source Code to Implement Multiple Inheritance in C++ Programming

#include
#include
class first
{
      int a;
      public:
             void get()
             {
                  cin>>a;}
                 int disp()
                 {return a;}
};
class second
{
      int b;
      public:
             void getsec(){
                  cin>>b;
                  }
                int  dispsec()
                  {
                      return b;}
                 
};
class third:public first,public second
{
public:
       void getfinal()
       {
            get();
            getsec();
            }
            void dispfinal()
            {
                 cout<<"ans="<<disp()+dispsec();
                 }
                 
};
main()
{
      third t1;
      t1.getfinal();
      t1.dispfinal();
      getch();
      }

Multiple Inheritances:

A C++ class can inherit members from more than one class and here is the extended syntax:
class derived-class: access baseA, access baseB....
Where access is one of public, protected, or private and would be given for every base class and they will be separated by comma as shown above. Let us try the following example
#include
#include
class first
{
      public:
      int a;
};
class sec
{
      public:
      int b;
};
      class third:public sec,public first
      {
            public:
            int c;
            void get()
            {
                 cin>>a>>b>>c;
                 }
            void disp()
            {
                 cout<<a*b*c;
                 }
                 };
            
int main()
{
    third t;
    t.get();
    t.disp();
    getch();
    return 0;
}
ex 2:
#include
#include
class first
{
      int a;
      public:
             void get()
             {
                  cin>>a;}
                 int disp()
                 {return a;}
};
class second
{
      int b;
      public:
             void getsec(){
                  cin>>b;
                  }
                int  dispsec()
                  {
                      return b;}
                 
};
class third:public first,public second
{
public:
       void getfinal()
       {
            get();
            getsec();
            }
            void dispfinal()
            {
                 cout<<"ans="<<disp()+dispsec();
                 }
                 
};
main()
{
      third t1;
      t1.getfinal();
      t1.dispfinal();
      getch();
      }
ex 3:
#include
#include
class first
{protected:
      int a;
      int b;
      
      public:
             void get()
             {cout<<"enter a and b";
             cin>>a>>b;
             }
           int sum()
             {
                return  a+b;
                  }
                  };
class second: protected first
{
      int c;
      public:
             void getsec()
             {
                  get();
                  cout<<"enter value of c";
                  cin>>c;
                  }
                  int calc()
                  {
                       return sum()+c;
                  }
};
class third:protected second
{
      int d;
      public:
             void getthird()
             {
             getsec();
             cout<<"enter value of d";
             cin>>d;
             }
             void calcfinal()
             {
             cout<<calc()+d;
             }
      };
main()
{
      third t1;
      t1.getthird();
      t1.calcfinal();
      getch();
      }    

In C++ programming, a class be can derived from a derived class which is known as multilevel inhertiance. For example:
class A
{ .... ... .... };
class B : public A
{ .... ... .... };
class C : public B
{ .... ... .... };
In this example, class B is derived from class A and class C is derived from derived class B.

Example to Demonstrate the Multilevel Inheritance

#include 
using namespace std;

class A
{
public:
void display()
{
cout
<<"Base class content.";
}
};

class B : public A
{

};

class C : public B
{

};

int main()
{
C c
;
c
.display();
return 0;
}
Output
Base class content.