code-rag-bench/online-tutorials huggingface dataset:
lp - Unix, Linux Command

lp: submits files for printing or alters a pending job..
 lp -i request-ID [-c] [-m] [-p] [-s] [-w] [-d destination] [-f form-name] 
   [-H special-handling] [-n number] [-o options] [-p pagenumbers] 
   [-q priority-level] [-S character-set | print-wheel] [-t title] 
   [-T content-Type [-r]] [-y mode-list]
 
 lp -i request-ID [-c] [-m] [-p] [-s] [-w] [-d destination] [-f form-name] 
   [-H special-handling] [-n number] [-o options] [-p pagenumbers] 
   [-q priority-level] [-S character-set | print-wheel] [-t title] 
   [-T content-Type [-r]] [-y mode-list]
lp command arranges for the files specified by the Files parameter and their associated information (called a request) to be printed by a line printer. If you do not specify a value for the Files parameter, the lp command accepts standard input. The file name - (dash) represents standard input and can be specified on the command line in addition to files. The lp command sends the requests in the order specified. If the job is submitted to a local print queue, the lp command displays the following to standard output:
Job number is: nnn
where nnn is the assigned job number. To suppress the job number use the -s flag.

-H hh:mm
-H hold
-H immediate
-H restart
-H resume
Example-1:
To print the /etc/motd file on printer lp0 attached to device dlp0, enter:
# lp /etc/motd 
Example-2:
To print 30 copies of the /etc/motd file using a copy of the file, and to notify the user that the job is completed using mail, enter:
# lp  -c  -m  -n30  -dlp0:lpd0 /etc/motd 
Example-3:
To print the /etc/motd file using backend flags -f and -a, with a job title of blah, enter:
# lp  -t"blah"  -o -f  -o -a /etc/motd 
Example-4:
To queue the MyFile file and return the job number, enter:
# lp myfile
Example-5:
To queue the MyFile file and suppress the job number, enter:
# lp  -s myfile
Example-6:
To Print the double-sided legal document filename to printer myprinter.
# lp -d myprinter -o media=legal -o sides=two-sided-long-edge filename
Example-7:
Print document filename across 4 pages.
# lp -d myprinter -o scaling=200 filename
Example-8:
Print a text file with 12 characters per inch, 8 lines per inch, and a 1 inch left margin.
# lp -d myprinter -o cpi=12 -o lpi=8 -o page-left=72 filename

    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page
How to plot a Pandas multi-index dataFrame with all xticks (Matplotlib)?

To plot a Pandas multi-index data frame with all xticks, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create index value with 1000 smaples data.
Make a one-dimensional ndarray with axis labels.
Get the mean value of the series.
Plot g dataframe.
Set the ticks and ticklabel on the current axes
To display the figure, use show() method.
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

idx = pd.date_range("2020-01-01", periods=1000)
val = np.random.rand(1000)
s = pd.Series(val, idx)

g = s.groupby([s.index.year, s.index.month]).mean()

ax = g.plot()
ax.set_xticks(range(len(g)))
ax.set_xticklabels(["%s-%02d" % item for item in g.index.tolist()],
rotation=45, ha='center')

plt.show()
How to achieve parallel execution in TestNG?

We can achieve parallel execution with the help of TestNG. There is a parallel attribute in TestNG which is used for this implementation. The parallel execution in TestNG is associated with another attribute called thread-count.
The parallel attribute can have the values listed below −
Methods.
Methods.
Classes.
Classes.
Instances
Instances
Tests
Tests
Testng xml file.
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name = "Tutorialspoint Test" parallel ="tests" thread-count= ="5">
   <test name = "Test Cycle 1">
      <groups>
         <run>
            <include name = "Smoke"/>
         </run>
      </groups>
      <classes>
         <class name = "TestQA" />
      </classes>
   </test>
</suite>
The execution will trigger in parallel mode for tests with the thread count of 5.
How to remove a column from a data frame that contains same value in R?

If we have only one value in all of the rows of an R data frame then we might want to remove the whole column because the effect of that column will not make any sense in the data analysis objectives. Thus, instead of removing the column we can extract the columns that contains different values.
 Live Demo
set.seed(1001)
x1<-sample(0:1,20,replace=TRUE)
x2<-rep(5,20)
x3<-sample(0:5,20,replace=TRUE)
x4<-sample(1:10,20,replace=TRUE)
df1<-data.frame(x1,x2,x3,x4)
df1
  x1 x2 x3 x4
1  0 5  1  6
2  0 5  1  4
3  0 5  3  7
4  0 5  2  5
5  1 5  3  5
6  0 5  0  5
7  1 5  1  7
8  0 5  5  5
9  1 5  5  4
10 1 5  2  1
11 1 5  4  6
12 1 5  5  8
13 1 5  0  4
14 1 5  1  9
15 1 5  2  9
16 0 5  5  8
17 0 5  1  6
18 0 5  1  4
19 1 5  3  7
20 0 5  4  2
Removing column that contains 5 −
df1[,c(1,3,4)]
  x1 x3 x4
1  0 1  6
2  0 1  4
3  0 3  7
4  0 2  5
5  1 3  5
6  0 0  5
7  1 1  7
8  0 5  5
9  1 5  4
10 1 2  1
11 1 4  6
12 1 5  8
13 1 0  4
14 1 1  9
15 1 2  9
16 0 5  8
17 0 1  6
18 0 1  4
19 1 3  7
20 0 4  2
Let’s have a look at another example −
 Live Demo
y1<-sample(1:3,20,replace=TRUE)
y2<-sample(1:5,20,replace=TRUE)
y3<-rep(1,20)
y4<-sample(1:2,20,replace=TRUE)
y5<-sample(1:6,20,replace=TRUE)
y6<-sample(1:8,20,replace=TRUE)
df2<-data.frame(y1,y2,y3,y4,y5,y6)
df2
  y1 y2 y3 y4 y5 y6
