Saturday, November 4, 2017

WT 11,12 JavaScript

Question: 
Create an HTML file to display the various arithmetic operations on variables using JavaScript.

Code:

<html>
<head>
<title>Arithmetic Operators</title>

<style type="text/css">
p{
color: white;
margin:1in;
margin-bottom: 0in;
margin-top: 0in;
text-align: center;
background-color: purple;
font-size: 25px;
font-family: Arial;
}
</style>

<script type="text/javascript">
function add(){
document.form1.result.value=parseInt(document.form1.a.value)+parseInt(document.form1.b.value);
}

function sub(){
document.form1.result.value=parseInt(document.form1.a.value)-parseInt(document.form1.b.value);
}

function mul(){
document.form1.result.value=parseInt(document.form1.a.value)*parseInt(document.form1.b.value);
}

function Div(){
document.form1.result.value=parseInt(document.form1.a.value)%parseInt(document.form1.b.value);
}
</script>
</head>
<body>
<center>
<p>This is a Simple Example  to display the various arithmetic operations on variables using JavaScript</p>
<br>
<br>
<form name="form1" style="font-size:20px;">
Enter First Number  : <input type="number" name="a" placeholder="Enter A : "/><br><br>
Enter Second Number : <input type="number" name="b" placeholder="Enter B : "/><br><br>
<button type="button" onClick="add()">+</button>&nbsp;&nbsp;<button type="button" onclick="sub()">-</button>&nbsp;&nbsp;<button type="button" onclick="mul()">*</button>&nbsp;&nbsp;<button type="button" onclick="Div()">%</button><br><br>
Result              : <input type="number" name="result" placeholder="Result :">
</form>
</center>
</body>
</html> 

Output:



Question:

Create an HTML file to implement the concept of document object model using JavaScript.

Code:
 <html>
<head>
<script type="text/javascript">
function change(){

var a=document.getElementById("Jarvis");
a.innerHTML="This Is Text After Clicking On Below Button";

a.style.color = "blue";
a.style.fontFamily = "Arial";
a.style.fontSize = "larger";
}

</script>


<style type="text/css">
h1{
color: white;
margin:1in;
margin-bottom: 0in;
margin-top: 0in;
text-align: center;
background-color: purple;
font-size: 25px;
font-family: Arial;
}
</style>

</head>

<body>
<h1>This is a simple Example  to implement the concept of document object model using
JavaScript. </h1>

<p id='Jarvis'>Clicking Below Button Will Change The Element Having Id='Jarvis'</p>
<center><button onclick="change()">Click Here</button></center>

</body>

</html>

Output:


WT 13,14,15 PHP Practicals

Question:
. Create a PHP file to print any text using variable

Code:
<html>

<head>
<?php
$variable="Hello World";
echo "<center><h1>".$variable."</h1></center>";
?>

<style type="text/css">
h1{
color: white;
background-color: purple;
font-size: 50px;
font-family: Arial;
}
</style>
</head>

<body>
<p style="font-size:30px;">This is a Simple Example To Show Text Using Variable in PHP</p>

</body>

</html>

Output:


Question:
 Demonstrate the use of statements, operators and functions in PHP.

Code:
<html>

<head>
<?php

if(isset($_POST['c'])){
$a=$_POST['a'];
$b=$_POST['b'];
$d=$_POST['d'];

operate($a,$b,$d);
}

function operate($a,$b,$d)
{
if(!(empty($a)||empty($b))){
if($d=="Add"){
echo "<html><h1>Result is : ".($a+$b)."</h1></html>";
}
else if($d=="Subtract"){
echo "<html><h1>Result is : ".($a-$b)."</h1></html>";
}
else if($d=="Multiply"){
echo "<html><h1>Result is : ".($a*$b)."</h1></html>";
}
else if($d=="Modulus"){
echo "<html><h1>Result is : ".($a%$b)."</h1></html>";
}
}else{
echo "All Fields are Mandatory";
}
}

?>

<style type="text/css">
h1{
color: white;
background-color: purple;
font-size: 50px;
font-family: Arial;
}
</style>
</head>

<body>
<p style="font-size:30px; text-align:center;">This is a Simple Example To Demonstrate the use of statements, operators and functions in PHP</p>

<center>
<form action="wt13.php" method="post">
<input type="number" name="a" placeholder="Enter A : ">
<input type="number" name="b" placeholder="Enter B : ">
<select name="d">
<option>Add</option>
<option>Subtract</option>
<option>Multiply</option>
<option>Modulus</option>
</select>
<input type="submit" value="Submit" name="c">
</form>
</center>

</body>

</html>

Output:

Question:
Demonstrate the use of Loops and arrays in PHP

Code:

<html>

<head>
<?php
if(isset($_POST['c']))
{

$array=array();
$a=$_POST['a'];

for($i=1;$i<=10;$i++){
$array[$i]=$a*$i;
// echo $a." * ".$i." = ".($a*$i);
}


for($i=1;$i<=10;$i++){
echo "<h1>",$a." * ".$i." = ".$array[$i]."</h1><br>";
}
}



?>

<style type="text/css">
h1{
color: white;
margin:1in;
margin-bottom: 0in;
margin-top: 0in;
text-align: center;
background-color: purple;
font-size: 30px;
font-family: Arial;
}
</style>
</head>

<body>
<p style="font-size:30px; text-align:center;">This is a Simple Example To Demonstrate the use of Loops and arrays in PHP</p>

<center>
<form action="wt13.php" method="post">
<input type="number" name="a" placeholder="Enter Any Number : " required>
<input type="submit" value="Submit" name="c">
</form>
</center>

</body>

</html>

Output:

Transformation Computer Graphics

Question:
Write a program to draw any 2-D object and perform the transformations on it according to the input parameters from the user, namely: Translation, Rotation or Scaling

Code:

#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main(){

    int g=DETECT,gmode;
    initgraph(&g,&gmode,"C://TURBOC3//BGI");
    line(200,300,300,200);
    int x;
    cout<<"Enter Your Choice\nPress 1 For Translation\n2 For Rotation\n3 For Scaling\n";
    cin>>x;

    if(x==1){
cleardevice();
int tx,ty;
line(200,300,300,200);
cout<<"Enter Translation Along x and y\n";
cout<<"Tx =";
cin>>tx;
cout<<"Ty =";
cin>>ty;
line(200+tx,300+ty,300+tx,200+ty);
    }else if(x==2){
cleardevice();
line(200,300,300,200);
cout<<"Enter Rotation Angle:\n";
cout<<"a=";
float a;
cin>>a;
a=a*(3.142/180);
cout<<200*cos(a)-300*sin(a)<<","<<200*sin(a)+300*cos(a)<<","<<300*cos(a)-200*sin(a)<<","<<300*sin(a)+200*cos(a);
//line((int)200*cos(a)-300*sin(a),(int)200*sin(a)+300*cos(a),(int)300*cos(a)-200*sin(a),(int)300*sin(a)+200*cos(a));
line(200*cos(a)-300*sin(a),200*sin(a)+300*cos(a),300*cos(a)-200*sin(a),300*sin(a)+200*cos(a));
    }else{
cleardevice();
float sx,sy;
line(200,300,300,200);
cout<<"Enter Scaling along x and y\n";
cout<<"Sx =";
cin>>sx;
cout<<"Sy =";
cin>>sy;
line(200*sx,300*sy,300*sx,200*sy);
    }

    getch();
}

Output:

Wednesday, November 1, 2017

Wt Practical 8,9,10

Code:

<html>
<head>
<link rel="stylesheet" type="text/css" href="Wt8.css">
<style type="text/css">
h2{
font-size:40px;
font-family: Arial;
text-align: center;
}
</style>
</head>

<body>
<h1 style="font-size:50px; text-align:left; font-family:TimesNewRoman; ">Inline Style</h1>
<h2>Internal Style</h2>
<h3>External Style</h3>
</body>
</html>


