Command line arguments in C/C++

Arjun Thakur
Updated on 30-Jul-2019 22:30:25
It is possible to pass some values from the command line to your C programs when they are executed. These values are called command line arguments and many times they are important for your program especially when you want to control your program from outside instead of hard coding those values inside the code.The command line arguments are handled using main() function arguments where argc refers to the number of arguments passed, and argv[] is a pointer array which points to each argument passed to the program. Following is a simple example which checks if there is any argument supplied ... Read More

C++ Program to Implement Expression Tree Algorithm

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25
An expression tree is basically a binary which is used to represent expressions. In expression tree, internal nodes correspond to operators and each leaf node corresponds to an operand. Here is a C++ Program to implement the Expression Tree Algorithm which takes the postfix expression as an input and generates the corresponding expression tree traversed in inorder.AlgorithmBegin    function construct_expression_tree():       Flag = 1 when it is operand.       Flag = -1 when it is operator.       S = suffix[0] means read the first operand from the expression.    For i = 0 and ... Read More

Perform conditional upserts or updates in MongoDB

Chandu yadav
Updated on 30-Jul-2019 22:30:25
For conditional upserts or updates, you can use $max operator. Let us first create a collection with documents>db.conditionalUpdatesDemo.insertOne({"_id":100, "StudentFirstScore":89, "StudentSecondScore":78, "BiggestScore":89}); { "acknowledged" : true, "insertedId" : 100 } >db.conditionalUpdatesDemo.insertOne({"_id":101, "StudentFirstScore":305, "StudentSecondScore":560, "BiggestScore":1050}); { "acknowledged" : true, "insertedId" : 101 } >db.conditionalUpdatesDemo.insertOne({"_id":103, "StudentFirstScore":560, "StudentSecondScore":789, "BiggestScore":880}); { "acknowledged" : true, "insertedId" : 103 } Following is the query to display all documents from a collection with the help of find() method: > db.conditionalUpdatesDemo.find().pretty();This will produce the following output{    "_id" : 100,    "StudentFirstScore" : 89,    "StudentSecondScore" : 78,    "BiggestScore" : 89 } {    "_id" : 101,   ... Read More

Java Program to convert LocalDate to java.util.Date

Samual Sam
Updated on 30-Jul-2019 22:30:25
Let us first set the LocalDate to current date −LocalDate date = LocalDate.now();Create an Instant −Instant i = date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();Convert it to java.util.Date −java.util.Date.from(i)Example Live Demoimport java.time.Instant; import java.time.LocalDate; import java.time.ZoneId; public class Demo {    public static void main(String[] args) {       LocalDate date = LocalDate.now();       System.out.println("LocalDate = "+date);       Instant i = date.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant();       System.out.println("java.util.Date = "+java.util.Date.from(i));    } }OutputLocalDate = 2019-04-19 java.util.Date = Fri Apr 19 00:00:00 IST 2019

How to write a short literal in C++?

Smita Kapse
Updated on 30-Jul-2019 22:30:25
Here we will see how will be the short literal in C++. In C or C++, different types of data have different literals. These are listed below.Sr.NoDatatypes & Literals1int52unsigned int5U3Long5L4long long5LL5float5.0f6double5.07char‘\5’Now, there are int, long float, double etc, but no short is present. So we cannot use any literals for short type data. But we can solve this problem by explicit typecasting.If we use the line like below, then it will be converted into short.int x; x = (short) 5; //converted into short type data.Example#include using namespace std; main() {    int x;    x = 65700;    cout ... Read More

C++ Program to Implement the Solovay-Strassen Primality Test to Check if a Given Number is Prime

Anvi Jain
Updated on 30-Jul-2019 22:30:25
Solovay-Strassen Primality Test is used to test a number whether it is a composite or possibly prime number.AlgorithmsBegin    Declare a function modulo to the long datatype to perform binary calculation.       Declare m_base, m_exp, m_mod of long datatype and pass them as a parameter.       Declare two variables a, b of long datatype.          Initialize a = 1, b = m_base.       while (m_exp > 0) do          if (m_exp % 2 == 1) then             a = (a * b) % ... Read More

Why college reunions are an important ritual?

Pari
Updated on 30-Jul-2019 22:30:25
College reunions are the times which brings back the old memories, pleasant or unpleasant. Many people look forward to such reunions to prove to the world what they have achieved and many will be reluctant to go to such reunions because of their scarred memories.But college reunions are some of the important rituals in one's life. Individuals will be compared to their adolescent self and how far they have come in life when compared to their classmates. They are a kind of eye-opening sessions. Individuals develop maturity with age. Recalling our old memories will help us to gain better insight ... Read More

What is a Triplet class in Java Tuples?

Samual Sam
Updated on 30-Jul-2019 22:30:25
A Triplet class is a Tuple of three elements. It is part of the JavaTuples library.The following is the declaration −public final class Triplet extends Tuple implements IValue0, IValue0, IValue0Let us first see what we need to work with JavaTuples. To work with Triplet class in JavaTuples, you need to import the following package −import org.javatuples.Triplet;Some of its features include −ComparableIterableTypesafeSerializableImmutableNote − Steps to download and run JavaTuples program. If you are using Eclipse IDE to run Triplet Class in JavaTuples, then Right Click Project ->Properties ->Java Build Path ->Add External Jars and upload the downloaded JavaTuples jar file.The following ... Read More

How to convert date and time into int in Android sqlite?

Anvi Jain
Updated on 30-Jul-2019 22:30:25
Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How to convert date and time into int in Android sqliteStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all ... Read More

How to use actual row count (COUNT(*)) in WHERE clause without writing the same query as subquery in MySql?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25
Achieve this with the help of where clause.The syntax is as followsSELECT yourColumnName1, yourColumnName2, ...N FROM yourTableName WHERE (    SELECT COUNT(*) FROM yourTableName )=2;To understand the concept, let us create a table. The query to create a table is as followsmysql> create table CountWithSubqueryDemo    - > (    - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > EmployeeName varchar(20)    - > ); Query OK, 0 rows affected (2.09 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into CountWithSubqueryDemo(EmployeeName) values('John'); Query OK, 1 row affected (0.54 sec) mysql> ... Read More
Advertisements