1  3 2   1 1   3 1
2  2 2   1 2   3 5
3  2 5   1 1   2 6
4  2 4   1 1   4 6
5  1 1   1 1   1 4
6  1 2   1 1   3 6
7  1 3   1 2   5 2
8  3 2   1 2   5 1
9  1 3   1 1   3 6
10 3 1   1 2   6 1
11 3 3   1 2   4 2
12 2 4   1 2   5 5
13 3 5   1 2   4 7
14 3 2   1 1   1 5
15 3 1   1 2   3 1
16 2 4   1 2   5 5
17 2 3   1 2   3 6
18 3 4   1 1   1 6
19 1 1   1 1   6 5
20 1 3   1 1   6 1
Removing column 3 from data frame df2 −
df2[,c(1,2,4,5,6)]
  y1 y2 y4 y5 y6
1  3 2   1 3   1
2  2 2   2 3   5
3  2 5   1 2   6
4  2 4   1 4   6
5  1 1   1 1   4
6  1 2   1 3   6
7  1 3   2 5   2
8  3 2   2 5   1
9  1 3   1 3   6
10 3 1   2 6   1
11 3 3   2 4   2
12 2 4   2 5   5
13 3 5   2 4   7
14 3 2   1 1   5
15 3 1   2 3   1
16 2 4   2 5   5
17 2 3   2 3   6
18 3 4   1 1   6
19 1 1   1 6   5
20 1 3   1 6   1
fgets() and gets() in C language - GeeksforGeeks

15 Nov, 2017
For reading a string value with spaces, we can use either gets() or fgets() in C programming language. Here, we will see what is the difference between gets() and fgets().
fgets()
It reads a line from the specified stream and stores it into the string pointed to by str. It stops when either (n-1) characters are read, the newline character is read, or the end-of-file is reached, whichever comes first.Syntax :
char *fgets(char *str, int n, FILE *stream)
str : Pointer to an array of chars where the string read is copied.
n : Maximum number of characters to be copied into str 
(including the terminating null-character).
*stream : Pointer to a FILE object that identifies an input stream.
stdin can be used as argument to read from the standard input.

returns : the function returns str

It follow some parameter such as Maximum length, buffer, input device reference.
It is safe to use because it checks the array bound.
It keep on reading until new line character encountered or maximum limit of character array.
Example : Let’s say the maximum number of characters are 15 and input length is greater than 15 but still fgets() will read only 15 character and print it.
// C program to illustrate// fgets()#include <stdio.h>#define MAX 15int main(){    char buf[MAX];    fgets(buf, MAX, stdin);    printf("string is: %s\n", buf);      return 0;}
Since fgets() reads input from user, we need to provide input during runtime.
Input:
Hello and welcome to GeeksforGeeks

Output:
Hello and welc

gets()
Reads characters from the standard input (stdin) and stores them as a C string into str until a newline character or the end-of-file is reached.Syntax:
char * gets ( char * str );
str :Pointer to a block of memory (array of char) 
where the string read is copied as a C string.
returns : the function returns str
 
It is not safe to use because it does not check the array bound.
It is used to read string from user until newline character not encountered.
Example : Suppose we have a character array of 15 characters and input is greater than 15 characters, gets() will read all these characters and store them into variable.Since, gets() do not check the maximum limit of input characters, so at any time compiler may return buffer overflow error.
// C program to illustrate// gets()#include <stdio.h>#define MAX 15  int main(){    char buf[MAX];      printf("Enter a string: ");    gets(buf);    printf("string is: %s\n", buf);      return 0;}
Since gets() reads input from user, we need to provide input during runtime.
Input:
Hello and welcome to GeeksforGeeks

Output:
Hello and welcome to GeeksforGeeks

C-File Handling
C Language
Misc
Misc
Misc
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
fork() in C
Command line arguments in C/C++
Function Pointer in C
Substring in C++
Structures in C
Top 10 algorithms in Interview Questions
vector::push_back() and vector::pop_back() in C++ STL
Overview of Data Structures | Set 1 (Linear Data Structures)
How to write Regular Expressions?
Minimax Algorithm in Game Theory | Set 3 (Tic-Tac-Toe AI - Finding optimal move)
How to draw a rectangle on HTML5 Canvas?

The HTML5 <canvas> tag is used to draw graphics, animations, etc. using scripting. It is a new tag introduced in HTML5. The canvas element has a DOM method called getContext, which obtains rendering context and its drawing functions. This function takes one parameter, the type of context 2d.
To draw a rectangle with HTML5 canvas, use the fillRect(x, y, width, height) method:
You can try to run the following code to learn how to draw a rectangle with HTML5 Canvas
<!DOCTYPE html>
<html>
   <head>
      <title>HTML5 Canvas Tag</title>
   </head>
   
   <body>
      <canvas id="newCanvas" width="200" height="100" style="border:1px
         solid #000000;"></canvas>
      <script>
         var c = document.getElementById('newCanvas');
         var ctx = c.getContext('2d');
         ctx.fillStyle = '#7cce2b';
         ctx.fillRect(0,0,300,100);
      </script>
   </body>
</html>
Java Program for check if a given number is Fibonacci number?

Following is the Java program to check if a given number is Fibonacci −
 Live Demo
public class Demo{
   static boolean perfect_square_check(int val){
      int s = (int) Math.sqrt(val);
      return (s*s == val);
   }
   static boolean fibonacci_num_check(int n){
      return perfect_square_check(5*n*n + 4) || perfect_square_check(5*n*n - 4);
   }
   public static void main(String[] args){
      for (int i = 6; i <= 17; i++)
      System.out.println(fibonacci_num_check(i) ? i + " is a Fibonacci number" :
      i + " is a not Fibonacci number");
   }
}
6 is a not Fibonacci number
7 is a not Fibonacci number
8 is a Fibonacci number
9 is a not Fibonacci number
10 is a not Fibonacci number
11 is a not Fibonacci number
12 is a not Fibonacci number
13 is a Fibonacci number
14 is a not Fibonacci number
15 is a not Fibonacci number
16 is a not Fibonacci number
17 is a not Fibonacci number
A class named Demo defines a static Boolean function that takes in an integer value as parameter. It checks the square root of the value and assigns it to another value. If the product of square root multiplied by square root is equal to the value passed, then it is returned.
Next, another Boolean static function is defined that calls the previous function. In the main function, the starting number, and the ending number are iterated through, and relevant message is printed as well as checking whether every number is a Fibonacci number or not.
C++ Queue Library - size() Function

The C++ function std::priority_queue::size() returns the total number of elements present in the priority_queue.
Following is the declaration for std::priority_queue::size() function form std::queue header.
size_type size() const;

None
Returns the total number of elements present in the priority_queue.
This member function never throws exception.
Constant i.e. O(1)
The following example shows the usage of std::priority_queue::size() function.
#include <iostream>
#include <queue>

using namespace std;

int main(void) {
   priority_queue<int> q;

   cout << "Initial size of queue = " << q.size() << endl;

   for (int i = 0; i < 5; ++i)
      q.push(i + 1);

   cout << "After push opration size of queue = " << q.size() << endl;

   return 0;
}
Let us compile and run the above program, this will produce the following result −
Initial size of queue = 0
After push opration size of queue = 5

 Print
 Add Notes
 Bookmark this page
Explain different types of expressions in C program

An expression is a combination of operators and operands which reduces to a single value. An operation is performed on a data item which is called an operand. An operator indicates an operation to be performed on data.
For example, z = 3+2*1
z = 5
Primary expressions − It is an operand which can be a name, a constant or any parenthesized expression. Example − c = a+ (5*b);
Primary expressions − It is an operand which can be a name, a constant or any parenthesized expression. Example − c = a+ (5*b);
Postfix expressions − In a postfix expression, the operator will be after the operand. Example − ab+
Postfix expressions − In a postfix expression, the operator will be after the operand. Example − ab+
Prefix expressions − n a prefix expression, the operator is before the operand. Example − +ab
Prefix expressions − n a prefix expression, the operator is before the operand. Example − +ab
Unary expression − It contains one operator and one operand. Example − a++, --b
Unary expression − It contains one operator and one operand. Example − a++, --b
Binary expression − t contains two operands and one operator. Example − a+b, c-d
Binary expression − t contains two operands and one operator. Example − a+b, c-d
Ternary expression − It contains three operands and one operator. For Example, Exp1? Exp2 − Exp3. If Exp1 is true, Exp2 is executed. Otherwise, Exp3 is executed.
Ternary expression − It contains three operands and one operator. For Example, Exp1? Exp2 − Exp3. If Exp1 is true, Exp2 is executed. Otherwise, Exp3 is executed.
Given below is the C program explaining the different types of expressions in C language −
 Live Demo
#include<stdio.h>
int main(){
   int a,b,c,d,z;
   int p,q,r,s,t,u,v;
   printf("enter the values of a,b,c,d:\n");
   scanf("%d%d%d%d",&a,&b,&c,&d);
   r=a++;
   s=--b;
   t=a+b;
   u=c-d;
   v=a+(5*b);
   z = (5>3) ? 1:0;
   printf("unaryexpression=%d\nunary expression=%d\n Binary
   expression=%d\nBinary expression=%d\nPrimary expression=%d\nTernary expression=%d\n",r,s,t,u,v,z);
}
You will see the following output −
enter the values of a,b,c,d:
2 3 4 6
unary expression=2
unary expression=2
Binary expression=5
Binary expression=-2
Primary expression=13
Ternary expression=1
Bootstrap dropdown class

Dropdown menus are toggleable, contextual menus for displaying links in a list format. To use a drop-down, just wrap the drop-down menu within the class .dropdown.
You can try to run the following code to implement the dropdown class in Bootstrap
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Example</title>
      <link href = "/bootstrap/css/bootstrap.min.css" rel = "stylesheet">
      <script src = "/scripts/jquery.min.js"></script>
      <script src = "/bootstrap/js/bootstrap.min.js"></script>
   </head>
   <body>
      <div class = "dropdown">
         <button type = "button" class = "btn dropdown-toggle" id = "dropdownMenu1" data-toggle = "dropdown">
            Subjects
            <span class = "caret"></span>
         </button>
         <ul class = "dropdown-menu" role = "menu" aria-labelledby = "dropdownMenu1">
            <li role = "presentation">
               <a role = "menuitem" tabindex = "-1" href = "#">Java</a>
            </li>
            <li role = "presentation">
               <a role = "menuitem" tabindex = "-1" href = "#">Data Mining</a>
            </li>
            <li role = "presentation">
               <a role = "menuitem" tabindex = "-1" href = "#">
                  C++
               </a>
            </li>
            <li role = "presentation" class = "divider"></li>
            <li role = "presentation">
               <a role = "menuitem" tabindex = "-1" href = "#">Separated link</a>
            </li>
         </ul>
      </div>
   </body>
</html>
C++ Vector Library - cbegin() Function

The C++ function std::vector::cbegin() returns a constant random access iterator which points to the beginning of the vector.
Iterator obtained by this member function can be used to iterate container but cannot be used to modify the content of object to which it is pointing even if object itself is not constant.
Following is the declaration for std::vector::cbegin() function form std::vector header.
const_iterator cbegin() const noexcept;

None
Returns a constant random access iterator which points to the beginning of the vector.
This member function never throws exception.
Constant i.e. O(1)
The following example shows the usage of std::vector::cbegin() function.
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
   auto ilist = {1, 2, 3, 4, 5};
   vector<int> v(ilist);

   for (auto it = v.cbegin(); it != v.end(); ++it)
      cout << *it << endl;

   return 0;
}
Let us compile and run the above program, this will produce the following result −
1
2
3
4
5

 Print
 Add Notes
 Bookmark this page
Swift - While Loop

A while loop statement in Swift 4 programming language repeatedly executes a target statement as long as a given condition is true.
The syntax of a while loop in Swift 4 programming language is −
while condition {
   statement(s)
}

Here statement(s) may be a single statement or a block of statements. The condition may be any expression. The loop iterates while the condition is true. When the condition becomes false, the program control passes to the line immediately following the loop.
The number 0, the strings '0' and "", the empty list(), and undef are all false in a Boolean context and all other values are true. Negation of a true value by ! or not returns a special false value.
The key point of a while loop is that the loop might not ever run. When the condition is tested and the result is false, the loop body will be skipped and the first statement after the while loop will be executed.
var index = 10

while index < 20 {
   print( "Value of index is \(index)")
   index = index + 1
}
Here we are using comparison operator < to compare the value of the variable index against 20. While the value of index is less than 20, the while loop continues executing a block of code next to it and as soon as the value of index becomes equal to 20, it comes out. When executed, the above code produces the following result −
Value of index is 10
Value of index is 11
Value of index is 12
Value of index is 13
Value of index is 14
Value of index is 15
Value of index is 16
Value of index is 17
Value of index is 18
Value of index is 19


    38 Lectures 
     1 hours 

 Ashish Sharma

    13 Lectures 
     2 hours 

 Three Millennials

    7 Lectures 
     1 hours 

 Three Millennials

    22 Lectures 
     1 hours 

 Frahaan Hussain

    12 Lectures 
     39 mins

 Devasena Rajendran

    40 Lectures 
     2.5 hours 

 Grant Klimaytys
 Print
 Add Notes
 Bookmark this page
Tryit Editor v3.7

Tryit: One font should be the boss
Type.GetMember() Method in C#

The Type.GetMember() method in C# is used to get the specified members of the current Type.
Following is the syntax −
public System.Reflection.MemberInfo[] GetMember (string name);
public virtual System.Reflection.MemberInfo[] GetMember (string name, System.Reflection.BindingFlags bindingAttr);
Let us now see an example to implement the Type.GetMember() method −
using System;
using System.Reflection;
public class Demo {
   public static void Main(){
      Type type = typeof(Subject);
      try {
         FieldInfo fieldInfo = type.GetField("SubName");
         MemberInfo[] info = type.GetMember("SubName");
         Console.Write("Members = ");
         for (int i = 0; i < info.Length; i++)
            Console.WriteLine(" {0}", info[i]);
         Console.WriteLine("FieldInfo = {0}", fieldInfo);
      }
      catch (ArgumentNullException e){
         Console.Write("{0}", e.GetType(), e.Message);
      }
   }
}
public class Subject{
   public string SubName = "Science";
}
This will produce the following output −
Members = System.String SubName
FieldInfo = System.String SubName
Let us now see another example to implement the Type.GetMember(String, BindingFlags) method −
using System;
using System.Reflection;
public class Demo {
   public static void Main(){
      Type type = typeof(Subject);
      try {
         FieldInfo fieldInfo = type.GetField("SubName");
         MemberInfo[] info = type.GetMember("SubName", BindingFlags.Public | BindingFlags.Instance);
         Console.Write("Members = ");
         for (int i = 0; i < info.Length; i++)
            Console.WriteLine(" {0}", info[i]);
         Console.WriteLine("FieldInfo = {0}", fieldInfo);
      }
      catch (ArgumentNullException e){
         Console.Write("{0}", e.GetType(), e.Message);
      }
   }
}
public class Subject{
   public string SubName = "Science";
}
This will produce the following output −
Members = System.String SubName
FieldInfo = System.String SubName
Data Structure and Algorithms - AVL Trees

What if the input to binary search tree comes in a sorted (ascending or descending) manner? It will then look like this −
It is observed that BST's worst-case performance is closest to linear search algorithms, that is Ο(n). In real-time data, we cannot predict data pattern and their frequencies. So, a need arises to balance out the existing BST.
Named after their inventor Adelson, Velski & Landis, AVL trees are height balancing binary search tree. AVL tree checks the height of the left and the right sub-trees and assures that the difference is not more than 1. This difference is called the Balance Factor.
Here we see that the first tree is balanced and the next two trees are not balanced −
In the second tree, the left subtree of C has height 2 and the right subtree has height 0, so the difference is 2. In the third tree, the right subtree of A has height 2 and the left is missing, so it is 0, and the difference is 2 again. AVL tree permits difference (balance factor) to be only 1.
BalanceFactor = height(left-sutree) − height(right-sutree)

If the difference in the height of left and right sub-trees is more than 1, the tree is balanced using some rotation techniques.
To balance itself, an AVL tree may perform the following four kinds of rotations −
Left rotation
Right rotation
Left-Right rotation
Right-Left rotation
The first two rotations are single rotations and the next two rotations are double rotations. To have an unbalanced tree, we at least need a tree of height 2. With this simple tree, let's understand them one by one.
If a tree becomes unbalanced, when a node is inserted into the right subtree of the right subtree, then we perform a single left rotation −
In our example, node A has become unbalanced as a node is inserted in the right subtree of A's right subtree. We perform the left rotation by making A the left-subtree of B.
AVL tree may become unbalanced, if a node is inserted in the left subtree of the left subtree. The tree then needs a right rotation.
As depicted, the unbalanced node becomes the right child of its left child by performing a right rotation.
Double rotations are slightly complex version of already explained versions of rotations. To understand them better, we should take note of each action performed while rotation. Let's first check how to perform Left-Right rotation. A left-right rotation is a combination of left rotation followed by right rotation.
The second type of double rotation is Right-Left Rotation. It is a combination of right rotation followed by left rotation.

    42 Lectures 
     1.5 hours 

 Ravi Kiran

    141 Lectures 
     13 hours 

 Arnab Chakraborty

    26 Lectures 
     8.5 hours 

 Parth Panjabi

    65 Lectures 
     6 hours 

 Arnab Chakraborty

    75 Lectures 
     13 hours 

 Eduonix Learning Solutions

    64 Lectures 
     10.5 hours 

 Eduonix Learning Solutions
 Print
 Add Notes
 Bookmark this page
