Coordinates of Rectangle with Given Points in C++

Ayush Gupta
Updated on 29-Jan-2020 07:30:11

244 Views

In this tutorial, we will be discussing a program to find the coordinates of rectanglewith given points lying inside.For this we will be provided with some coordinate points. Our task is to find the smallest rectangle such that all the points lie inside it and it should have its sides parallel to the coordinate axis.Example Live Demo#include using namespace std; //calculating the coordinates of smallest rectangle void print_rectangle(int X[], int Y[], int n){    //finding minimum and maximum points    int Xmax = *max_element(X, X + n);    int Xmin = *min_element(X, X + n);    int Ymax = *max_element(Y, ... Read More

Interesting Observations About C/C++ Ternary Operator

Arnab Chakraborty
Updated on 29-Jan-2020 07:29:59

321 Views

We know that ternary operator is implemented instead of if..else clause. It is denoted by ?: . '?' symbol is equivalent to if part and ':' is equivalent to else part. The following 3 programs explain some interesting observation in case of ternary operator.The following program is able to compile without any error. Ternary expression’s return type is expected to be float (as that of exp2) and exp3 (i.e. literal zero - int type) is able to implicitly convert to float.#include using namespace std; int main(){    int test1 = 0;    float fvalue = 3.111f;    cout

Convex Hull Using Divide and Conquer Algorithm in C++

Ayush Gupta
Updated on 29-Jan-2020 07:28:58

1K+ Views

In this tutorial, we will be discussing a program to find the convex hull of a given set of points.Convex hull is the smallest polygon convex figure containing all the given points either on the boundary on inside the figure.In this program, we will use brute force to divide the given points into smaller segments and then finally merging the ones that follow on to construct the convex hull.Example Live Demo#include using namespace std; //storing the center point of polygon pair mid; //calculating the quadrant of //a particular point int quad(pair p){    if (p.first >= 0 && p.second >= 0) ... Read More

Example of Event Handlers in HTML5 CORS

Vrundesha Joshi
Updated on 29-Jan-2020 07:27:21

198 Views

Cross-origin resource sharing (CORS) is a mechanism to allows the restricted resources from another domain in a web browserFor suppose, if you click on HTML5- video player in html5 demo sections. It will ask camera permission. If the user allows the permission then only it will open the camera or else it doesn't open the camera for web applications.The following is an example of event handlers in CORS:xhr.onload = function() {    var responseText = xhr.responseText;    // process the response.    console.log(responseText); }; xhr.onerror = function() {    console.log('There was an error!'); };

Two-Way Communication Between Browsing Contexts in HTML5

Rishi Rathor
Updated on 29-Jan-2020 07:26:39

382 Views

Two-way communication between the browsing contexts is called channel messaging. It is useful for communication across multiple origins.While creating messageChannel, it internally creates two ports to send the data and forwarded to another browsing context.postMessage() − Post the message throw channelstart() − It sends the dataclose() − it close the portsIn this scenario, we are sending the data from one iframe to another iframe. Here we are invoking the data in function and passing the data to DOM.var loadHandler = function(){    var mc, portMessageHandler;    mc = new MessageChannel();    window.parent.postMessage('documentAHasLoaded', 'http://foo.example', [mc.port2]);    portMessageHandler = function(portMsgEvent){     ... Read More

Send Cross-Document Message with HTML

Nancy Den
Updated on 29-Jan-2020 07:26:04

212 Views

Create a new web browsing context either by creating new iframe or new window. We can send the data using with postMessage() and it has two arguments. They are asmessage − The message to sendtargetOrigin − Origin nameLet us see an example to send a message from iframe to button:var iframe = document.querySelector('iframe'); var button = document.querySelector('button'); var clickHandler = function(){    iframe.contentWindow.postMessage('The message to send.','https://www.tutorialspoint.com); } button.addEventListener('click',clickHandler,false);

HTML5 Microdata Attributes

Samual Sam
Updated on 29-Jan-2020 07:25:23

189 Views

Microdata introduces five global attributes that would be available for any element to use and give context for machines about your data.AttributeDescriptionItemscopeThis is used to create an item. The itemscope attribute is a boolean attribute that tells that there is Microdata on this page, and this is where it starts.Itemtype This attribute is a valid URL which defines the item and provides the context for the properties.ItemidThis attribute is a global identifier for the item.ItempropThis attribute defines a property of the item.ItemrefThis attribute gives a list of additional elements to crawl to find the name-value pairs of the item.Read More

C vs Bash Fork Bomb

Arnab Chakraborty
Updated on 29-Jan-2020 07:25:12

461 Views

It is already cleared that the BASH fork bomb is much more powerful than its version of C program. The main cause is that in BASH the created process is detached from the parent. If the parent process (the one we initially started) is destroyed or killed, the remaining or rest of the processes live on. But in case of the C implementation, the listed child processes die automatically if the parent is destroyed or killed. A script is responsible to communicate with the system directly.The fork bomb program in C can be updated or modified. We can be able ... Read More

Convex Hull Monotone Chain Algorithm in C++

Ayush Gupta
Updated on 29-Jan-2020 07:23:54

237 Views

In this tutorial, we will be discussing a program to find the convex hull of a given set of points.Convex hull is the smallest polygon convex figure containing all the given points either on the boundary on inside the figure.Example Live Demo#include #define llu long long int using namespace std; //structure for the given point struct Point {    llu x, y;    bool operator= t && calc_crossproduct(ans[k - 2],       ans[k - 1], A[i - 1])

Else and Switch Statements with Initializers in C++17

Arnab Chakraborty
Updated on 29-Jan-2020 07:22:23

295 Views

In many cases, we need to verify the value of something returned by a function and perform conditional operations based on this value. So our code is given below −// Some method or function return_type foo(Params) // Call function with Params and // store return in var1 auto var1 = foo(Params); if (var1 == /* some value */) {    //Perform Something } else {    //Perform Something else }Just follow the general format in all conditional if-else blocks. Firstly there is exist an optional initial statement which sets up the variable, followed by the if-else block. So the general ... Read More

Advertisements