Menu BAR

FEEL FREE TO ASK ANY PROGRAM and please mention any error if you find it

20 Nov 2022

C++ Program to call the function

## C++ Program to call the function ##



#include<iostream.h>
#include<conio.h>
class first
{  
public:
   void my()
    {
      cout<<"Welcome to C++";
     }
};
void main()
{
first a;
a.my();
getch();
}


===OUTPUT=== 

Welcome to C++

16 Nov 2022

Java Program to print an integer entered by user

## Java program to print an integer ##

import java.util.Scanner;

public class PrintInteger {

    public static void main (String[] args){
    
        Scanner reader = new Scanner (System.in);    
        System.out.println ("Input a Number: ");

        int number = reader.nextInt ();
        System.out.println ("Number you entered: " + number);
    }
}


===OUTPUT===

Input a Number: 4
Number you entered: 4

15 Nov 2022

Node JS program to connect to SQL table and use WHERE clause

  ## Node JS program to connect to SQL table and use WHERE clause ## 

var mysql = require ('mysql');

// create a connection 
var con = mysql.createConnection({
    host: "localhost",
    user: "admin",
    password: "admin",
    database: "dummy"
});

con.connect(function(err)){
    if (err) throw err;

    con.query("Select * from student where age>15", function (err, result, fields) {
    if (err) throw err;
   
    console.log (" Result is: ", result);
    });
});

14 Nov 2022

Node JS program to delete a text file

 ## Node JS program to delete a text file ##


var fs = require ('fs');


fs.unlink ('file.txt', function (err){
    if (err) throw err;

    console.log (' File deleted successfully!! ');
});


===OUTPUT===

Run the program using the node command:
$ node deleteFile.js
File deleted successfully!! 

C++ program to create star pattern

WRITE A PROGRAM TO PRINT THE FOLLOWING STAR PATTERN

#include<iostream.h>
#include<conio.h>
void main()
{
 clrscr();
 int i, j, n;
 cout<<"Enter number of rows\n";
 cin>>n;
 for(i=1;i<=n;i++)
  {
   for(j=1;j<=i;j++)
    {
     cout<<"*";
    }
   cout<<endl;
  }
 for(i=n-1;i>=1;i--)
  {
   for(j=1;j<=i;j++)
    {
     cout<<"*";
    }
   cout<<endl;
 }
 getch();
}

Node JS program to connect to sql server

## Node js program to connect to SQL server ##

var express = require ('express');
var app = express();

app.get ('/', function (req,res){
    var sql = require ("mssql");

    // database config
    var config = {
        user: 'admin',
        password: 'admin',
        server: 'localhost',
        database: 'db'
    };

    // Database connectivity
    sql.connect (config, function (err){
        if (err) console.log (err);
        
        //create a request object
        var request = new sql.Request();

        // database query
        request.query (' Select * from student', function (err, record){
        res.send (record);
        });
    });
});

var server = app.listen(3000, function (){
    console.log (' Server running ....');
});

Node JS program to read a text file

 4) Program to read a file from node.js

const fs = require ('fs');

fs.readFile('./test.txt','utf8', (err, data) => {
    if (err) {console.error(err); }

    console.log ("Data is: "+data);
});

13 Nov 2022

Node JS program to create a new file

 3) Create a new text file from Node.js 

var fs = require ('fs');  // include pre-built node file stream module
var data = "Creating a new file";


fs.writeFile('newFile.txt', data, function (err){
    if (err) throw err;
    console.log (" File created successfully"};
});


Run the program in the terminal:
$ node createNewFile.js
File created successfully

Node JS program to create a module

2) Program to create a node module

Let us create a Calculator.js file with add, subtract, and multiply functions ->

// Addition of two numbers
exports.add = function (x, y){
    return x+y;
}

// Subtraction of two numbers
exports.subtract = function (x, y){
    return x-y;
}

// Multiply of two numbers
exports.multiply = function (x,y){
    return x*y;
}

Let us create a new node file to call these functions ->

var calc = require ('./Calculator.js')
var x = 15, y= 10;

console.log (" Addition of two numbers is: "+ calc.add (x,y));
console.log (" Subtraction of two numbers is: "+ calc.subtract (x,y));
console.log (" Multiplication of two numbers is: "+ calc.multiply (x,y));


===OUTPUT===

Addition of two numbers is: 25
Subtraction of two numbers is: 5
Multiplication of two numbers is: 150

Node JS program to create a server

## Program to create a server in node.js language ##


var http = require ('http');
http.createServer( function (req, res) {
    res.writeHead (200, {'Content-type': 'text/plain'});
    res.end ('Hello World!!');
}).listen (8080);

===OUTPUT===

Hello World!!