Wednesday, 24 October 2018
Interfaces in JAVA
Program No 1:-Single Inheritance
Program No 2:-Multiple Inheritance
Program No 3:-Multiple Inheritance using Interfaces
Program No 2:-Multiple Inheritance
Program No 3:-Multiple Inheritance using Interfaces
Arrays, Strings and Vectors in JAVA
Program No 1:- One Dimensional Array in Java
Program No 2:- Two Dimensional Array in Java
Program No 3:- Matrix Addition in Java
Program No 4:- Matrix Subtraction in Java
Program No 5:- Matrix Multiplication in Java
Program No 6:- Transpose of the Matrix
Program No 7:- Upper Triangular Matrix Formation
Program No 8:- Lower Triangular Matrix Formation
Program No 9:- Sum of Diagonal Elements of a Square Matrix
Program No 10:-Determinant of 2 * 2 Matrix
Program No 11:-Determinant of 3 * 3 Matrix
Program No 12:-Enter and Display a String
Program No 13:-Different Ways to Display a String
Program No 14:-Use of charAt
Program No 15:-Length of the String
Program No 16:-Conversion of string into its upper and lower case
Program No 17:-Vectors in Java
Program No 2:- Two Dimensional Array in Java
Program No 3:- Matrix Addition in Java
Program No 4:- Matrix Subtraction in Java
Program No 5:- Matrix Multiplication in Java
Program No 6:- Transpose of the Matrix
Program No 7:- Upper Triangular Matrix Formation
Program No 8:- Lower Triangular Matrix Formation
Program No 9:- Sum of Diagonal Elements of a Square Matrix
Program No 10:-Determinant of 2 * 2 Matrix
Program No 11:-Determinant of 3 * 3 Matrix
Program No 12:-Enter and Display a String
Program No 13:-Different Ways to Display a String
Program No 14:-Use of charAt
Program No 15:-Length of the String
Program No 16:-Conversion of string into its upper and lower case
Program No 17:-Vectors in Java
Classes Objects and Methods in JAVA
Program No 1:- Use of class in Java
Program No 2:- default constructor in Java
Program No 3:- Parameterized Constructor in Java
Program No 4:- Constructor Overloading in Java
Program No 5:- Method Overloading in Java
Program No 2:- default constructor in Java
Program No 3:- Parameterized Constructor in Java
Program No 4:- Constructor Overloading in Java
Program No 5:- Method Overloading in Java
Decision Making Branching and Looping Statements in JAVA
Program No 1:- Simple if Statement in Java
Program No 2:- if else statement in Java
Program No 3:- Nested if else Statement in Java
Program No 4:- if else if ladder in Java
Program No 5:- Switch Statement in Java
Program No 6:- Maximum out of 3
Program No 7:- Use of for loop in Java
Program No 8:- Nested for loop in Java
Program No 9:- While loop in Java
Program No 10:- do while loop in Java
Program No 2:- if else statement in Java
Program No 3:- Nested if else Statement in Java
Program No 4:- if else if ladder in Java
Program No 5:- Switch Statement in Java
Program No 6:- Maximum out of 3
Program No 7:- Use of for loop in Java
Program No 8:- Nested for loop in Java
Program No 9:- While loop in Java
Program No 10:- do while loop in Java
Operators and Mathematical Functions in JAVA
Program 2 :- Modulus Operator
Program 3 :- Relational Operators
Program 4 :- Increment and Decrement Operators
Program 5 :- Bitwise Operators
Program 6 :- Conditional Operator to Calculate Max out of 2
Program 7 :- Conditional Operator to Calculate Max out of 3
Program 8 :- Shorthand Assignment Operators
Program 9 :- Type Casting
Program 10 :- Conversion of Days into Years Months Weeks and Days
Program 11 :- Square Root in Java
Program 12 :- Power Function in Java
Program 13 :- Compound Interest in Java
Practical File of JAVA
1.
Operators and Mathematical Functions (Click
Here)
2. Decision
Making Branching and Looping Statements(Click
Here)
3. Classes
Objects and Methods(Click
Here)
4. Arrays,
Strings and Vectors(Click
Here)
5. Interfaces(Click
Here)
6. Packages(Click
Here)
7.
Exception Handling(Click
Here)
8.
Applet Programming(Click
Here)
9.
Abstract Window Toolkit(Click Here)
10.
Event Handling(Click
Here)
11.
Input Output Handling(Click
Here)
12. Java
Swings(Click
Here)
13. JSP(Click
Here)
14.
JDBC(Click
Here)
15.
Socket Programming(Click
Here)
Monday, 16 April 2018
Implementation of xor in CANVAS
<!DOCTYPE html>
<html>
<body>
<h2> Implementation of xor in CANVAS</h2>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle='green';
context.fillRect(x-200,y-200,200,200);
context.globalCompositeOperation='xor';
context.beginPath();
context.fillStyle='red';
context.fillRect(x-100,y-100,200,200);
</script>
</body>
</html>
Implementation of copy in CANVAS
<!DOCTYPE html>
<html>
<body>
<h2> Implementation of copy in CANVAS</h2>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle='green';
context.fillRect(x-200,y-200,200,200);
context.globalCompositeOperation='copy';
context.beginPath();
context.fillStyle='red';
context.fillRect(x-100,y-100,200,200);
</script>
</body>
</html>
Implementation of lighter in CANVAS
<!DOCTYPE html>
<html>
<body>
<h2> Implementation of lighter in CANVAS</h2>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle='green';
context.fillRect(x-200,y-200,200,200);
context.globalCompositeOperation='lighter';
context.beginPath();
context.fillStyle='red';
context.fillRect(x-100,y-100,200,200);
</script>
</body>
</html>
Implementation of destination-out in CANVAS
<!DOCTYPE html>
<html>
<body>
<h2> Implementation of destination-out in CANVAS</h2>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle='green';
context.fillRect(x-200,y-200,200,200);
context.globalCompositeOperation='destination-out';
context.beginPath();
context.fillStyle='red';
context.fillRect(x-100,y-100,200,200);
</script>
</body>
</html>
Implementation of destination-in in CANVAS
<!DOCTYPE html>
<html>
<body>
<h2> Implementation of destination-in in CANVAS</h2>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle='green';
context.fillRect(x-200,y-200,200,200);
context.globalCompositeOperation='destination-in';
context.beginPath();
context.fillStyle='red';
context.fillRect(x-100,y-100,200,200);
</script>
</body>
</html>
Implementation of destination-atop in CANVAS
<!DOCTYPE html>
<html>
<body>
<h2> Implementation of destination-atop in CANVAS</h2>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle='green';
context.fillRect(x-200,y-200,200,200);
context.globalCompositeOperation='destination-atop';
context.beginPath();
context.fillStyle='red';
context.fillRect(x-100,y-100,200,200);
</script>
</body>
</html>
Implementation of destination-over in CANVAS
<!DOCTYPE html>
<html>
<body>
<h2> Implementation of destination-over in CANVAS</h2>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle='green';
context.fillRect(x-200,y-200,200,200);
context.globalCompositeOperation='destination-over';
context.beginPath();
context.fillStyle='red';
context.fillRect(x-100,y-100,200,200);
</script>
</body>
</html>
Implementation of source-out in CANVAS
<!DOCTYPE html>
<html>
<body>
<h2> Implementation of source-out in CANVAS</h2>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle='green';
context.fillRect(x-200,y-200,200,200);
context.globalCompositeOperation='source-out';
context.beginPath();
context.fillStyle='red';
context.fillRect(x-100,y-100,200,200);
</script>
</body>
</html>
Implementation of source-in in CANVAS
<!DOCTYPE html>
<html>
<body>
<h2> Implementation of source-in in CANVAS</h2>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle='green';
context.fillRect(x-200,y-200,200,200);
context.globalCompositeOperation='source-in';
context.beginPath();
context.fillStyle='red';
context.fillRect(x-100,y-100,200,200);
</script>
</body>
</html>
Implementation of source-atop in CANVAS
<!DOCTYPE html>
<html>
<body>
<h2> Implementation of source-atop in CANVAS</h2>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle='green';
context.fillRect(x-200,y-200,200,200);
context.globalCompositeOperation='source-atop';
context.beginPath();
context.fillStyle='red';
context.fillRect(x-100,y-100,200,200);
</script>
</body>
</html>
Implementation of source-over in CANVAS
<!DOCTYPE html>
<html>
<body>
<h2> Implementation of source-over in CANVAS</h2>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle='green';
context.fillRect(x-200,y-200,200,200);
context.globalCompositeOperation='source-over';
context.beginPath();
context.fillStyle='red';
context.fillRect(x-100,y-100,200,200);
</script>
</body>
</html>
XOR operation in canvas
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="500" height="400" style="border:3px solid #FF00FF;"></canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var gradient = ctx.createLinearGradient(0, 0, 200,300);
gradient.addColorStop("0", "blue");
gradient.addColorStop("0.25", "green");
gradient.addColorStop("0.5", "yellow");
gradient.addColorStop("0.75","red");
gradient.addColorStop("1.0", "magenta");
ctx.strokeStyle = gradient;
ctx.lineWidth = 7;
ctx.strokeRect(40,40,400,300);
ctx.strokeStyle = 'red';
ctx.beginPath();
ctx.arc(200,200,100, 0, 2.0 * Math.PI, false);
ctx.fillStyle = 'yellow';
ctx.fill();
ctx.lineWidth = 5;
ctx.stroke();
ctx.globalCompositeOperation = "xor";
ctx.strokeStyle = 'red';
ctx.beginPath();
ctx.arc(300,200,100, 0, 2.0 * Math.PI, false);
ctx.fillStyle = 'yellow';
ctx.fill();
ctx.lineWidth = 5;
ctx.stroke();
</script>
</body>
</html>
Clipping of Circle,SemiCircle,Trapezium and Triangle in CANVAS
<!DOCTYPE html>
<html>
<body>
<span>Without clip():</span>
<canvas id="myCanvas" width="300" height="300" style="border:4px solid #0000FF;">
</canvas>
<script>
var c = document.getElementById("myCanvas");
var context= c.getContext("2d");
context.rect(50, 50, 200, 200);
context.lineWidth = 3;
context.stroke();
context.beginPath();
context.arc(230,230,50, 0, 2*Math.PI, true);
context.closePath();
context.lineWidth = 5;
context.fillStyle = 'yellow';
context.fill();
context.lineWidth = 5;
context.stroke();
context.beginPath();
context.arc(80,270,50, 0, Math.PI, true);
context.closePath();
context.lineWidth = 5;
context.fillStyle = 'red';
context.fill();
context.lineWidth = 5;
context.stroke();
context.beginPath();
context.moveTo(20, 20);
context.lineTo(20, 200);
context.lineTo(100, 130);
context.lineTo(100, 70);
context.closePath();
context.fillStyle = 'magenta';
context.fill();
context.lineWidth = 5;
context.stroke();
context.beginPath();
context.moveTo(120, 20);
context.lineTo(100, 40);
context.lineTo(160, 100);
context.closePath();
context.fillStyle = 'green';
context.fill();
context.lineWidth = 5;
context.stroke();
</script>
<span>With clip():</span>
<canvas id="myCanvas2" width="300" height="300" style="border:4px solid #0000FF;">
</canvas>
<script>
var c = document.getElementById("myCanvas2");
var context = c.getContext("2d");
context.rect(50, 50, 200, 200);
context.lineWidth = 3;
context.stroke();
context.clip();
context.beginPath();
context.arc(230,230,50, 0, 2*Math.PI, true);
context.closePath();
context.lineWidth = 5;
context.fillStyle = 'yellow';
context.fill();
context.lineWidth = 5;
context.stroke();
context.beginPath();
context.arc(80,270,50, 0, Math.PI, true);
context.closePath();
context.lineWidth = 5;
context.fillStyle = 'red';
context.fill();
context.lineWidth = 5;
context.stroke();
context.beginPath();
context.moveTo(20, 20);
context.lineTo(20, 200);
context.lineTo(100, 130);
context.lineTo(100, 70);
context.closePath();
context.fillStyle = 'magenta';
context.fill();
context.lineWidth = 5;
context.stroke();
context.beginPath();
context.moveTo(120, 20);
context.lineTo(100, 40);
context.lineTo(160, 100);
context.closePath();
context.fillStyle = 'green';
context.fill();
context.lineWidth = 5;
context.stroke();
</script>
</body>
</html>
Clipping of Rectangle in Canvas
<!DOCTYPE html>
<html>
<body>
<span>Without clip():</span>
<canvas id="myCanvas" width="300" height="300" style="border:4px solid #FFFF00;">
</canvas>
<script>
var c = document.getElementById("myCanvas");
var context= c.getContext("2d");
context.rect(50, 50, 200, 200);
context.stroke();
context.fillStyle = "green";
context.fillRect(10, 10, 150, 100);
context.fillStyle = "red";
context.fillRect(150,150,140,140);
context.fillStyle = "blue";
context.fillRect(10,130,110,140);
context.fillStyle = "magenta";
context.fillRect(180,10,110,130);
</script>
<span>With clip():</span>
<canvas id="myCanvas2" width="300" height="300" style="border:4px solid #FFFF00;">
</canvas>
<script>
var c = document.getElementById("myCanvas2");
var context = c.getContext("2d");
context.rect(50, 50, 200, 200);
context.stroke();
context.clip();
context.fillStyle = "green";
context.fillRect(10, 10, 150, 100);
context.fillStyle = "red";
context.fillRect(150,150,140,140);
context.fillStyle = "blue";
context.fillRect(10,130,110,140);
context.fillStyle = "magenta";
context.fillRect(180,10,110,130);
</script>
</body>
</html>
clear rectangle in canvas
<!DOCTYPE HTML>
<html>
<body>
<canvas id="myCanvas" width="800" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.fillStyle = "yellow";
context.fillRect(x-300,y-200,600,400);
context.clearRect(x-200,y-100,400,200);
</script>
</body>
</html>
bezier Curve in Canvas
<!DOCTYPE HTML>
<html>
<body>
<canvas id="myCanvas" width="800" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
context.strokeStyle = 'red';
<!--Setting of color of arc-->
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.beginPath();
context.moveTo(x-200, y-100);
context.bezierCurveTo(x-200, y+100, x+200, y+100,x+200,y-100);
context.lineWidth = 10;
context.strokeStyle = 'red';
context.stroke();
context.lineWidth = 2;
context.moveTo(x-200, y-100);
context.lineTo(x-200,y+100);
context.moveTo(x+200, y+100);
context.lineTo(x+200,y-100);
context.moveTo(x-200, y+100);
context.lineTo(x,y+50);
context.moveTo(x+200, y+100);
context.lineTo(x,y+50);
context.stroke();<!--for the drawing of line stroke is required-->
context.font = "20px Arial";
context.fillText("(x-200,y-100)",x-260,y-110);
context.fillText("(x-200,y+100)",x-260,y+120);
context.fillText("(x+200,y-100)",x+150,y-110);
context.fillText("(x+200,y+100)",x+150,y+120);
context.font = "28px Arial";
context.fillText("x,y represents centre of the canvas",x-215,y-190);
context.fillText("moveTo(x-200,y-100)",x-350,y+170);
context.fillText("bezierCurveTo(x-200, y+100, x+200, y+100,x+200,y-100)",x-350,y+210);
</script>
</body>
</html>
Sunday, 15 April 2018
quadraticCurve in Canvas
<!DOCTYPE HTML>
<html>
<body>
<canvas id="myCanvas" width="800" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
context.strokeStyle = 'red';
<!--Setting of color of arc-->
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
context.beginPath();
context.moveTo(x-100, y-100);
context.quadraticCurveTo(x-100, y+100, x+200, y-200);
context.lineWidth = 10;
context.strokeStyle = 'green';
context.stroke();
context.lineWidth = 2;
context.moveTo(x-100, y-100);
context.lineTo(x-100,y+100);
context.moveTo(x-100, y+100);
context.lineTo(x+200,y-200);
context.moveTo(x+200, y-200);
context.lineTo(x-100,y-100);
context.stroke();<!--for the drawing of line stroke is required-->
context.font = "20px Arial";
context.fillText("(x-100,y-100)",x-160,y-110);
context.fillText("(x-100,y+100)",x-160,y+120);
context.fillText("(x+200,y-200)",x+150,y-210);
context.font = "30px Arial";
context.fillText("moveTo(x-100,y-100)",x-310,y+170);
context.fillText("quadraticCurveTo(x-100, y+100, x+200, y-200)",x-310,y+210);
</script>
</body>
</html>
Multicolored Rectangle in CANVAS
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="800" height="500" style="border:3px solid #FF00FF;"></canvas>
<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var gradient = ctx.createLinearGradient(0, 0, 200,300);
gradient.addColorStop("0", "magenta");
gradient.addColorStop("0.25", "green");
gradient.addColorStop("0.5", "blue");
gradient.addColorStop("0.75","yellow");
gradient.addColorStop("1.0", "red");
// Fill with gradient
ctx.strokeStyle = gradient;
ctx.lineWidth = 7;
ctx.strokeRect(40,40,700,400);
</script>
</body>
</html>
Filled Semi-Circle in Canvas
<!DOCTYPE HTML>
<html>
<body>
<canvas id="myCanvas" width="800" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
context.strokeStyle = 'red';
<!--Setting of color of arc-->
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
var r = 150; var r1=125;var r2=50;
context.beginPath();
context.arc(x,y+20,r, 0, Math.PI, false);
context.closePath();
context.lineWidth = 5;
context.fillStyle = 'yellow';
context.fill();
context.lineWidth = 5;
context.stroke();
context.beginPath();
context.arc(x,y-20,r1, 0, Math.PI, true);
context.closePath();
context.lineWidth = 5;
context.fillStyle = 'yellow';
context.fill();
context.lineWidth = 5;
context.stroke();
context.beginPath();
context.arc(x,y,r2, 0, 2*Math.PI, true);
context.closePath();
context.lineWidth = 5;
context.fillStyle = 'yellow';
context.fill();
context.lineWidth = 5;
context.stroke();
</script>
</body>
</html>
Filled Circle in CANVAS
<!DOCTYPE HTML>
<html>
<body>
<canvas id="myCanvas" width="800" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
context.strokeStyle = 'red';
<!--Setting of color of arc-->
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
var r = 150;
context.beginPath();
context.arc(x,y,r, 0, 2.0 * Math.PI, false);
context.fillStyle = 'yellow';
context.fill();
context.lineWidth = 5;
context.stroke();
</script>
</body>
</html>
Designing of arc in canvas
<!DOCTYPE HTML>
<html>
<body>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #FFFF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
context.strokeStyle = 'red';
<!--Setting of color of arc-->
var x = canvas.width / 2;<!--center of x axis-->
var y = canvas.height / 2;<!--center of y axis-->
var r = 100;
var st = 0 * Math.PI;
var end = 1.0 * Math.PI;
var cc = false;
context.beginPath();
context.arc(x, y, r, st, end, cc);
<!--centre,radius,start angle,end angle and cc means counter clockwise-->
context.lineWidth = 7;
<!--setting of line width-->
context.stroke();<!--stroke is used to draw arc-->
context.strokeStyle = 'green';
<!--Setting of color of arc-->
var r1 = 120;
var st1 = 0 * Math.PI;
var end1 = 1.0 * Math.PI;
var cc1 = true;
context.beginPath();
context.arc(x, y, r1, st1, end1, cc1);
<!--centre,radius,start angle,end angle and cc means counter clockwise-->
context.lineWidth = 7;
<!--setting of line width-->
context.stroke();<!--stroke is used to draw arc-->
</script>
</body>
</html>
Round Cap Line in Canvas
<!DOCTYPE HTML>
<html>
<body>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #00FF00;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
context.strokeStyle = "#FF00FF";
<!--Setting of color of lines-->
context.lineCap = 'round';
context.lineWidth = 20;
context.beginPath();<!--To start a line beginpath is required-->
context.moveTo(100, 100);<!--Starting point of line in canvas-->
context.lineTo(400, 400);<!--End point of line in canvas-->
context.stroke();<!--for the drawing of line stroke is required-->
</script>
</body>
</html>
Designing of Line in CANVAS
<!DOCTYPE HTML>
<html>
<body>
<canvas id="myCanvas" width="500" height="500" style="border:3px solid #00FFd3;"></canvas>
<!--Setting of size of Canvas-->
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
context.strokeStyle = "#FF0000";
<!--Setting of color of lines-->
context.beginPath();<!--To start a line beginpath is required-->
context.moveTo(100, 100);<!--Starting point of line in canvas-->
context.lineTo(400, 100);<!--End point of line in canvas-->
context.moveTo(400, 100);
context.lineTo(400, 400);
context.moveTo(400, 400);
context.lineTo(100, 100);
context.moveTo(100, 400);
context.lineTo(400, 100);
context.stroke();<!--for the drawing of line stroke is required-->
</script>
</body>
</html>
Open multiple files for reading and writing purposes using C++
//open multiple files for
//reading and writing purposes
#include<fstream.h>
#include<conio.h>
void main()
{
clrscr();
ofstream out;
//writing data
out.open("months");//opens file
out<<"March\n"; //writes string to the file
out<<"April\n";
out<<"May\n";
out.close();//closes the file
out.open("days");//opens another file
out<<"31\n";
out<<"30\n";
out<<"31\n";
out.close();//closes second file
//reading data
char text[20];
ifstream in;
in.open("months"); //opens file for reading
cout<<"\nMonths are\n";
while(in)
{
in.getline(text,20);
cout<<text<<"\n";
}
in.close();
in.open("days");
cout<<"\nDays are\n";
while(in)
{
in.getline(text,20);
cout<<text<<"\n";
}
in.close();
getch();
}
Write and Read Text in a File using C++
//Write and Read Text in a FILE
#include<fstream.h>
#include<conio.h>
void main()
{
clrscr();
char name[15];
int age;
ofstream out("text1");
cout<<"\nName:";
cin>>name;
cout<<"\nAge:";
cin>>age;
out<<name<<"\t";
out<<age<<"\n";
out.close();//File is closed
ifstream in("text1");
in>>name;
in>>age;
cout<<"\nName:"<<name<<"\n";
cout<<"Age:"<<age;
in.close();
getch();
}
Read data from file using C++
//read data from the file
//using object of ifstream class
#include<fstream.h>
#include<conio.h>
void main()
{
clrscr();
char *n;
ifstream in("text");//opens a file in read mode
in>>n; //reads string from file
cout<<n<<" "; //display string to the console
in>>n;
cout<<n<<" ";
in>>n;
cout<<n<<" ";
in>>n;
cout<<n<<" ";
in>>n;
cout<<n<<" ";
in>>n;
cout<<n<<" ";
in>>n;
cout<<n<<" ";
getch();
}
Friday, 13 April 2018
4 Patterns in CG
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,x,y,i,j;
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
x=getmaxx()/2;y=getmaxy()/2;
settextstyle(3,0,2);
for(i=0;i<=625;i=i+10)
{
outtextxy(x,10+i,"|");
outtextxy(10+i,y,"-");
}
setcolor(YELLOW);
for(i=0;i<=(x-20);i=i+20)
{
for(j=0;j<=(y-20);j=j+20)
{
outtextxy(20+i,20+j,"*");
outtextxy(x+20+i,20+j,"@");
outtextxy(20+i,y+20+j,"&");
outtextxy(x+20+i,y+20+j,"#");
}
}
getch();
closegraph();
}
Virtual Keyword in CPP
//Use of Virtual Keyword in CPP
#include<iostream.h>
#include<conio.h>
class A
{
protected:
int a;
};
class B:public virtual A
{
protected:
int b;
};
class C:public virtual A
{
protected:
int c;
};
class D:public virtual A
{
protected:
int d;
};
class E:public virtual B,public virtual C
{
protected:
int e;
};
class F:public virtual C,public virtual D
{
protected:
int f;
};
class G:public E,F
{
private:
int g;
public:
void getdata()
{
cout<<"Enter 7 values\n";
cin>>a>>b>>c>>d>>e>>f>>g;
}
void showdata()
{
cout<<"\nFirst value="<<a;
cout<<"\nSecond value="<<b;
cout<<"\nThird value="<<c;
cout<<"\nFourth value="<<d;
cout<<"\nFifth value="<<e;
cout<<"\nSixth value="<<f;
cout<<"\nseventh value="<<g;
}
};
void main()
{
clrscr();
G x;
x.getdata();
x.showdata();
getch();
}
More on Date and Time Formats
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
t1.Text = Format(Now, "M")
t2.Text = Format(Now, "MM")
t3.Text = Format(Now, "MMM")
t4.Text = Format(Now, "MMMM")
t5.Text = Format(Now, "dd/MM/yyyy")
t6.Text = Format(Now, "MMM,d,yyyy")
t7.Text = Format(Now, "h:mm:ss tt")
t8.Text = Format(Now, "MM/dd/yyyy h:mm:ss tt")
End Sub
End Class
Date and Time Formats in VB 2010
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txt1.Text = Format(Now, "General Date")
txt2.Text = Format(Now, "Long date")
txt3.Text = Format(Now, "Short Date")
txt4.Text = Format(Now, "Long Time")
txt5.Text = Format(Now, "Short Time")
End Sub
End Class
Thursday, 12 April 2018
Wednesday, 11 April 2018
Harmonic Series in JAVA
import java.util.Scanner;
public class HarmonicSeries
{
public static void main(String arg[])
{
Scanner sc=new Scanner(System.in);
double sum=0,i=1,n;
System.out.println("Enter any integer value");
n=sc.nextDouble();
while(i<=n)
{
sum=sum+1/i;
i++;
}
System.out.println("Sum of the series="+sum);
}
}
ArrayList in JAVA
import java.util.*;
public class ArrayListExp
{
public static void main(String args[])
{
ArrayList <String> obj=new ArrayList <String>();
obj.add("Honey");
obj.add("Sukhvir");
obj.add("Monu");
obj.add("Inder");
obj.add("Sonu");
obj.add("Preet");
obj.add("Hi");
obj.add("xyz");
System.out.println("Array Elements are:"+obj);
obj.add(4,"Doraha");
obj.remove("Preet");
System.out.println("Now Array Elements are:"+obj);
obj.remove(6);
System.out.println("Now Array Elements are:"+obj);
obj.set(6,"TOM");
System.out.println("Now Array Elements are:"+obj);
int pos=obj.indexOf("TOM");
System.out.println("Index of TOM is:"+pos);
int NOI=obj.size();
System.out.println("No of Items:"+NOI);
System.out.println("SS in the array is present or not:"+obj.contains("SS"));
}
}
Palindrome Number in JAVA
import java.util.Scanner;
public class Palindrome2
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int r,sum=0,temp;
int n;
System.out.println("Enter any positive integer value");
n=sc.nextInt();
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
System.out.println("palindrome number ");
else
System.out.println("not palindrome");
}
}
Subscribe to:
Posts (Atom)