Tuesday, December 17, 2019

Javascript program to display alert box on click


Alert box on click in javascript program:

<input type="button" value="Click me" onclick="alert('Thanks for visiting my blog.....!');">


The multi threading concept in C++ with an example

The multi threading concept in C++ with an example:

#include
#include
using namespace std;
// function to be used in callable
void func_dummy(int N)
 {

  for (int i = 0; i < N; i++) {
  cout << "Thread 1 :: callable => function pointer\n";
   }

 }
 
// A callable object

class thread_obj {

 public:

   void operator()(int n) {

       for (int i = 0; i < n; i++)

           cout << "Thread 2 :: callable => function object\n";

   }

};

int main()
{
// Define a Lambda Expression
auto f = [](int n) {
   for (int i = 0; i < n; i++)
   cout << "Thread 3 :: callable => lambda expression\n";
   };
//launch thread using function pointer as callable
thread th1(func_dummy, 2);
// launch thread using function object as callable
thread th2(thread_obj(), 2);
//launch thread using lambda expression as callable
thread th3(f, 2);
// Wait for thread t1 to finish
 th1.join();
// Wait for thread t2 to finish
th2.join();
// Wait for thread t3 to finish
th3.join();
return 0;
}

Output:

Thread 1 :: callable => function pointer
Thread 1 :: callable => function pointer
Thread 3 :: callable => lambda expression
Thread 3 :: callable => lambda expression
Thread 2 :: callable => function object
Thread 2 :: callable => function object

Programming language : Ruby

Programming language : Ruby

Ruby is an interpreted, high-level, general-purpose programming language.
It was designed and developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.
A dynamic, open source programming language with a focus on simplicity and productivity.
It has an elegant syntax that is natural to read and easy to write.


Platform support
Matsumoto originally did Ruby development on the 4.3BSD-based Sony NEWS-OS 3.x, but later migrated his work to SunOS 4.x, and finally to Linux.
Ruby versions and implementations are available on many operating systems, such as Linux, BSD, Solaris, AIX, macOS, Windows, Windows Phone,[104] Windows CE, Symbian OS, BeOS, and IBM i.

Features of Ruby:

1.Thoroughly object-oriented with inheritance, mixins and metaclasses
2.Dynamic typing and duck typing
3.Everything is an expression (even statements) and everything is executed imperatively (even declarations)
4.Succinct and flexible syntaxthat minimizes syntactic noise and serves as a foundation for domain-specific languages
5.Dynamic reflection and alteration of objects to facilitate metaprogramming
6.Lexical closures, iterators and generators, with a block syntax
7.Literal notation for arrays, hashes, regular expressions and symbols
8.Embedding code in strings (interpolation)
9.Default arguments
10.Four levels of variable scope (global, class, instance, and local) denoted by sigils or the lack thereof
11.Garbage collection
12.First-class continuations
13.Strict boolean coercion rules (everything is true except false and nil)
14.Exception handling
15.Operator overloading
16.Built-in support for rational numbers, complex numbers and arbitrary-precision arithmetic
17.Custom dispatch behavior (through method_missing and const_missing)
18.Native threads and cooperative fibers (fibers are a 1.9/YARV feature)
19.Support for Unicode and multiple character encodings.
20.Native plug-in API in C
21.Interactive Ruby Shell (a REPL)
22.Centralized package management through RubyGems
23.Implemented on all major platforms
24.Large standard library, including modules for YAML, JSON, XML, CGI, OpenSSL, HTTP, FTP, RSS, curses, zlib and Tk

Repositories and libraries:
RubyGems is Ruby's package manager. A Ruby package is called a "gem" and can easily be installed via the command line. Most gems are libraries, though a few exist that are applications, such as IDEs.
There are over 10,000 Ruby gems hosted on RubyGems.org.
Many new and existing Ruby libraries are hosted on GitHub, a service that offers version control repository hosting for Git.
The Ruby Application Archive, which hosted applications, documentation, and libraries for Ruby programming, was maintained until 2013, when its function was transferred to RubyGems.

Date and time java script program

<!DOCTYPE html>
<title>Time and Date</title>


<time id="msg"></time>

<script>
  document.getElementById("msg").innerHTML = new Date().toLocaleString();
</script>

JavaScript program to create a JavaScript object to show the current time

<!DOCTYPE html>
<title>Current time</title>

<time id="time"></time>
<script language="javascript">
  /*Create a JavaScript object for the current time,then extract the desired parts, then join them again in the desired format.*/

  var currentTime = new Date(),
      hours = currentTime.getHours(),
      minutes = currentTime.getMinutes();
 
 
  if (minutes < 10) {
    minutes  = "0" + minutes;
  }

 
var suffix = "AM";
if (hours >= 12) {
    suffix = "PM";
    hours = hours - 12;
}
if (hours == 0) {
hours = 12;
}


  time = hours + ":" + minutes + " " + suffix;
     
  // Output
  document.getElementById("time").innerHTML = time;
</script>

JavaScript program for multiplication table

<html>
<head>
  <title>Multiplication Table</title>
  <script type="text/javascript">
    var rows = prompt("How many rows for your multiplication table?");
    var cols = prompt("How many columns for your multiplication table?");
    if(rows == "" || rows == null)
    rows = 10;
    if(cols== "" || cols== null)
    cols = 10;
    createTable(rows, cols);
    function createTable(rows, cols)
    {
      var j=1;
      var output = "<table border='1' width='500' cellspacing='0'cellpadding='5'>";
      for(i=1;i<=rows;i++)
      {
    output = output + "<tr>";
        while(j<=cols)
        {
    output = output + "<td>" + i*j + "</td>";
      j = j+1;
    }
    output = output + "</tr>";
    j = 1;
    }
    output = output + "</table>";
    document.write(output);
    }
  </script>
</head>
<body>
</body>
</html>

Monday, December 16, 2019

C program solved practical slips of F.Y.B.Sc. Computer Science Laboratory Course I & II

C program solved practical slips of F.Y.B.Sc. Computer Science Laboratory Course I & II:

Program no: 6

Title:To demonstrate the use of library functions

#include
#include
#include
void main()
{
int n,x;
float s,c,l,sqr,expo;
clrscr();
printf("\n Enter the number:");
scanf("%d",&n);
do
{
printf("\n Select any of the following operations:");
printf("\n 1.Sine");
printf("\n 2.Cosine");
printf("\n 3.Log");
printf("\n 4.Exponential");
printf("\n 5.Squareroot");
printf("\n 6.Exit\t");
scanf("%d",&x);
switch(x)
{
case 1:s=sin(n);
printf("\n Sine= %f",s);
break;
case 2:c=cos(n);
printf("\n Cosine= %f",c);
break;
case 3:l=log(n);
printf("\n Log= %f",l);
break;
case 4:expo=exp(n);
printf("\n Exponential= %f",expo);
break;
case 5:sqr=sqrt(n);
printf("\n Squareroot= %f",sqr);
break;
case 6:break;
default:printf("\n Invalid choice ");
break;
}

}while(x!=6);

getch();
}

Output:

Enter the number:4
Select any of the following operations:
1.Sine
2.Cosine
3.Log
4.Exponential
5.Squareroot
6.Exit 2

Cosine = -0.6536

Select any of the following operations:
1.Sine
2.Cosine
3.Log
4.Exponential
5.Squareroot
6.Exit



Program no: 7
Title:To demonstratethe use of functions

#include
#include
void prime();
void main()
{
clrscr();
prime();
getch();
}
void prime()
{
int num,temp=0,i,j=1,ct=0,n=0,a=1;
printf("\nEnter a number:");
scanf("%d",&num);
if(num>0)
{
for(i=2;i{
if(num%i==0)
{
printf("\n not a prime number");
temp=1;
break;
}
}
if(temp==0)
printf("\n it is a prime number");
}
while(n<10 p="">{
j=1;
ct=0;
while(j<=a)
{
if(a%j==0)
ct++;
j++;
}
if(ct==2)
printf("\n\n%d",a);
n++;
}
a++;
}
}


Output:


Enter a prime number: 5
It is a prime number
2
3
5
7
11
13
17
19
23
29


Program no: 8
Title:To demonstrate the use of one dimenstional array

#include
#include
void occur();
void main()
{
clrscr();
occur();
getch();
}
void occur()
{
int a[25],i,n,count=0,x;
printf(“\n Enter number of elements:”);
scanf(“%d”,&n);
printf(“\n Enter elements for array:\n “);
for(i=0;i<=n-1;i++)
{
scanf(“%d”,&a[i]);
}
printf(“\n Enter number to check the frequency of occurrence:”);
scanf(“%d”,&x);
for(i=0;i<=n-1;i++)
{
if(a[i]==x)
count++;
}
printf(“\n The frequency of occurrence is %d”,count);
}
Output:
Enter number of elements: 5
Enter elements for array:
2
1
3
4
5
5
The frequency of occurrence is 2



Program no: 9
Title:To demonstrate the use of two dimenstional array

#include
#include
void trans();
void main()
{
clrscr();
trans();
getch();
}
void trans()
{
int a[20][20],i,j,m,n;
printf("\n Enter the number of rows and columns:");
scanf("%d\t%d",&m,&n);
printf("\n Enter elements for matrix:\n");
for(i=0;i<=m-1;i++)
{
for(j=0;j<=n-1;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("\n Transpose of matrix is:\n");
for(i=0;i<=n-1;i++)
{
for(j=0;j<=m-1;j++)
{
printf("%d",a[j][i]);
}
printf("\n");
}
}
Output:
Enter the number of rows and columns: 3 3
Enter elements for matrix:
2
3
4
5
6
7
8
9
1
Transpose of matrix is:
2 5 8
3 6 9
4 7 1






List of bank names in India

 Here is a comprehensive list of banks in India, categorized by type: