Anvi Jain

Anvi Jain

427 Articles Published

Articles by Anvi Jain

Page 19 of 43

C function argument and return values

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 10K+ Views

Here we will see what are the different types of C functions based on the return values and arguments.So a function either can take some arguments, or nothing is taken. Similarly, a function can return something, otherwise does not return anything. So we can categorize them into four types.Function with No argument and No return type.Function with No argument and Return something.A function that takes argument but returns nothing.Functions that take an argument and also return something.Example#include void my_function() {    printf("This is a function that takes no argument, and returns nothing."); } main() {    my_function(); }OutputThis is ...

Read More

MongoDB Limit fields and slice projection together?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 288 Views

Use the $slice operator. Let us first create a collection with documents −> db.limitAndSliceProjectionDemo.insertOne(    {       "_id" : 101,       "UserName" : "Carol",       "UserAge" : 26,       "UserMesssage" : [          "Hi",          "Hello",          "Bye",          "Awesome",          "Good",          "Bad",          "Nice",          "Good Night",          "Good Morning"       ]    } ); { "acknowledged" : true, "insertedId" : ...

Read More

Compiling multiple .cpp files in c++ program

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 2K+ Views

Here we will see how to compile multiple cpp file in C++ program. The task is very simple. We can provide the names as a list to the g++ compiler to compile them into one executable fileTo compile multiple files like abc.cpp, and xyz.cpp at once, the syntax will be like this −g++ abc.cpp xyz.cppTo run the program, we can use this −./a.outExamplefloat area(float r){    return (3.1415*r*r); //area of a circle } float area(float l, float w) {    return (l * w); //area of a rectangle }Example#include #include "area.cpp" using namespace std; main() {    cout

Read More

Check input character is alphabet, digit or special character in C

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 3K+ Views

In this section, we will see how to check whether a given character is number, or the alphabet or some special character in C.The alphabets are from A – Z and a – z, Then the numbers are from 0 – 9. And all other characters are special characters. So If we check the conditions using these criteria, we can easily find them.Example#include #include main() {    char ch;    printf("Enter a character: ");    scanf("%c", &ch);    if((ch >= 'A' && ch = 'a' && ch = '0' && ch

Read More

How to insert an 8-byte integer into MongoDB through JavaScript shell?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 263 Views

You can use below syntax for inserting an 8-byte integer in MongoDB through JavaScript shell −anyVariableName= {"yourFieldName" : new NumberLong("yourValue")};To display the above variable, you can use the variable name or printjson(). Following is the query to insert 8 byte integer in MongoDB −> userDetail = {"userId" : new NumberLong("98686869")}; { "userId" : NumberLong(98686869) }Let us display the above variable value using variable name. The query is as follows −> userDetailThis will produce the following output −{ "userId" : NumberLong(98686869) }Let us display the variable value using printjson() −> printjson(userDetail); This will produce the following output −{ "userId" : NumberLong(98686869) }

Read More

How to change header background color of a table in Java

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 2K+ Views

To change header background color, at first get the header background −JTableHeader tableHeader = table.getTableHeader();Now, set the background color using set Background() −tableHeader.setBackground(Color.black);Above, we have used the Color class to set the color.The following is an example to change the header background color of a JTable −Examplepackage my; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.JTableHeader; public class SwingDemo {    public static void main(String[] argv) throws Exception {       Integer[][] marks = {          { 70, 66, 76, 89, 67, 98 },          { 67, 89, 64, ...

Read More

How to get primary key value (auto-generated keys) from inserted queries using JDBC?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 5K+ Views

If you insert records into a table which contains auto-incremented column, using a Statement or, PreparedStatement objects.You can retrieve the values of that particular column, generated by them object using the getGeneratedKeys() method.ExampleLet us create a table with name sales in MySQL database, with one of the columns as auto-incremented, using CREATE statement as shown below −CREATE TABLE Sales(    ID INT PRIMARY KEY AUTO_INCREMENT,    ProductName VARCHAR (20),    CustomerName VARCHAR (20),    DispatchDate date,    DeliveryTime time,    Price INT,    Location VARCHAR(20) );Retrieving auto-generated values (PreparedStatement object)Following JDBC program inserts 3 records into the Sales table (created above) ...

Read More

Simulating final class in C++

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 578 Views

In Java or C#, we can use final classes. The final classes are special type of class. We cannot extend that class to create another class. In C++ there are no such direct way. Here we will see how to simulate the final class in C++.Here we will create one extra class called MakeFinalClass (its default constructor is private). This function is used to solve our purpose. The main Class MyClass can call the constructor of the MakeFinalClass as they are friend classes.One thing we have to notice, that the MakeFinalClass is also a virtual base class. We will make ...

Read More

MongoDB query to fetch elements between a range excluding both the numbers used to set range?

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 2K+ Views

Let’s say both the numbers are 50 and 60. You can use below syntax −db.yourCollectionName.find({yourFieldName: { $gt : 50 , $lt : 60 } } );If you want to include 50 and 60 also then use below syntax −db.yourCollectionName.find({yourFieldName: { $gte : 50 , $lte : 60 } } );Let us first create a collection with documents −> db.returnEverythingBetween50And60.insertOne({"Amount":55}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3c42eedc6604c74817cdb") } > db.returnEverythingBetween50And60.insertOne({"Amount":45}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3c432edc6604c74817cdc") } > db.returnEverythingBetween50And60.insertOne({"Amount":50}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd3c436edc6604c74817cdd") } > db.returnEverythingBetween50And60.insertOne({"Amount":59}); {    "acknowledged" : true, ...

Read More

Difference between set, multiset, unordered_set, unordered_multiset in C++\\n

Anvi Jain
Anvi Jain
Updated on 30-Jul-2019 416 Views

Here we will see what are the differences for set, multiset, unordered_set and unordered_multiset in C++. Let us see the properties of them using some example.SetThe properties of set are like belowStores data in sorted orderStores only unique valuesWe can insert or delete data, but cannot change the dataWe can remove more than one element using start and end iteratorWe can traverse using iteratorsSets are implemented using Binary Search TreeNow let us see an exampleExample#include #include using namespace std; main() {    int data[15] = {11, 55, 22, 66, 33, 22, 11, 44, 77, 88, 66, 99, 66, 23, 41};    set my_set;    for(int i = 0; i

Read More
Showing 181–190 of 427 articles
« Prev 1 17 18 19 20 21 43 Next »
Advertisements