Basic SQL Commands - GeeksforGeeks

26 Apr, 2021
QUESTION: Consider the following table ITEM given below, write the commands in SQL for 1 – 10 and output for 11 – 20
                                                                                       TABLE: ITEM
Write the SQL commands for 1. to 10.
1. To display the name of the item and cost of those items which were purchased after ‘2010-08-05’.
Select Item_Name,Cost from ITEM where DOP>"2010-08-05";
2. To display information of those items whose purchase quantity is more than 10 arranged by Date of Purchase.
Select * from ITEM where Purchase_Qty>10 ORDER BY DOP;
3. To display the average cost price of the items of ‘JKL’ Company.
Select avg(cost) from ITEM where Company="JKL";
4. To display all the information of those items whose name starts with letter ‘M’.
Select * from ITEM where Item_Name like "M%";
5. To display maximum cost price of the items which contain letter ‘J’ in the company name.
Select max(Cost) from ITEM where Company like '%J%;
6. To display all details of items whose purchase quantity is more than 5 arranged in decreasing order of Date of Purchase.
Select * from ITEM where Purchase_Qty>5 order by DOP desc;
7. To display S_No, Item_Name and cost of all those items where Item_Name has the letter ‘o’ in second position.
Select S_No,Item_Name,Cost from ITEM where instr(Item_Name,'o')=2;
8. To display Company, minimum of Purchase_Qty grouped by the month of purchase.
Select Company,min(Purchase_Qty) from ITEM group by month(DOP);
9. To show the structure of the table ITEM.
Desc ITEM;
10. To set Purchase_Qty as 31 of ‘JKL’ company. 
Update ITEM set Purchase_Qty=31 where Company='JKL'; 
Write the Output for the following SQL queries 11 – 20.
11. Select count(*) from item where cost>6000 and Purchase_Qty<25;       OUTPUT:
12. Select max(Purchase_Qty) from item where cost<5000;       OUTPUT:
13. Select avg(Cost) from item where Purchase_Qty>25;      OUTPUT:
14. Select cost+200 as ‘Selling_Price’ from item where Item_Name=’Scanner’;       OUTPUT:
15. Select S_No,Item_Name,Purchase_Qty from ITEM where Purchase_Qty>=10;      OUTPUT:
16. Select Ucase(Item_Name), Lcase(Company) from ITEM;     OUTPUT:
17. Select S_No, DOP from ITEM where month(DOP)=8;      OUTPUT:
18. Select avg(Cost), Max(Purchase_Qty) from ITEM;       OUTPUT:
19. Select Item_Name from ITEM where Item_Name like “%e%”;       OUTPUT:
20. Select * from ITEM where length(Item_Name)=3;      OUTPUT:
DBMS-SQL
DBMS
SQL
DBMS
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Types of Functional dependencies in DBMS
Introduction of Relational Algebra in DBMS
What is Temporary Table in SQL?
Two Phase Locking Protocol
KDD Process in Data Mining
SQL | DDL, DQL, DML, DCL and TCL Commands
How to find Nth highest salary from a table
SQL | ALTER (RENAME)
How to Update Multiple Columns in Single Update Statement in SQL?
MySQL | Group_CONCAT() Function
Find Nth term of the series 0, 2, 4, 8, 12, 18... - GeeksforGeeks

15 Mar, 2021
Given a number N. The task is to write a program to find the Nth term in the below series:  
0, 2, 4, 8, 12, 18...
Examples:  
Input: 3
Output: 4
For N = 3
Nth term = ( 3 + ( 3 - 1 ) * 3 ) / 2
         = 4
Input: 5 
Output: 12
 
On observing carefully, the Nth term in the above series can be generalized as:  
Nth term = ( N + ( N - 1 ) * N ) / 2
Below is the implementation of the above approach: 
C++
Java
Python 3
C#
PHP
Javascript
// CPP program to find N-th term of the series:// 0, 2, 4, 8, 12, 18...#include <iostream>using namespace std; // Calculate Nth term of seriesint nthTerm(int N){    return (N + N * (N - 1)) / 2;} // Driver Functionint main(){    int N = 5;     cout << nthTerm(N);     return 0;}
// Java program to find N-th term of the series:// 0, 2, 4, 8, 12, 18...import java.io.*; // Main class for main methodclass GFG {    public static int nthTerm(int N)    {        // By using above formula        return (N + (N - 1) * N) / 2;    }        // Driver code    public static void main(String[] args)    {        int N = 5; // 5th term is 12                     System.out.println(nthTerm(N));    }}
# Python 3 program to find N-th term of the series:# 0, 2, 4, 8, 12, 18. # Calculate Nth term of seriesdef nthTerm(N) :         return (N + N * (N - 1)) // 2 # Driver Codeif __name__ == "__main__" :     N = 5     print(nthTerm(N)) # This code is contributed by ANKITRAI1
// C# program to find N-th term of the series:// 0, 2, 4, 8, 12, 18...using System;class gfg{      // Calculate Nth term of series    public int nthTerm(int N)    {        int n = ((N + N * (N - 1)) / 2);        return n;    }     //Driver program    static void Main(string[] args)    {        gfg p = new gfg();        int a = p.nthTerm(5);        Console.WriteLine(a);        Console.Read();    }}//This code is contributed by SoumikMondal
<?php// PHP program to find// N-th term of the series:// 0, 2, 4, 8, 12, 18... // Calculate Nth term of seriesfunction nthTerm($N){    return (int)(($N + $N *                 ($N - 1)) / 2);} // Driver Code$N = 5; echo nthTerm($N); // This code is contributed by mits?>
<script> // JavaScript program to find N-th term of the series:// 0, 2, 4, 8, 12, 18... // Calculate Nth term of seriesfunction nthTerm(N){    return parseInt((N + N * (N - 1)) / 2);}// Driver Function     let N = 5;    document.write(nthTerm(N));     // This code contributed by Rajput-Ji </script>
12
 
Time Complexity: O(1) 
Mithun Kumar
ankthon
SoumikMondal
Rajput-Ji
C++
Java
Pattern Searching
Java
Pattern Searching
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Inheritance in C++
Map in C++ Standard Template Library (STL)
C++ Classes and Objects
Bitwise Operators in C/C++
Operator Overloading in C++
For-each loop in Java
Arrays.sort() in Java with examples
Reverse a string in Java
Initialize an ArrayList in Java
Object Oriented Programming (OOPs) Concept in Java
Tryit Editor v3.7

Tryit: Another text shadow effect
Gaussian Filter Generation in C++

As we know the Gaussian Filtering is very much useful applied in the field of image processing. It is used to reduce the noise of an image. In this section we will see how to generate a 2D Gaussian Kernel. Gaussian Distribution for generating 2D kernel is as follows.
G(x,y)=12Πσ2ex2+y22σ2
Let us see the following implementation to get better understanding −
 Live Demo
#include <cmath>
#include <iomanip>
#include <iostream>
#define PI 3.1415
using namespace std;
void calc_filter(double kernel[][5]) {
   double sigma = 1.0;
   double p, q = 2.0 * sigma * sigma;
   double sum = 0.0;
   for (int x = -2; x <= 2; x++) {
      for (int y = -2; y <= 2; y++) {
         p = sqrt(x * x + y * y);
         kernel[x + 2][y + 2] = (exp(-(p * p) / q)) / (PI * q);
         sum += kernel[x + 2][y + 2];
      }
   }
   for (int i = 0; i < 5; i++)
      for (int j = 0; j < 5; j++)
         kernel[i][j] /= sum;
}
int main() {
   double kernel[5][5];
   calc_filter(kernel);
   for (int i = 0; i < 5; ++i) {
      for (int j = 0; j < 5; ++j)
         cout << kernel[i][j] << " ";
      cout << endl;
   }
}
0.00296902 0.0133062 0.0219382 0.0133062 0.00296902
0.0133062 0.0596343 0.0983203 0.0596343 0.0133062
0.0219382 0.0983203 0.162103 0.0983203 0.0219382
0.0133062 0.0596343 0.0983203 0.0596343 0.0133062
0.00296902 0.0133062 0.0219382 0.0133062 0.00296902
Python | Pretty Print a dictionary with dictionary value - GeeksforGeeks

28 Aug, 2019
This article just provides a quick way to pretty print a dictionary which has dictionary as values. This is required many times now days as the advent of NoSQL databases. Lets code a way to perform this particular task.
Method : Using loopsWe just loop through each dictionary element and it’s corresponding values using brute manner of loops.
# Python3 code to demonstrate working of# Pretty Print a dictionary with dictionary value# Using loops  # initializing dictionarytest_dict = {'gfg' : {'rate' : 5, 'remark' : 'good'}, 'cs' : {'rate' : 3}}  # printing original dictionaryprint("The original dictionary is : " +  str(test_dict))  # using loops to Pretty Printprint("The Pretty Print dictionary is : ")for sub in test_dict:    print (sub)    for sub_nest in test_dict[sub]:        print (sub_nest, ':', test_dict[sub][sub_nest])
The original dictionary is : {'gfg': {'remark': 'good', 'rate': 5}, 'cs': {'rate': 3}}
The Pretty Print dictionary is : 
gfg
remark : good
rate : 5
cs
rate : 3

Python list-programs
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
How to drop one or multiple columns in Pandas Dataframe
Python Classes and Objects
Python | os.path.join() method
Python | Pandas dataframe.groupby()
Create a directory in Python
Defaultdict in Python
Python | Get unique values from a list
C# | How to change the WindowWidth of the Console - GeeksforGeeks

28 Jan, 2019
Given the normal Console in C#, the task is to change the WindowWidth of the Console.
Approach: This can be done using the WindowWidth property in the Console class of the System package in C#. The WindowWidth refers to the Width of the console window measured in columns.
Program 1: Getting the value of WindowWidth
// C# program to illustrate the// Console.WindowWidth Propertyusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;  namespace GFG {  class Program {      static void Main(string[] args)    {          // Get the WindowWidth        Console.WriteLine("Current WindowWidth: {0}",                                Console.WindowWidth);    }}}
Output:
Program 2: Setting the value of WindowWidth
// C# program to illustrate the// Console.WindowWidth Propertyusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;  namespace GFG {  class Program {      static void Main(string[] args)    {          // Get the WindowWidth        Console.WriteLine("Current WindowWidth: {0}",                                Console.WindowWidth);          // Set the WindowWidth        Console.WindowWidth = 150;          // Get the WindowWidth        Console.Write("Current WindowWidth: {0}",                            Console.WindowWidth);    }}}
Output:
Note: See the Width of the Window in both the images.
CSharp-Console-Class
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C# | Delegates
C# | Abstract Classes
Extension Method in C#
Difference between Ref and Out keywords in C#
C# | Replace() Method
C# | Class and Object
C# | Constructors
C# | String.IndexOf( ) Method | Set - 1
Introduction to .NET Framework
C# | Data Types
How to convert a super class variable into a sub class type in Java

