static_cast − This is used for the normal/ordinary type conversion. This is also the cast responsible for implicit type coersion and can also be called explicitly. You should use it in cases like converting float to int, char to int, etc.dynamic_cast − This cast is used for handling polymorphism. You only need to use it when you're casting to a derived class. This is exclusively to be used in inheritance when you cast from base class to derived class.Regular Cast − This is the most powerful cast available in C++ as it combines const_cast, static_cast and reinterpret_cast. but it's also ... Read More
PyMongo is a Python distribution containing tools for working with MongoDB. Use the following syntax to use a variable for collection name −var yourVariableName="yourCollectionName"; db[storeCollectionName].yourOperationName;To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows. We have used variable for collection name −> var storeCollectionName="new_Collection"; > db[storeCollectionName].insertOne({"UserName":"John", "UserAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c912aea4afe5c1d2279d6a0") } > db[storeCollectionName].insertOne({"UserName":"Carol", "UserAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5c912af54afe5c1d2279d6a1") } > db[storeCollectionName].insertOne({"UserName":"Mike", "UserAge":27}); { "acknowledged" : true, "insertedId" : ObjectId("5c912afe4afe5c1d2279d6a2") }Display ... Read More
Hangman is a classic word game in which participants needs to guess as many secret words as you can before time runs out! So, it’s a nice game to learn new words, one letter at a time!So we are going to write python script for this classic game “hangman”.#importing the time module import time #welcoming the user name = input("What is your name? ") print("Hello, " + name, "Time to play hangman!") print ("") #wait for 1 second time.sleep(1) print ("Start guessing...") time.sleep(0.5) #here we set the secret word= ("Secret") word = word.lower() ... Read More
In MySQL, we give an alias name for a column. Similarly, you can give an alias name for field name in MongoDB. The MongoDB equivalent syntax is as followsdb.yourCollectionName.aggregate( [ { "$project": { "_id": 0, "anyAliasName": "$yourFieldName" }} ]);Let us first create a collection with documents> db.selectFieldAsAnotherNameDemo.insertOne({"Name":"Larry"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9d448827b86948e204ca91") } > db.selectFieldAsAnotherNameDemo.insertOne({"Name":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9d449027b86948e204ca92") } > db.selectFieldAsAnotherNameDemo.insertOne({"Name":"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9d449527b86948e204ca93") } > db.selectFieldAsAnotherNameDemo.insertOne({"Name":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5c9d449927b86948e204ca94") ... Read More
At first, create a Random class object −Random rand = new Random();Now, create a new array −int num; int arr[] = new int[10];Loop through and set the Random nextInt with 20 as parameter since you want random numbers less than 20 −for (int j = 0; j
To convert string to bitset, use the CONV() method. Let us first create a table −mysql> create table DemoTable ( stringValue BIT(4) ); Query OK, 0 rows affected (3.50 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(CONV('1110', 2, 10) * 1); Query OK, 1 row affected (0.62 sec) mysql> insert into DemoTable values(b'1011'); Query OK, 1 row affected (0.14 sec)Following is the query to display all records from the table using select statement −mysql> select *from DemoTable;Following is the output that displays blank result because the type is bitset −Following is the query ... Read More
Yes, we can do that using removeArrow() method.The following is an example to disable JComboBox arrow button:Exampleimport java.awt.Component; import java.awt.Container; import javax.swing.*; public class SwingDemo { public static void main(String[] args) { String[] strValues = {"One", "Two"}; JComboBox comboBox = new JComboBox(strValues); removeArrow(comboBox); JOptionPane.showMessageDialog(null, comboBox); } private static void removeArrow(Container container) { Component[] c = container.getComponents(); for (Component res : c) { if (res instanceof AbstractButton) { container.remove(res); } } } }Output
A view of the ByteBuffer can be created as a CharBuffer using the asCharBuffer() method in the class java.nio.ByteBuffer. This method requires no parameters and it returns a char buffer as required. This buffer reflects the changes made to the original buffer and vice versa.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 50; try { ByteBuffer bufferB = ByteBuffer.allocate(n); ... Read More
This program represents a graph using incidence list and the time complexity of this algorithm is O(e).AlgorithmBegin Take the input of the number of vertex ‘v’ and edges ‘e’ and also take the input of ‘e’ pairs of vertexes of the given graph in e[][]. For each edge print the corresponding vertex involved in that connection. EndExample Code#include using namespace std; int main() { int i, v, e, j, c; coutv; coute; int edge[e][2]; for(i = 0; i < e; i++) { cout
To update the objects in a document’s array, you need to use update() method. To understand the update() method, let us create a collection with document. The query to create a collection with document is as follows:> db.updateObjects.insertOne({"CustomerId":1, "CustomerName":"Larry", "TotalItems":100, ... "ItemDetails":[ ... { ... "NameOfItem":"Item_1", ... "Amount":450 ... }, ... { ... "NameOfItem":"Item_2", ... "Amount":500 ... }, ... { ... "NameOfItem":"Item_3", ... "Amount":200 ... } ... ] ... } ... );The following is the output:{ "acknowledged" : true, "insertedId" : ObjectId("5c6d688b0c3d5054b766a769") }Now you can display documents from a collection with the help of find() method. The query ... Read More