Transform in C++

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

3K+ Views

The transform function is present in the C++ STL. To use it, we have to include the algorithm header file. This is used to perform an operation on all elements. For an example if we want to perform square of each element of an array, and store it into other, then we can use the transform() function.The transform function works in two modes. These modes are −Unary operation modeBinary operation modeUnary Operation ModeIn this mode the function takes only one operator (or function) and convert into output.Example#include #include using namespace std; int square(int x) {    //define square ... Read More

String Stream in C++

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

11K+ Views

Here we will see the string stream in C++. The string stream associates a string object with a string. Using this we can read from string as if it were a stream like cin.The Stringstream has different methods. These are like below −clear(): Used to clear the streamstr(): To get and set the string object whose content is present in streamoperator > : This is used to read from stringstream object.Let us see two examples of string streams. In the first program we will divide the words into separate strings.Example#include #include #include #include using namespace std; ... Read More

Java Connection getCatalog Method with Example

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

1K+ Views

In general, a catalog is a directory which holds information about data sets, file or, a database. Whereas in a database catalog holds the list of all the databases, base tables, views (virtual tables), synonyms, value ranges, indexes, users, and user groups.The getCatalog() method of the Connection interface returns the name of the current catalog/database, of the current connection object.This method returns a Sting value representing the name of the catalog. It returns null if there is no catalog.To get the catalog name −Register the driver using the registerDriver() method of the DriverManager class as −//Registering the Driver DriverManager.registerDriver(new com.mysql.jdbc.Driver());Get the connection ... Read More

Display Distinctly Ordered MongoDB Records with Skip and Limit

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

850 Views

You can work with aggregate framework and use $sort, $skip and $limit to display distinctly ordered records with skip and also set the limit. Let us first create a collection with documents> db.orderedDistinctDemo.insertOne({"Name":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb8e0140b992277dae0e9") } > db.orderedDistinctDemo.insertOne({"Name":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb8e5140b992277dae0ea") } > db.orderedDistinctDemo.insertOne({"Name":"Larry"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb8e7140b992277dae0eb") } > db.orderedDistinctDemo.insertOne({"Name":"Sam"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb8ea140b992277dae0ec") } > db.orderedDistinctDemo.insertOne({"Name":"John"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5ccfb8ee140b992277dae0ed") } > db.orderedDistinctDemo.insertOne({"Name":"Carol"}); {    "acknowledged" : true,    "insertedId" ... Read More

Read Input from JOptionPane in Java

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

268 Views

Yes, we can read from JOptionPane. Here, we will get the result of the showInputDialog() in a String variable −String input = JOptionPane.showInputDialog("Enter the C++ lessons you covered till now?");After getting the result, we will convert it to integer with parseInt() and display it on Console −int res = Integer.parseInt(input); System.out.println("Lessons covered = "+res);The following is an example to read from JOptionPane by requesting input from user −Examplepackage my; import java.awt.BorderLayout; import java.awt.Color; import java.awt.GridBagLayout; import java.awt.GridLayout; import java.net.URL; import javax.swing.ImageIcon; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; public class SwingDemo {    public static void main(String[] args) throws Exception { ... Read More

Sorted Difference Between Two Columns in MySQL

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

525 Views

Use ORDER BY clause for this. Let us first create a table −mysql> create table DemoTable    (    Value1 int,    Value2 int    ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values(10, 40); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable values(50, 5); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values(51, 56); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values(52, 78); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(90, 7); Query ... Read More

HTML Object Data Attribute

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

121 Views

Tha data attribute of the element sets the URL of the resource, which can be audio, video, pdf, flash, etc. used by the object.Following is the syntax:The url is the URL of the resource used by the object.Let us now see an example to implement the data attribute of the element:Example Live Demo CSS Demonstrating Application     OutputIn the above example, we have set the URL of the resource, which is a .swf file i.e. a flash file:The external link we have used in the element is:https://www.tutorialspoint.com/flex/samples/CSSApplication.swfRead More

Using List as Stack and Queues in Python

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

6K+ Views

In this article, we will learn about Stack & Queue structures in Python 3.x. Or earlier. Here we will discuss the working and modification within these data structures −This includes −Insertion operation (Push, Enqueue)Deletion operation (Pop, Dequeue)Display / Traversing OperationPrerequisites: List & List OperationsRelated Data Structure: List ManipulationRelated ImagesStackIn stacks, objects are stored one over another, and these objects get removed in the reverse order of the arrival i.e. LIFO concept is followed. LIFO means Last in First Out type arrangement is followed in the Stack data structure.Operations on a Stack −Addition / Appending of Element: This increases the stack ... Read More

C++ Program for Maximum Height When Coins are Arranged in a Triangle

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

627 Views

In this section, we will see one interesting problem. There are N coins. we have to find what is the max height we can make if we arrange the coins as pyramid. In this fashion, the first row will hold 1 coin, second will hold 2 coins and so on.In the given diagram, we can see to make a pyramid of height three we need minimum 6 coins. We cannot make height 4 until we have 10 coins. Now let us see how to check the maximum height.We can get the height by using this formula.Example Live Demo#include #include using namespace ... Read More

Object Slicing in C++

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

560 Views

Object slicing is used to describe the situation when you assign an object of a derived class to an instance of a base class. This causes a loss of methods and member variables for the derived class object. This is termed as information being sliced away. For example, class Foo {    int a; }; class Bar : public Foo {    int b; }Since Bar extends Foo, it now has 2 member variables, a and b. So if you create a variable bar of type Bar and then create a variable of type Foo and assign bar, you'll lose ... Read More

Advertisements