Inheritance is a relation between two classes where one class inherits the properties of the other class. This relation can be defined using the extends keyword as −
public class A extends B{}
public class A extends B{
The class which inherits the properties is known as sub class or, child class and the class whose properties are inherited is super class or, parent class.
In inheritance a copy of super class members is created in the sub class object. Therefore, using the sub class object you can access the members of the both classes.
You can try to convert the super class variable to the sub class type by simply using the cast operator. But, first of all you need to create the super class reference using the sub class object and then, convert this (super) reference type to sub class type using the cast operator.
Live Demo
class Person{
   public String name;
   public int age;
   public Person(String name, int age){
      this.name = name;
      this.age = age;
   }
   public void displayPerson() {
      System.out.println("Data of the Person class: ");
      System.out.println("Name: "+this.name);
      System.out.println("Age: "+this.age);
   }
}
public class Sample extends Person {
   public String branch;
   public int Student_id;

   public Sample(String name, int age, String branch, int Student_id){
   super(name, age);
      this.branch = branch;
      this.Student_id = Student_id;
   }
   public void displayStudent() {
      System.out.println("Data of the Student class: ");
      System.out.println("Name: "+super.name);
      System.out.println("Age: "+super.age);
      System.out.println("Branch: "+this.branch);
      System.out.println("Student ID: "+this.Student_id);
   }
   public static void main(String[] args) {        
      Person person = new Sample("Krishna", 20, "IT", 1256);      
      //Converting super class variable to sub class type
      Sample obj = (Sample) person;      
      obj.displayPerson();
      obj.displayStudent();
   }
}
Data of the Person class:
Name: Krishna
Age: 20
Data of the Student class:
Name: Krishna
Age: 20
Branch: IT
Student ID: 1256
Live Demo
class Super{
   public Super(){
      System.out.println("Constructor of the super class");
   }
   public void superMethod() {
      System.out.println("Method of the super class ");
   }
}
public class Test extends Super {
   public Test(){
      System.out.println("Constructor of the sub class");
   }
   public void subMethod() {
      System.out.println("Method of the sub class ");
   }
   public static void main(String[] args) {        
      Super sup = new Test();      
      //Converting super class variable to sub class type
      Test obj = (Test) sup;      
      obj.superMethod();
      obj.subMethod();
   }
}
Constructor of the super class
Constructor of the sub class
Method of the super class
Method of the sub class
What are integer literals in C#?

An integer literal can be a decimal, or hexadecimal constant. A prefix specifies the base or radix: 0x or 0X for hexadecimal, and there is no prefix id for decimal. It can also have a suffix that is a combination of U and L, for unsigned and long, respectively.
Here are some of the examples of integer literals −
200 // int
90u// unsigned int
Let’s use the above literal while declaring and initializing a variable −
// int
int a =200;
We will now print the values −
 Live Demo
using System;

namespace Demo {

   class Program {

      static void Main(string[] args) {

         // integer literal
         int a = 200;
         Console.WriteLine(a);

      }
   }
}
200
How to use an HTML button to call a JavaScript function?

The simplest way to use an HTML button to call a JavaScript function is shown below −
<input id = "Double Click here" type = "button" value = "clickme" ondblclick = "myFunction();" />
You can also use the following by adding to the DOM property −
document.getElementById("Double Click here ").ondblclick = myFunction;
How to do recursive SELECT query in MySQL?

For recursive select, let us see an example. First, we will create a table. The CREATE command is used to create a table.
mysql> CREATE table tblSelectDemo
   - > (
   - > id int,
   - > name varchar(100)
   - > );
Query OK, 0 rows affected (0.61 sec)
Now, we will insert records in the table “tblSelectDemo”.
mysql> insert into tblSelectDemo values(1,'John');
Query OK, 1 row affected (0.10 sec)

mysql> insert into tblSelectDemo values(2,'Carol');
Query OK, 1 row affected (0.09 sec)

mysql> insert into tblSelectDemo values(3,'Smith');
Query OK, 1 row affected (0.17 sec)

mysql> insert into tblSelectDemo values(4,'David');
Query OK, 1 row affected (0.15 sec)

mysql> insert into tblSelectDemo values(5,'Bob');
Query OK, 1 row affected (0.18 sec)
To display all records.
mysql> SELECT *from tblSelectDemo;
Here is the output.
+------+-------+
| id   | name  |
+------+-------+
|    1 | John  |
|    2 | Carol |
|    3 | Smith |
|    4 | David |
|    5 | Bob   |
+------+-------+
6 rows in set (0.00 sec)

The following is the syntax for recursive SELECT.
mysql> SELECT var1.id as id, @sessionName:= var1.Name as NameofStudent
   - > from (select * from tblSelectDemo order by id desc) var1
   - > join
   - > (select @sessionName:= 4)tmp
   - > where var1.id = @sessionName;
Here is the output.
+------+----------------+
| id   | NameofStudent  |
+------+----------------+
|    4 | David          |
+------+----------------+
1 row in set (0.00 sec)
Booleans Class in Java

The Boolean class wraps a value of the primitive type boolean in an object. An object of type Boolean contains a single field whose type is boolean.
Following are the fields of the Boolean class −
static Boolean FALSE − This is the Boolean object corresponding to the primitive value false.
static Boolean TRUE − This is the Boolean object corresponding to the primitive value true.
static Class<Boolean> TYPE − This is the Class object representing the primitive type boolean.
Following are some of the methods of the Boolean class−
Let us now see an example −
 Live Demo
import java.lang.*;
public class Demo {
   public static void main(String[] args){
      Boolean val1, val2;
      val1 = new Boolean(true);
      val2 = new Boolean(true);
      boolean res = val1.equals(val2);
      System.out.println("Are both the Boolean values equal? = "+res);
   }
}
Are both the Boolean values equal? = true
Let us now see another example−
 Live Demo
import java.lang.*;
public class Demo {
   public static void main(String[] args){
      Boolean val1, val2;
      val1 = new Boolean(false);
      val2 = new Boolean(true);
      System.out.println("Value1 = "+val1);
      System.out.println("Value2 = "+val2);
      System.out.println("HashCode Value1 = "+val1.hashCode());
      System.out.println("HashCode Value2 = "+val2.hashCode());
      boolean res = val1.equals(val2);
      System.out.println("Are both the Boolean values equal? = "+res);
   }
}
Value1 = false
Value2 = true
HashCode Value1 = 1237
HashCode Value2 = 1231
Are both the Boolean values equal? = false
D3.js - Delimiter-Separated Values API

A delimiter is a sequence of one or more characters used to specify the boundary between separate, independent regions in plain text or other data. A field delimiter is a sequence of comma-separated values. Well, delimiter-separated values are comma separated values (CSV) or tab-separated values (TSV). This chapter explains the delimiter separated values in detail.
We can easily load the API using the following syntax.
<script src = "https://d3js.org/d3-dsv.v1.min.js"></script>
<script>
   var data = d3.csvParse(string);
</script>
Following are the various API methods of the delimiter-separated values.
d3.csvParse(string[, row])
d3.csvParseRows(string[, row])
d3.csvFormat(rows[, columns])
d3.csvFormatRows(rows)
d3.tsvParse(string[, row])
d3.tsvParseRows(string[, row])
d3.tsvFormat(rows[, columns])
d3.tsvFormatRows(rows)
Let us go through each of these API methods in detail.
This method is used to parse the csv format. Consider the file data.csv that is shown below.
year,population
2006,40
2008,45
2010,48
2012,51
2014,53
2016,57
2017,62

Now, we can apply the above-given function.
Example − Let us consider the following example.
var data = d3.csvParse(string, function(d) {
   return {
      year: new Date(+d.Year, 0, 1), // lowercase and convert "Year" to Date
      population: d.population
   };
});
Here, it Parses the specified string in the delimiter-separated values. It returns an array of objects representing the parsed rows.
This method is used to parse the csv format equivalent to rows.
var data = d3.csvParseRows(string, function(d, i) {
   return {
      year: new Date(+d[0], 0, 1), // convert first colum column to Date
      population: d[1],
   };
});
It parses each row in the csv file.
This method is used to format the csv rows and columns.
Example − Let us consider the following example.
var string = d3.csvFormat(data, ["year", "population"]);
Here, if the columns are not specified, the list of the column names that forms the header row is determined by the union of all properties on all the objects in the rows. If columns are specified, it is an array of strings representing the column names.
This method is used to format the csv rows.
Example − Let us consider the following example.
var string = d3.csvFormatRows(data.map(function(d, i) {
   return [
      d.year.getFullYear(), // Assuming d.year is a Date object.
      d.population
   ];
}));
Here, it formats the specified array of string rows as delimiter-separated values, returning a string.
This method is used to parse the tsv format. It is similar to csvParse.
This method is used to parse the tsv format equivalent to rows. It is similar to csvParseRows function.
This method is used to format the tsv rows and columns.
This method is used to format the tsv rows.
 Print
 Add Notes
 Bookmark this page
How do we split a string with any whitespace chars as delimiters using java?

The split() method of the String class accepts a delimiter (in the form of the string), divides the current String into smaller strings based on the delimiter and returns the resulting strings as an array. If the String does not contain the specified delimiter this method returns an array which contains only the current string.
If the String does not contain the specified delimiter this method returns an array containing the whole string as element.
To split a String into an array of strings with white pace as delimiter −
Read the source string.
Read the source string.
Invoke split() method by passing “ ” as a delimiter.
Invoke split() method by passing “ ” as a delimiter.
Print the resultant array.
Print the resultant array.
Following Java program reads the contents of a file into a Sting and splits it using the split() method with white space as delimiter −
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
public class SplitExample {
   public static void main(String args[]) throws FileNotFoundException {
      Scanner sc = new Scanner(new File("D:\\sample.txt"));
      StringBuffer sb = new StringBuffer();
      String input = new String();
      while (sc.hasNextLine()) {
         input = sc.nextLine();
         sb.append(input);
      }
      String source = sb.toString();
      String result[] = source.split(" ");
      for(int i = 0; i < result.length; i++) {
         System.out.println(result[i]);
      }
   }
}
Hello
how
are
you
Python - Display images with PyGame

Pygame is a multimedia library for Python for making games and multimedia applications. In this article we will see how to use the pygame module to paint a picture on the screen taking into consideration, its height, width and position in the pygame window.
In the below program we initialize the pygame module and then define the mode and the caption for the image. Next we load the image and define the coordinates. The screen.blit function paints the screen while the while loop keeps listening the end of the game is clicked.
import pygame
pygame.init()
w = 300;
h = 300
screen = pygame.display.set_mode((w, h))
pygame.display.set_caption('Tutorialspoint Logo')
TPImage = pygame.image.load("E:\\Python3\\tutorialspoint.png").convert()
# coordinates of the image
x = 10;
y = 20;
screen.blit(TPImage, (x, y))
# paint screen one time
pygame.display.flip()
running = True
while (running): # loop listening for end of game
   for event in pygame.event.get():
      if event.type == pygame.QUIT:
         running = False
# loop over, quite pygame
pygame.quit()

Running the above code gives us the following result −
Tryit Editor v3.7

Tryit: Change the opacity on hover