HTML DOM MouseEvent Object

AmitDiwan
Updated on 25-Oct-2019 07:20:32

421 Views

The HTML DOM MouseEvent Object represents an event which incurs on interaction of mouse with the HTML document elements.Here, “MouseEvent” can have the following properties and methods −Property/MethodDescriptionaltKeyItreturns whether the "ALT" key on keyboard was pressedwhen the mouse event was triggeredbuttonItreturns a number corresponding to which mouse button was pressedwhen the mouse event was triggeredbuttonsItreturns which mouse buttons were pressed when the mouse event wastriggeredclientXItreturns the horizontal (x) coordinate of the mouse pointer, relative to the current window, when the mouse event was triggeredclientYItreturns the vertical (y) coordinate of the mouse pointer, relativeto the current window, when the mouse event ... Read More

HTML DOM MouseEvent screenY Property

AmitDiwan
Updated on 25-Oct-2019 06:54:17

102 Views

The HTML DOM MouseEvent screenY property returns the vertical (y) coordinate of the mouse pointer relative to the users screen display if a mouse event was triggered. Use with screenY to get the horizontal coordinate as well.Following is the syntax −Returning reference to the screenY objectMouseEventObject.screenYLet us see an example of MouseEvent screenY property −Example Live Demo MouseEvent screenY    * {       padding: 2px;       margin:5px;    }    form {       width:70%;       margin: 0 auto;       text-align: center;    }    #outer {     ... Read More

Find Amount to be Added to Achieve Target Ratio in a Given Mixture in C++

Arnab Chakraborty
Updated on 24-Oct-2019 14:12:49

72 Views

Suppose we have a container with size X. It has a mixture of water and other liquid, the mixture has W% of water in it. We have to find how many water must be added to increase the ratio of water to Y%? If X = 125, W = 20 and Y = 25, then output will be 8.33 liters.Suppose we have to add A amount of water with the previous mixture, so new amount will be X + A. So the amount of water in the mixture will follow this formula.Old Amount+A=((W% of X) + A)Also the amount of ... Read More

Find All Pairs (A, B) and (C, D) in Array Satisfying A*B = C*D in C++

Arnab Chakraborty
Updated on 24-Oct-2019 13:23:15

239 Views

Suppose we have an array A, from that array, we have to choose two pairs (a, b) and (c, d), such that ab = cd. Let the array A = [3, 4, 7, 1, 2, 9, 8]. The output pairs are (4, 2) and (1, 8). To solve this, we will follow these steps −For i := 0 to n-1, dofor j := i + 1 to n-1, doget product = arr[i] * arr[j]if product is not present in the hash table, then Hash[product] := (i, j)if product is present in the hash table, then print previous and current elements.Example Live ... Read More

Find All Pairs (A, B) in an Array Such That A - B = K in C++

Arnab Chakraborty
Updated on 24-Oct-2019 13:15:12

193 Views

Suppose we have an array A, from that array, we have to get all pairs (a, b) such that the a%b = k. Suppose the array is A = [2, 3, 4, 5, 7], and k = 3, then pairs are (7, 4), (3, 4), (3, 5), (3, 7).To solve this, we will traverse the list and check whether the given condition is satisfying or not.Example Live Demo#include using namespace std; bool displayPairs(int arr[], int n, int k) {    bool pairAvilable = true;    for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {          if (arr[i] % arr[j] == k) {             cout

Find All Factorial Numbers Less Than or Equal to N in C++

Arnab Chakraborty
Updated on 24-Oct-2019 13:08:48

1K+ Views

Here we will see how to print all factorial numbers less than or equal to n, a number N is said to be factorial number if it is a factorial of a positive number. So some factorial numbers are 1, 2, 6, 24, 120.To print factorial numbers, we do not need to find the factorial directly. Starting from i = 1, print factorial*i. Initially factorial is 1. Let us see the code for better understanding.Example Live Demo#include using namespace std; void getFactorialNumbers(int n) {    int fact = 1;    int i = 2;    while(fact

Find All Duplicate Subtrees in C++

Arnab Chakraborty
Updated on 24-Oct-2019 13:05:38

202 Views

Consider we have a binary tree. We have to find if there are some duplicate subtrees in the tree or not. Suppose we have a binary tree like below −There are two identical subtrees of size 2. In each subtree D, BD and BE both are also duplicate subtrees We can solve this problem by using tree serialization and hashing process. We will store the inorder traversal of subtrees in the hash table. We will insert opening and closing parenthesis for empty nodes.Example Live Demo#include #include #include #include using namespace std; const char MARKER = '$'; struct ... Read More

Find Symmetric Matrix of Order N with 0s on Main Diagonal in C++

Arnab Chakraborty
Updated on 24-Oct-2019 13:02:41

141 Views

Here we will see how to generate one symmetric matrix of order N, and the elements of each row will contain numbers from 0 to N – 1. The diagonal elements will be 0 always.This task is easy, we will form a matrix of N x N, then for each row i and for each column j, if i and j are same, then mark it as 0, otherwise increase one counter from 1 to N – 1, place the values for each individual row.Example#include using namespace std; void makeSymmetricMatrix(int n) {    int matrix[n][n];    for(int i = 0; i

Find Subset with Greatest Geometric Mean in C++

Arnab Chakraborty
Updated on 24-Oct-2019 12:58:09

162 Views

Here we have an array A with some elements. Our task is to find the subset where the geometric mean is maximum. Suppose A = [1, 5, 7, 2, 0], then the subset with greatest geometric mean will be [5, 7].To solve this, we will follow one trick, we will not find the mean, as we know that the largest two elements will form the greatest geometric mean, so the largest two elements will be returned as subset.Example#include using namespace std; void largestGeoMeanSubset(int arr[], int n) {    if (n < 2) {       cout max) ... Read More

Find a Point to Minimize Sum of Manhattan Distances in C++

Arnab Chakraborty
Updated on 24-Oct-2019 12:55:39

686 Views

Suppose we have n different points in K dimension space, the value of n is in range (2, 105), and value of k in range (1 to 5). We have to determine the point such that the sum of Manhattan distance from resultant point to n points is minimized.The Manhattan distance between two points P1(x1, y1) and P2(x2, y2), is |x1 – x2| + |y1 – y2|. Suppose dimension is 3, and there are three points like (1, 1, 1), (2, 2, 2), (3, 3, 3), then the output will be (2, 2, 2).To solve this problem, we have to ... Read More

Advertisements