Area of the Largest Square Inscribed in an Ellipse in C++

Arnab Chakraborty
Updated on 20-Aug-2019 07:32:24

134 Views

Here we will see the area of largest square that can be inscribed in an ellipse. The square in ellipse will be like below −The area of ellipse is −Now, if x and y are same, thenSo area is −Example#include #include using namespace std; float area(float a, float b) {    if (a < 0 || b < 0 ) //if values are is negative it is invalid       return -1;    float area = (4*(a*a + b*b)) / (a*a*b*b);    return area; } int main() {    float a = 4, b = 2;    cout

HTML DOM Geolocation Coordinates Property

AmitDiwan
Updated on 20-Aug-2019 07:28:46

182 Views

The HTML DOM Geolocation coordinates property is used for getting a user’s device position and altitude on earth. The user have to approve that he wants to give coordinates before this property could work. This is done so that a user’s privacy isn’t compromised. This can be used for tracking various device's location.PropertiesFollowing are the coordinates property −Note − All these properties are read-only and their return type is double.Sr.NoProperty & Description1coordinates.latitudeTo return the device position’s latitude in decimal degrees.2coordinates.longitudeTo return the device position's longitude in decimal degrees3coordinates.altitudeTo return the position's altitude in meters, relative to sea level. It can ... Read More

Area of the Circumcircle of Any Triangle with Sides in C++

Arnab Chakraborty
Updated on 20-Aug-2019 07:28:26

159 Views

Here we will see how to get the area of the circumcircle of any triangle whose sides are given. Here the side AB is a, BC is b and CA is c, the radius is ‘r’.The radius r is same as −Example#include #include using namespace std; float area(float a, float b, float c) {    if (a < 0 || b < 0 || c < 0) //if values are is negative it is invalid       return -1;    float s = (a + b + c) /2;    float triangle = sqrt(s * (s - ... Read More

HTML DOM fullscreenEnabled Method

AmitDiwan
Updated on 20-Aug-2019 07:20:46

118 Views

The HTML DOM fullscreenEnabled() method is used for specifying if the fullscreen mode is available or not for the current document. Its return type is boolean and is a read-only property. True is returned if the fullscreen mode is available otherwise it returns false. Different prefixes are used to make it work with your browser.SyntaxFollowing is the syntax for fullscreenEnabled() method −document.fullscreenEnabled()Let us look at an example for the fullscreenEnabled() method −Note − You will need to use your browser prefix for fullscreenEnabled() method to work. Check the note at the last to have your browser specific prefix.ExampleLet us see ... Read More

Addition and Subtraction of Matrix Using Pthreads in C/C++

Arnab Chakraborty
Updated on 20-Aug-2019 07:19:09

943 Views

Here we will see how to perform the matrix addition and subtraction using multithreaded environment. The pthread is used to execute multiple threads simultaneously in C or C++.There are two matrices A and B. Order of each matrix is (m x n). Each thread will take each row, and perform addition or subtraction. So for m rows, there are m different threads.Example#include #include #include #include #define CORE 3 #define MAX 3 using namespace std; int AMat[MAX][MAX] = {{10, 20, 30},    {40, 50, 60},    {70, 80, 50} }; int BMat[MAX][MAX] = {{80, 60, 20},    {30, ... Read More

Find Sum of Series with N-th Term as n^2 - (n-1)^2 in C++

Arnab Chakraborty
Updated on 20-Aug-2019 07:15:14

180 Views

Here we will see how to get the sum of the series with n-th term as n2 – (n-1)2. The recurrence relation is like below −Tn = n2 − (n−1)2So the series is −We need to find S mod (109 + 7), where S is the sum of all terms of the given series.Example#include #define X 1000000007 using namespace std; long long getSum(long long n) {    return ((n % X) * (n % X)) % X; } int main() {    long long n = 56789;    cout

Hidden Tricks of C++ Related to STL

Arnab Chakraborty
Updated on 20-Aug-2019 07:07:31

263 Views

Here we will see some hidden tricks of C++ related to STL.Assign value of pairs using braces ‘{}’. We can use them to assign into tuples also.pair my_pair = make_pair(10, 20); pair my_pair2 = { 10, 20 }; //using braces pair my_pair3 = { 10, { 'A', 20 } }; //complex pairSometimes we do not remember to include lots of headers, or sometimes we forget the names of the headers, in that time we can follow this trick to include all headers.#include C++ has inbuilt GCD function. That function is not so popular so we do not know about it. ... Read More

Add All Greater Values to Every Node in the Given BST

Arnab Chakraborty
Updated on 20-Aug-2019 07:04:27

175 Views

Here we will see one interesting problem, where we will add greater values to every node in one given binary search tree. So the initial and final tree will be look like below −AlgorithmbstUpdate(root, sum) −Begin    if root is null, then stop    bstUpdate(right of room, sum)    sum := sum + value of root    update root value using sum    bstUpdate(left of room, sum) EndExample#include using namespace std; class Node {    public:       int data;       Node *left, *right;    };    Node *getNode(int item) {       Node *newNode = ... Read More

Types of Polymorphisms: Ad-Hoc Inclusion, Parametric, and Coercion

Arnab Chakraborty
Updated on 20-Aug-2019 07:01:05

4K+ Views

Here we will see different types of polymorphism. The types are −Ad-HocInclusionParametricCoercionThe Ad-Hoc polymorphism is called as overloading. This allows function with same name to act in different manner for different types. The function and the operator both can be overloaded. Some language does not support operator overloading, but function overloading is common.Example#include using namespace std; int add(int a, int b) {    return a + b; } string add(string a, string b) {    return a + b; //concatenate } int main() {    cout

HTML DOM Form Target Property

AmitDiwan
Updated on 20-Aug-2019 07:00:30

278 Views

The HTML DOM Form target property is used for specifiying where the response should be displayed after the form data has been submitted. It could display in a new tab, current tab or a new window. The form target property set or gets the target attribute value.SyntaxFollowing is the syntax for −Setting the target property −formObject.target = "_blank|_self|_parent|_top|framename"Here, _blank will open the response in new window, _self will open the response in the same window; parent will open in the parent frame, _top will open in full window body and framename will open it in a specified named frame.ExampleLet us ... Read More

Advertisements