CODE FOR + OPERATOR OVER LOADING C++

 PROBLEM STATEMENT: ADD 2 OBJECTS AND ADD INTO OTHER. CODE: #include<iostream> using namespace std; class Experience { private: int days; int month; double year; public: Experience() { } Experience(int a,int b,double c) { days = a; month = b; year = c; } Experience operator +(Experience E) { Experience E1; E1.days = days + E.days; E1.month = month + E.month; E1.year = year + E.year; return E1; } void display() { cout << "\nDAYS\t" << days << "\nMONTHS\t" << month << "\nYEAR\t" << year << endl; } }; int main() { Experience e1(2, 12, 2), e2(1, 12, 4), e3; e3 = e1 + e2; cout << "showing data of 1st Experience\n"; e1.display(); cout << "\n\n\n\n"; cout << "showing data of 2nd Experience\n"; e2.display(); cout << "\n\n\n\n"; cout << "showing data of sum of Experiences\

NESTED LOOPS IN C++

 IN THIS BLOG I WILL SHOW YOU HOW TO MAKE PATTERNS USING FORLOOPS AND ALSO WE WILL SHOW YOU SYNTAX OF NESTED FOR LOOPS

Nested for loops are used for many purposes in c++.
nested for loops are used for making different types of shapes.


Here are codes with different types of shapes:

//nested for loops in c++

//lets begin

#include<iostream>

using namespace std;

int main()

{

      for (int i = 1; i <= 5; i++)

      {

            for (int j = 1; j <= i; j++)

            {

                  cout << j;

            }cout << endl;

      }

}

 

output:


#include<iostream>

using namespace std;

int main()

{

                for (int i = 5; i >= 1; i--)

                {

                                for (int j = 1; j <= i; j++)

                                {

                                                cout << j;

                                }cout << endl;

                }

}

 

 

OUTPUT:


 

//nested for loops in c++

//lets begin

#include<iostream>

using namespace std;

int main()

{

      for (int i = 1; i <= 5; i++)

      {

            for (int j = 1; j <= i; j++)

            {

                  cout << (i-j)+1;

            }cout << endl;

      }

}

 

 

output:

FOR MORE INFORMATION PLS VISIT:

MY YOUTUBE CHANNEL


Comments

Popular posts from this blog

CODE FOR CAR AND BIKE MANAGEMENT USING(Virtual functions) C++