Posts

Showing posts from March, 2023

Jay Gives Question and Answers

Image
 1. A number is given as input. Find the odd digits in the number, add them and find if the sum is odd or not.if even return -1, if odd return 1 input:52315 logic:5+3+1+5=14(even) output:-1 input:1112 logic:1+1+1=3(odd) output:1 2.Find the day(Friday) of a date input given as MM-dd-yyyy (format) input:12-27-2012 output:Thursday 3.Given two integer arrays. merge the common elements into a new array. find the sum of the elements input1:{1,2,3,4} input2:{3,4,5,6} logic:{3,4} output:7

Encapsulation example with code

  // C++ program to demonstrate // Encapsulation #include <iostream> using namespace std;   class Encapsulation { private :      // Data hidden from outside world      int x;   public :      // Function to set value of      // variable x      void set( int a) { x = a; }        // Function to return value of      // variable x      int get() { return x; } };   // Driver code int main() {      Encapsulation obj;      obj.set(5);      cout << obj.get();      return 0;

OOPs concept Abtraction example with code

// C++ Program to Demonstrate the // working of Abstraction #include <iostream> using namespace std;   class implementAbstraction { private :      int a, b;   public :      // method to set values of      // private members      void set( int x, int y)      {          a = x;          b = y;      }        void display()      {          cout << "a = " << a << endl;          cout << "b = " << b << endl;      } };   int main() {      implementAbstraction obj;      obj.set(10, 20);      obj.display();      r...