C++ Function Call Puzzle

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

279 Views

We know that C and C++ are very much similar in different aspects. The C++ has additional object oriented feature in it, but most of the C programs can also be correct in C++. Here we will see one program related to function call, that can be run when it is written in C, but will not work in C++.Example Live Demo#include void myFunction() {    printf("Function called"); } int main() {    myFunction();    myFunction(2); }OutputFunction called Function calledThis program will run in C and generates output, but when we want to compile in C++, it will return an error ... Read More

Mongo Shell and Number Handling: Float by Default

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

253 Views

Yes, Mongo shell treats numbers as float by default. To work it as int or any other type, you need to mention explicitly. You can use NumberInt() for this. The syntax is as follows −var anyVariableName= [NumberInt("yourValue1"), NumberInt("yourValue2"), .....N];Let us implement the above syntax in order to treat numbers as integer only (not float) −> var integerArrayDemo = [NumberInt("50"), NumberInt("60"),    NumberInt("70"), NumberInt("90"), NumberInt("40")];Following is the query to display the array value −> printjson(integerArrayDemo);This will produce the following output −[    NumberInt(50),    NumberInt(60),    NumberInt(70),    NumberInt(90),    NumberInt(40) ]To display the array value, you can use print() −> ... Read More

Simulate JButton Click Action in Java

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

1K+ Views

Let us first set a JButton:JButton btn = new JButton("DemoButton");Now, attach action listener:btn.addActionListener(new ClickListener());If you have an ActionListener attached to your button it'll fire when you call the method doClick():btn.doClick();The following is an example to call JButton doClick() method to simulate a click action:Exampleimport java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JOptionPane; public class SwingDemo {    public static void main(final String args[]) {       JButton btn = new JButton("DemoButton");       btn.addActionListener(new ClickListener());       JOptionPane.showMessageDialog(null, btn);       btn.doClick();    } } class ClickListener implements ActionListener {    public void actionPerformed(ActionEvent e) {   ... Read More

Group Android Notifications Like WhatsApp

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

873 Views

This example demonstrate about How to group android notifications like whatsappStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.javapackage app.tutorialspoint.com.notifyme ; import android.app.NotificationChannel ; import android.app.NotificationManager ; import android.content.Context ; import android.support.v4.app.NotificationCompat ; import android.support.v7.app.AppCompatActivity ; import android.os.Bundle ; import android.view.View ; import android.widget.Button ; public class MainActivity extends AppCompatActivity {    public static final String NOTIFICATION_CHANNEL_ID = "10001" ;    private final ... Read More

Update Object at Specific Array Index in MongoDB

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

611 Views

To update object at specific array index, use update() in MongoDB. Let us first create a collection with documents −> db.updateObjectDemo.insertOne( ...   { ...       id : 101, ...       "StudentDetails": ...       [ ...          [ ...             { ...                "StudentName": "John" ...             }, ...             { "StudentName": "Chris" } ...          ], ...          [ { "StudentName": "Carol" }, ... Read More

Set Line Border Color and Width with Java

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

5K+ Views

To set Line Border color and width, use the LineBorder. At first, set a panel wherein we need to set the line border −JPanel panel = new JPanel();Now, create a border and set on the panel created above −Border border = new LineBorder(Color.ORANGE, 4, true); panel.setBorder(border);The following is an example to set LineBorder color and width −package my; import java.awt.Color; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.border.Border; import javax.swing.border.LineBorder; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       JPanel panel = new JPanel();   ... Read More

Change Data Type from Date to DateTime in MySQL

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

880 Views

To change data type from date to date/time, use alter command.alter table yourTableName change yourColumnName yourColumnName datetime;Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    LoginDate date    ); Query OK, 0 rows affected (1.26 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(LoginDate) values('2019-01-21'); Query OK, 1 row affected (0.29 sec) mysql> insert into DemoTable(LoginDate) values('2018-05-01'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable(LoginDate) values('2017-12-31'); Query OK, 1 row affected (0.12 sec)Display all records from the table using select statement ... Read More

Implement Lexicographical Compare in C++ STL

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

130 Views

The C++ function std::algorithm::lexicographical_compare() tests whether one range is lexicographically less than another or not. A lexicographical comparison is the kind of comparison generally used to sort words alphabetically in dictionaries.Declarationtemplate bool lexicographical_compare(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2);AlgorithmBegin    result = lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end())    if (result == true)       Print v1 is less than v2    result = lexicographical_compare(v1.begin(), v1.end(), v2.begin(), v2.end())    if (result == false)       Print v1 is not less than v2 EndExample Live Demo#include #include #include #include using namespace std; int main(void) {    //initialization ... Read More

Use Switch Statement with Strings in Java

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

11K+ Views

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.Syntaxswitch(expression) {    case value :       // Statements       break;    case value :       // Statements       break;       // You can have any number of case statements.       default :     // Statements }Strings in switchYes, we can use a switch statement with Strings in Java. While doing so you need ... Read More

HTML DOM Input Hidden Form Property

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

182 Views

The HTML DOM input hidden form property returns the reference of the form that contain the hidden input field in the HTML document.SyntaxFollowing is the syntax −object.formExampleLet us see an example of HTML DOM input hidden form property − Live Demo    body{       text-align:center;       background-color:#363946;       color:#fff;    }    form{       margin:2.5rem auto;    }    button{       background-color:#db133a;       border:none;       cursor:pointer;       padding:8px 16px;       color:#fff;       border-radius:5px;       font-size:1.05rem;   ... Read More

Advertisements