Menu BAR

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

14 Nov 2022

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!!

11 Jul 2016

What is SQL

What is SQL?

Full Form : Structured Query Language

Definition : SQL is the standard language for accessing database. It is used to create manage and manipulate the database.

5 Aug 2014

C++ CLASS EXAMPLE

Program to create a simple class in C++

#include<iostream.h>
class simple
{
  private:
  void you()
  {
    cout<<"Hi, i am private, you cannot access in main.";
   }
  public:
  void hello()
  {
     cout<<"Welcome to hello function.\n";
   }
   void world()
  {
    cout<<"You are now in world function.";
   }
};
void main()
{
  simple obj;  //creating object of class simple
  cout<<"Welcome to main function.\n";
  obj.hello();  //accessing the function hello using the object obj of class simple
  obj.world();
  //object.you();  //this will give error because the function is private
  getch();
}

==OUTPUT==
Welcome to main function.
Welcome to hello function.
You are now in world function.

30 Jul 2014

CALL BY VALUE PROGRAM IN C

Program of Call by value for swapping two values

#include<stdio.h>
void swap(int a, int b)
{
  int temp;
  temp=a;
  a=b;
  b=temp;
 }
void main()
{
   int a=5;
   int b=10;
   /*printf("c-programcodes.blogspot.in");*/
   swap(a,b);  /*the values goes out of scope  after the function is executed*/
   printf("values are not swapped");
   printf("a=%d\n",a);
   printf("b=%d",b)
}
==OUTPUT==

values are not swapped
a=5
b=10

7 Jul 2014

Java Program #2

Q) Write a Program to print STAR Pattern.
   *
   **
   ***
   ****
   *****

Sol)

class Stars {
  public static void main(String[] args) {
    int row, numberOfStars;

    for (row = 1; row <= 5; row++) {
      for(numberOfStars = 1; numberOfStars <= row; numberOfStars++) {
        System.out.print("*");
      }
      System.out.println(); // Go to next line
    }
  }
}

Java Program #1

Q) Write a Program to print " Hello World ".


Sol)

   public class HelloWorld {

    public static void main(String[] args) {
        
        System.out.println("Hello World");
        
    }