Wt8.css:

h3{
font-size: 40px;
font-family: Courier;
text-align: right;
}


Output:
Code:
<html>
<head>
<style type="text/css">
a{
font-family:Helvetica;
font-size: 30px;
}
a:visited{
color: red;
}

a:link{
color: yellow;
}

a:hover{
color: green;
font-size: 40px;
}
p{
text-align: center;
font-size: 50px;
font-family: Arial;
color: blue;
}
</style>
</head>
<body>

<p>Click On Below Links And You Will Be Redirected</p>
<ul type="square">
<li><a href="https://www.google.co.in/?q=hello U">iPhoneX</a></li>
<li><a href="https://www.google.co.in/">iPhone8</a></li>
<li><a href="https://www.google.co.in/?q=bye U">iPhone7</a></li>
</ul>


</body>
</html>

Output:

Code:

<html>
<head>
<style type="text/css">
table th{
background-color: purple;
color: white;
}

table tr{
font-family: Arial;
font-size: 20px;
}
table tr:hover{
background-color: green;
}

ul{
list-style: squares;
}
ul li{
font-size: 20px;
font-family: Arial;
}
ul li:hover{
color: red;
}
</style>
</head>
<body>

<center><h3>Key Specs iPhone7</h3>
<table border="2" cellpadding="5" cellspacing="5">
<tr><td>Display</td><td>Processor</td><td>Front Camera</td></tr>
<tr><th>4.70-inch</th><th>quad core</th><th>7-megapixel</th></tr>
<tr></tr>
<tr><td>Resolution</td><td>OS</td><td>Storage</td></tr>
<tr><th>750x1334 pixels</th><th>iOS 10</th><th>32GB</th></tr>
<tr></tr>
<tr><td>Rear Camera</td><td>Price</td></tr>
<tr><th>12-megapixel</th><th>Rs. 45,999</th></tr>
</table>
</center>
<br>
<ul>
<li>iPhone7</li>
<li>iPhone7+</li>
<li>iPhone8</li>
<li>iPhone8 plus</li>
<li>iPhoneX</li>
</ul>



</body>
</html>

Output:

Sunday, October 29, 2017

Prim's Java DAA 6

Code:




import java.util.ArrayList;

public class Prims {

   static class Vertex{
        int parent;
        boolean set;
        int key;


        public Vertex(int parent, boolean set, int key) {
            this.parent = parent;
            this.set = set;
            this.key = key;
        }

       @Override       public String toString() {
           return "Vertex{" +
                   "parent=" + parent +
                   ", set=" + set +
                   ", key=" + key +
                   '}';
       }
   }

    public static void main(String[] nt){

        int graph[][]= {{0, 2, 0, 6, 0},
                {2, 0, 3, 8, 5},
                {0, 3, 0, 0, 7},
                {6, 8, 0, 0, 9},
                {0, 5, 7, 9, 0},
        };

        int n=graph.length;

        ArrayList<Vertex> vertices=new ArrayList<>();
        for(int i=0;i<n;i++) {
            vertices.add(new Vertex(-1, false, Integer.MAX_VALUE));
        }
        vertices.get(0).key=0;


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

            int min=find(vertices);
            vertices.get(min).set=true;

            for(int j=1;j<n;j++){
                if(graph[min][j]<vertices.get(j).key&&vertices.get(j).set==false && graph[min][j]!=0){
                    vertices.get(j).key=graph[min][j];
                    vertices.get(j).parent=min;
                }
            }
        }

        System.out.println("Edge    Weight");
        for(int i=1;i<vertices.size();i++){
            System.out.println(vertices.get(i).parent+" - "+i+"  : "+graph[i][vertices.get(i).parent]);
            //System.out.println(vertices.get(i).toString());        }
    }

    static int find(ArrayList<Vertex> vertices){
        int min=Integer.MAX_VALUE,i=0;

        for(int x=0;x<vertices.size();x++){
            if(vertices.get(x).key<min && vertices.get(x).set!=true){
                min=vertices.get(x).key;
                i=x;
            }
        }

        return i;
    }

}
Output:



Friday, October 27, 2017

Knapsack Java

Knapsack Using Greedy Algorithm

Code:
package com.nearur;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class KNAPSACK {
 static int capacity=40;

 public static void main(String[] args) {
package com.nearur;

public class Item {

String name;
int value,weight;
public Item(String name, int value, int weight) {
super();
this.name = name;
this.value = value;
this.weight = weight;
}

int compareWeight(Item x) {
if(x.weight>weight) {
return -1;
}return 1;
}

int compareValue(Item x) {
if(x.value>value) {
return 1;
}return -1;
}

int compareratio(Item x) {
if(x.value/x.weight>value/weight) {
return 1;
}return -1;
}

}

  Item [] item=new Item[4];
  item[0]=new Item("I1",100,20);
  item[1]=new Item("I2",90,10);
  item[2]=new Item("I3",40,15);
  item[3]=new Item("I4",50,5);

  ArrayList<Item> knapsack=new ArrayList<>();
  ArrayList<Item> allitems=new ArrayList<>();

  for(int i=0;i<item.length;i++) {
   allitems.add(item[i]);
  }

  Comparator<Item> com=new Comparator<Item>() {
 
   @Override
   public int compare(Item o1, Item o2) {
    return o1.compareratio(o2);
    //return o1.compareValue(o2);
    //return o1.compareWeight(o2);
   }
  };

  Collections.sort(allitems,com);

  for(Item ite:allitems) {
   System.out.println(ite.name);
   if(ite.weight<=capacity) {
    knapsack.add(ite);
    capacity=capacity-ite.weight;
   }
  }

  int mvalue=0,mweight=0;

  for(Item i: knapsack) {
   mvalue +=i.value;
   mweight +=i.weight;
  }

  System.out.println("Total Value: "+mvalue+"\nTotal Weight: "+mweight);
 }
}


Output:


Tuesday, October 10, 2017

MidPoint Circle Generation Algorithm

Question: Write a program to generate a complete moving wheel using Midpoint circle drawing algorithm and DDA line drawing algorithm.

Code:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
int u=1;
void dda(int x1, int y1, int x2, int y2) {
  int s, dx, dy, m;
  float xi, yi, x, y;
  dx = x2 - x1;
  dy = y2 - y1;
  if (abs(dx) > abs(dy))
    s = abs(dx); else
    s = abs(dy);
  xi = dx / (float) s;
  yi = dy / (float) s;
  x = x1;
  y = y1;
  putpixel(x1 + 0.5, y1 + 0.5, 15);
  for (m = 0; m < s; m++) {
    x += xi;
    y += yi;
    putpixel(x + 0.5, y + 0.5, 15);
  }
}
void main(){

    int g=DETECT,gmode;
    initgraph(&g,&gmode,"C://TURBOC3//BGI");

    int r;
    cout<<"Enter Radius \n";
    cin>>r;

    int x=0,y=r;
    int p=1-r;
    int xc=50,yc=200;
    while(xc<750)
    {  cleardevice();
       x=0;y=r;p=1-r;
      while(x<y){

      if(p<=0){
p=p+2*x+3;
      }else{
p=p+2*(x-y)+5;
y--;
      }
      x++;
      putpixel(xc+x,yc+y,10);
      putpixel(xc+y,yc+x,10);
      putpixel(xc+x,yc-y,10);
      putpixel(xc-y,yc+x,10);
      putpixel(xc-x,yc-y,10);
      putpixel(xc+y,yc-x,10);
      putpixel(xc-x,yc+y,10);
      putpixel(xc-y,yc-x,10);


      if(u%20==0){
      dda(xc-x,yc+y,xc+x,yc-y);
      dda(xc+x,yc+y,xc-x,yc-y);
      dda(xc+y,yc+x,xc-y,yc-x);
      dda(xc-y,yc+x,xc+y,yc-x);
    }u++;
  }
  xc=xc+5;
  delay(90);
  }
getch();
}

Output: