Nishtha Thakur has Published 564 Articles

Set a component and place it next to the previously added component with GridBagLayout in Java

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

91 Views

We have set a component first −GridBagConstraints constraints = new GridBagConstraints(); constraints.gridy = 0; panel.add(new JButton("First row"), constraints);Now, we will place it next to the previously added component −constraints.gridx = GridBagConstraints.RELATIVE; constraints.gridy = 1; panel.add(new JButton("2nd row 1st column"), constraints); panel.add(new JButton("2nd row 2nd column"), constraints);Examplepackage my; import java.awt.GridBagConstraints; import ... Read More

C program that won’t compile in C++

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

367 Views

The C++ language is designed by adding some additional features like Object Oriented concepts with C. Most of the C programs can be compiled using C++ compiler also. Though there are some programs that cannot be compiled using C++ compiler.Let us see some code, that will compile in C compiler, ... Read More

C++ Program to Implement the Vizing’s Theorem

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

147 Views

Vizing’s theorem state that the chromatic index of simple graph can be either maxdegree or maxdegree+1. Here, chromatic index means maximum color needed for the edge coloring of the graph.This is a C++ program to implement the Vizing’s Theorem.AlgorithmBegin    Take the number of vertices and edges as input.   ... Read More

How to remove key fields in MongoDB?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

1K+ Views

To remove key fields in MongoFB, you can use $unset operator. Let us first create a collection with documents −>db.removeKeyFieldsDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Doe", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc6c8289cb58ca2b005e672") } >db.removeKeyFieldsDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Smith", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc6c8359cb58ca2b005e673") }Following is the query to display ... Read More

How to create titled border for a Panel in Java?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

375 Views

To create titled border for a panel, use the createTitledBorder() method. Let us create a panel first −JPanel panel = new JPanel(); JButton btn1 = new JButton("One"); JButton btn2 = new JButton("Two"); panel.add(btn1); panel.add(btn2);Now, set titled border with BorderFactory class −panel.setBorder(BorderFactory.createTitledBorder("Title of the border"));The following is an example to create ... Read More

trunc() , truncf() , truncl() in C language

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

1K+ Views

Here we will see three functions. These functions are trunc(), truncf() and the truncl(). These functions are used to convert floating point values into truncated form.The trunc() FunctionThis function is used to truncate double type value. And return only the integer part. The syntax is like below.double trunc(double argument)Example#include ... Read More

C++ program to print Happy Birthday

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

5K+ Views

This is a C++ program to print Happy Birthday.AlgorithmBegin    Take a str1 which takes the next character of our desired ouput like for H it will be G.    Assign the string to a pointer p.    Make a while loop till *p != NULL.       Go ... Read More

Variable collection name in MongoDB shell with JavaScript?

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

135 Views

Yes, you can set a variable collection name in MongoDB shell using JavaScript. Let us first create a collection with documents −> db.employeeInformation.insertOne({"EmployeeName":"John Smith", "EmployeeAge":24, "EmployeeSalary":450000}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cc6d06baf8e7a4ca6b2ad97") }Following is the query to display all documents from a collection with the help of ... Read More

Foreach in C++ and Java

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

125 Views

In C++ and Java, there are another type of loop called foreach loop. This is not present in C. This loop has introduced in C++11 and Java JDK 1.5.0. The advantage of this loop is that, it can access the elements very quickly without performing initialization, testing and increment/decrement. This ... Read More

C++ Program to Check Cycle in a Graph using Topological Sort

Nishtha Thakur

Nishtha Thakur

Updated on 30-Jul-2019 22:30:26

298 Views

In a Directed Acyclic Graph, we can sort vertices in linear order using topological sort.Topological sort is only work on Directed Acyclic Graph. In a Directed Acyclic Graph (DAG), there can be more than one topological sort.We shall consider a C++ program, which will perform topological sort to check cycle ... Read More

Advertisements