Here we will see the fesetround() and fegetround() method in C++. These methods can be found in the cfenv library.The fesetround() method is used to set the specified floating point rounding direction to the current rounding direction. This is used with rint(), nearbyint() and some other rounding functions in C++.The syntax is like below −int fesetround(int round);The round can be among these FE_TONEAREST, FE_DOWNWARD, FE_UPWARD etc. This function returns 0 when rounding direction is successfully applied to the required manner.Example#include #include #include using namespace std; main() { double x = 4.7, ans; fesetround(FE_TONEAREST); //round to ... Read More
The SQL Count() function returns the number of rows in a table. Using this you can get the number of rows in a table.select count(*) from TABLE_NAME;Let us create a table with name cricketers_data in MySQL database using CREATE statement as shown below −CREATE TABLE cricketers_data( First_Name VARCHAR(255), Last_Name VARCHAR(255), Date_Of_Birth date, Place_Of_Birth VARCHAR(255), Country VARCHAR(255), );Now, we will insert 5 records in cricketers_data table using INSERT statements −insert into cricketers_data values('Shikhar', 'Dhawan', DATE('1981-12-05'), 'Delhi', 'India'); insert into cricketers_data values('Jonathan', 'Trott', DATE('1981-04-22'), 'CapeTown', 'SouthAfrica'); insert into cricketers_data values('Kumara', 'Sangakkara', DATE('1977-10-27'), 'Matale', 'Srilanka'); insert into cricketers_data values('Virat', 'Kohli', DATE('1988-11-05'), 'Delhi', ... Read More
Let us first create a collection with documents −>db.missingDocumentDemo.insertOne({"StudentFirstName":"Adam", "StudentLastName":"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd3fb1eedc6604c74817ce6") } >db.missingDocumentDemo.insertOne({"StudentFirstName":"Carol", "StudentLastName":"Taylor"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd3fb29edc6604c74817ce7") } >db.missingDocumentDemo.insertOne({"StudentFirstName":"David", "StudentLastName":"Miller", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5cd3fb40edc6604c74817ce8") }Following is the query to display all documents from a collection with the help of find() method −> db.missingDocumentDemo.find().pretty();This will produce the following output −{ "_id" : ObjectId("5cd3fb1eedc6604c74817ce6"), "StudentFirstName" : "Adam", "StudentLastName" : "Smith" } { "_id" : ObjectId("5cd3fb29edc6604c74817ce7"), "StudentFirstName" : "Carol", "StudentLastName" : "Taylor" } { "_id" : ... Read More
To disable only the vertical scrollbar, use the VERTICAL_SCROLLBAR_NEVER constant, which displays only the horizontal scrollbar.The following is an example to disable only the vertical scrollbar in Java −Examplepackage my; import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.Box; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JScrollPane; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button1 = new JButton("Online Compiler"); JButton button2 = new JButton("Quiz"); JButton button3 = new JButton("Questions and Answers"); JButton button4 = new JButton("Videos"); ... Read More
To move the first row to the end of the table in Java, use the moveRow() method. It has three parameters. The first two parameters allows you to set the starting and ending row index to be moved. The last parameter sets the destination of the rows to be moved.As discussed above, move the first row to the end −tableModel.moveRow(0, 0, tableModel.getRowCount() - 1);The following is an example to move the first row to the end of the table −Examplepackage my; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class SwingDemo { public static void main(String[] argv) throws ... Read More
Grouping a set of INSERT Statements and executing them at once is known as batch insert.Batch inserts using PreparedStatement objectTo execute a batch of insert statements using the PreparedStatement object −Create a PreparedStatement − Create a PreparedStatement object using the prepareStatement() method. Pass the Insert query with place holders “?” instead of values as a parameter to this method.PreparedStatement pstmt = con.prepareStatement("INSERT INTO Sales VALUES (?, ?, ?, ?, ?)");Set the values to the place holders − Using the setXXX() methods (setInt(). SetString(), setFloat() etc…) set the values to the place holders in the PrepareStatement as −pstmt.setString(1, "KeyBoard"); pstmt.setString(2, "Amith"); ... Read More
Let us first get the current date using CURDATE(). The current date is as follows −mysql> select CURDATE(); +------------+ | CURDATE() | +------------+ | 2019-06-09 | +------------+ 1 row in set (0.00 sec)Let us first create a table −mysql> create table DemoTable -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ShippingDate date -> ); Query OK, 0 rows affected (0.63 sec)Insert some records in the table using insert command. While inserting, we have used date_sub to get the previous day −mysql> insert into DemoTable(ShippingDate) values(date_sub(CURDATE(), interval 1 day)); Query OK, 1 row ... Read More
Here we will see how to get the sum of elements from index i to index j in an array. This is basically the range query. The task is easy by just running one loop from index i to j, and calculate the sum. But we have to care about that this kind of range query will be executed multiple times. So if we use the mentioned method, it will take much time. To solve this problem using more efficient way we can get the cumulative sum at first, then the range sum can be found in constant time. Let ... Read More
Here we will see what are the sizes of the int and long type data in C++. The sizes are depending on the system architecture and the Operating system.So in the 32-bit system, the standard is ILP32. In this standard the int, long and the pointer variables are of 32-bits.For the 64-bit system there are two variations. For Linux Operating system the standard is LP64. Here long and pointer are of 64-bits, but int are of 32-bits. For the Windows operating system, the standard is LLP64. Here long long is 64-bit, but int and long are of 32-bits.Example#include using ... Read More
Bit-map protocol is a collision free protocol that operates in the Medium Access Control (MAC) layer of the OSI model. It resolves any possibility of collisions while multiple stations are contending for acquiring a shared channel for transmission.In this protocol, if a station wishes to transmit, it broadcasts itself before the actual transmission. This is an example of Reservation Protocol.Working PrincipleIn this protocol, the contention period is divided into N slots, where N is the total number of stations sharing the channel. If a station has a frame to send, it sets the corresponding bit in the slot.Suppose that there ... Read More