Program for Christmas Tree in C

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

1K+ Views

Here we will see one interesting problem. In this problem, we will see how to print Christmas tree randomly. So the tree will be flickering like Christmas tree lights.To print a Christmas tree, we will print pyramids of various sizes just one beneath another. For the decorative leaves a random character is printed from a given list of characters. The height and randomness is adjustable.Here after generating a tree, the whole screen is cleared, then generate again, that’s why this is looking like flickering tree.Example#include #include #include #include #define REFRESH_RATE 40000 #define RANDOM_NESS 5 // The ... Read More

Make an Icon in the Action Bar with Notification Count in Android

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

210 Views

This example demonstrate about How to make an icon in the action bar with the number of notifications in AndroidStep 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.                                                                                     ... Read More

Updating Sub-Object in MongoDB

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

499 Views

You can use $set operator for this. Let us first create a collection with documents −> db.updateSubObjectDemo.insertOne( ...    { ... ...       "ClientId" : 100, ...       "ClientDetails" : { ...          "ClientFirstName" : "Adam" ...       } ...    } ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5cd31434b64f4b851c3a13e9") }Following is the query to display all documents from a collection with the help of find() method −> db.updateSubObjectDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cd31434b64f4b851c3a13e9"),    "ClientId" : 100,    "ClientDetails" : {   ... Read More

Push New Key Element into Subdocument of MongoDB

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

303 Views

You can use $set operator for this. Following is the syntax −db.yourCollectionName.update({"_id" : yourObjectId }, {$set: { "yourOuterFieldName.anyInnerFieldName": yourValue}});Let us first create a collection with documents −> db.pushNewKeyDemo.insertOne({"UserId":100, "UserDetails":{}}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda58f5b50a6c6dd317adbf") }Following is the query to display all documents from a collection with the help of find() method −> db.pushNewKeyDemo.find();This will produce the following output −{ "_id" : ObjectId("5cda58f5b50a6c6dd317adbf"), "UserId" : 100, "UserDetails" : { } }Following is the query to push new key element into subdocument of MongoDB −> db.pushNewKeyDemo.update({"_id" : ObjectId("5cda58f5b50a6c6dd317adbf")}, {$set: {    "UserDetails.UserName": "David Miller"}}); WriteResult({ "nMatched" : 1, ... Read More

Calculate Area of Circumcircle of an Equilateral Triangle

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

234 Views

A circumcircle is a circle that inscribes a regular polygon inside it. The triangle that is inscribed inside a circle is an equilateral triangle. Area of circumcircle of can be found using the following formula, Area of circumcircle = “(a * a * (丌 / 3))”Code Logic, The area of circumcircle of an equilateral triangle is found using the mathematical formula (a*a*(丌/3)). The value of 丌 in this code is coded as 3.14. The expression is evaluated into a float value.Example Live Demo#include #include int main(){    int a = 5;    float area;    float pie = 3.14; ... Read More

Remainder in C++

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

208 Views

Here we will see the functionality of remainder() method of C++. The remainder() function is used to compute the floating point remainder of numerator/denominator.So the remainder(x, y) will be like below.remainder(x, y) = x – rquote * yThe rquote is the value of x/y. This is rounded towards the nearest integral value. This function takes two arguments of type double, float, long double, and returns the remainder of the same type, that was given as argument. The first argument is numerator, and the second argument is the denominator.Example#include #include using namespace std; main() {    double x = ... Read More

wprintf and wscanf in C Library

Anvi Jain
Updated on 30-Jul-2019 22:30:26

2K+ Views

Here we will see the wprintf() and wscanf() functions in C. These are the printf() and scanf() functions for wide characters. These functions are present in the wchar.hThe wprintf() function is used to print the wide character to the standard output. The wide string format may contain the format specifiers which is starting with % sign, these are replaced by the values of variables which are passed to the wprintf().The syntax is like below −int wprintf (const wchar_t* format, ...);This function takes the format. This format is a pointer to a null terminated wide string, that will be written in ... Read More

Project Specific Array Field in a MongoDB Collection

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

240 Views

Let us first create a collection with documents −> db.projectionAnElementDemo.insertOne( ...    { ...       "CustomerId":100, ...       "CustomerDetails": [ ...          { ...             "CustomerName": "Chris", ...             "CustomerCountryName": "US" ...          }, ...          { ...             "CustomerName": "Robert", ...             "CustomerCountryName": "UK" ...          } ...       ] ...    } ... ); {    "acknowledged" : true,   ... Read More

Circular References and Memory Leakage in JavaScript

vineeth.mariserla
Updated on 30-Jul-2019 22:30:26

542 Views

Circular reference A circular reference is formed when two variables reference to each other there by giving each object a reference count of 1.In pure garbage collected system, a circular reference may not be a problem when the variables involved were have no references.In that scenario the declared variables will be garbage collected.In reference counting system neither of the objects will be destroyed, because the reference count cannot be zero.In hybrid system, where reference counting and garbage collection are used, memory leaks will occur because the system fails to identify circular references.ExampleThe following example shows a circular reference between javascript object ... Read More

Update Multiple Documents in MongoDB

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

438 Views

You need to use multi:true to update multiple documents. Let us first create a collection with documents −> db.multiUpdateDemo.insertOne({"ClientName":"John", "ClientAge":29}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda5bc0b50a6c6dd317adc8") } > db.multiUpdateDemo.insertOne({"ClientName":"Carol", "ClientAge":31}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda5bc1b50a6c6dd317adc9") } > db.multiUpdateDemo.insertOne({"ClientName":"John", "ClientAge":39}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda5bc3b50a6c6dd317adca") } > db.multiUpdateDemo.insertOne({"ClientName":"John", "ClientAge":41}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda5bc5b50a6c6dd317adcb") } > db.multiUpdateDemo.insertOne({"ClientName":"David", "ClientAge":35}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cda5bc6b50a6c6dd317adcc") }Following is the query to display all documents from a collection with the help of find() method −> db.multiUpdateDemo.find().pretty();This ... Read More

Advertisements