Thursday, January 31, 2013
Wednesday, January 30, 2013
Code for Program to rotate about reference point in C++ Programming
Code for Program to rotate about reference
point in C++ Programming
# include <iostream.h>
# include <conio.h>
# include <graphics.h>
# include <math.h>
char IncFlag;
int PolygonPoints[4][2] =
{{10,100},{110,100},{110,200},{10,200}};
int RefX = 10;
int RefY = 100;
void PolyLine()
{
int
iCnt;
cleardevice();
line(0,240,640,240);
line(320,0,320,480);
for
(iCnt=0; iCnt<4; iCnt++)
{
line(PolygonPoints[iCnt][0],PolygonPoints[iCnt][1],
PolygonPoints[(iCnt+1)%4][0],PolygonPoints[(iCnt+1)%4][1]);
}
}
void Translate(int Direction)
{
int
iCnt;
for
(iCnt=0; iCnt<4; iCnt++)
{
PolygonPoints[iCnt][0] += Direction*RefX;
PolygonPoints[iCnt][1] -= Direction*RefY;
}
}
void Rotate()
{
float
Angle;
int
iCnt;
int
Tx,Ty;
Translate(-1);
cout<<endl;
Angle
= 30.0*(22.0/7.0)/180.0;
for
(iCnt=0; iCnt<4; iCnt++)
{
Tx = PolygonPoints[iCnt][0];
Ty = PolygonPoints[iCnt][1];
PolygonPoints[iCnt][0] = (Tx - 320)*cos(Angle) -
(Ty - 240)*sin(Angle) +
320;
PolygonPoints[iCnt][1] = (Tx - 320)*sin(Angle) +
(Ty - 240)*cos(Angle) +
240;
}
Translate(1);
}
void main()
{
int
gDriver = DETECT, gMode;
int
iCnt;
initgraph(&gDriver, &gMode, "C:\\TC\\BGI");
for
(iCnt=0; iCnt<4; iCnt++)
{
PolygonPoints[iCnt][0] += 320;
PolygonPoints[iCnt][1] = 240 - PolygonPoints[iCnt][1];
}
PolyLine();
getch();
Rotate();
PolyLine();
getch();
Friday, January 25, 2013
Cascading Style Sheet inline & internal example
<!--Example of Cascading Style Sheet with inline & internal....fensasaj@blogspot.com-->
<html>
<head>
<style>
body
{
background-color:lightblue;
}
h1
{
color:red;
text-align:center;
}
h4
{
text-align:left;
background-color:pink;
color:green;
}
p
{
font-family:"Palace Script MT";
font-size:70px;
color:blue;
}
</style>
</head>
<body>
<h1>WELCOME</h1>
<h4>Log onto e-mail</h4>
<p>This is first page...........................
Welcome to first page...........................
Keep trying.....................................
</p>
</body>
</html>
Validation of Username and Password
<!--Validation of Username and Password........fensasaj@blogspot.com-->
<html>
<head>
</head>
<body bgcolor="cyan">
<form>
<h3 align="center">username<input type="text" name="userid"/>
</h3>
<br>
<h3 align="center">password<input type="password" name="password"/>
</h3>
<br>
<input type ="button" onclick="check(this.form)" value="submit"/>
<input type="reset" value="reset"/>
</form>
<script language="javascript">
function check(form)
{
if(form.userid.value=="lbs"&&form.password.value=="it")
{
document.write("Welcome lbs!!");
}
else
{
alert("you are a wrong user");
}
}
</script>
</body>
</html>
Calculator using Javascript
<!--Creating Calculator using Javascript....fensasaj@blogspot.com-->
<html>
<head>
<script type="text/javascript">
function pushButton(buttonValue) {
if (buttonValue == 'C') {
document.getElementById('screen').value = '';
}
else {
document.getElementById('screen').value += buttonValue;
}
}
function calculate(equation) {
var answer = eval(equation);
document.getElementById('screen').value = answer;
}
</script>
</head>
<body>
<style type="text/css">
table.calc {
border: 2px solid #0034D1;
background-color: #809FFF;
}
input.calc {
width: 100%;
margin: 5px;
}
</style>
<fieldset>
<legend>Calculator</legend>
<table class="calc" cellpadding=4>
<tr><td colspan=3><input class="calc" id="screen" type="text"></td></tr>
<tr>
<td><input class="calc" type="button" value=1 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=2 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=3 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='/' onclick="pushButton(this.value);"></td>
</tr>
<tr>
<td><input class="calc" type="button" value=4 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=5 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=6 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='*' onclick="pushButton(this.value);"></td>
</tr>
<tr>
<td><input class="calc" type="button" value=7 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=8 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value=9 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='-' onclick="pushButton(this.value);"></td>
</tr>
<tr>
<td><input class="calc" type="button" value=0 onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='.' onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='C' onclick="pushButton(this.value);"></td>
<td><input class="calc" type="button" value='+' onclick="pushButton(this.value);"></td>
</tr>
<tr><td colspan=3><input class="calc" type="button" value='=' onclick="calculate(document.getElementById('screen').value);"></td></tr>
</table>
</body>
</html>
Online QUIZ using Javascript
<!--ONLINE QUIZ example ......fensasaj@blogspot.com.-->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
var ans = new Array;
var done = new Array;
var score = 0;
ans[1] = "c";
ans[2] = "a";
ans[3] = "b";
ans[4] = "b";
ans[5] = "d";
function Pop(question, answer) {
if (answer != ans[question]) {
if (!done[question]) {
done[question] = -1;
alert("Wrong! and Your score is now: " + score);
}
else {
alert("You have already answered that!");
}
}
else {
if (!done[question]) {
done[question] = -1;
score++;
alert("Correct!and Your score is now: " + score);
}
else {
alert("You have already answered that!");
}
}
}
function NextLevel () {
if (score > 5) {
alert("Cheater!");
}
if (score >= 3 && score <= 6) {
alert("Access permitted! But there are no more levels if you don't make any ...")
//change previous line to: self.location="js_misc_userquiz2.html" if you make more
}
else {
alert("Access denied! You need 3 points to enter the next level.")
}
}
</SCRIPT>
<BODY>
<font size=7 face=Arial>Online Quiz</font><br><p>
<b>Objective: answer 3 questions correctly. JavaScript required!</b><p>
<noscript>JavaScript is <b><i>disabled</b></i>. Get Netscape 3.0 or turn it on!</noscript>
<hr noshade>
<FORM>
<b>1. Which is the capital of <i>Canada</i>?</b><p>
<input type=radio value="a" onClick="Pop(1, this.value)">Doha<br>
<input type=radio value="b" onClick="Pop(1, this.value)">Canbera<br>
<input type=radio value="c" onClick="Pop(1, this.value)">Ottawa<br>
<input type=radio value="d" onClick="Pop(1, this.value)">Vienna<p>
<b>2. Where is the head quarters of <i>UNESCO</i>?</b><p>
<input type=radio value="a" onClick="Pop(2, this.value)">Paris<br>
<input type=radio value="b" onClick="Pop(2, this.value)">Switzerland<br>
<input type=radio value="c" onClick="Pop(2, this.value)">Brazil<br>
<input type=radio value="d" onClick="Pop(2, this.value)">Delhi<p>
<b>3. Which is the first country to introduce currency notes ?</b><p>
<input type=radio value="a" onClick="Pop(3, this.value)">India<br>
<input type=radio value="b" onClick="Pop(3, this.value)">China<br>
<input type=radio value="c" onClick="Pop(3, this.value)">Pakisthan<br>
<input type=radio value="d" onClick="Pop(3, this.value)">Sri Lanka<p>
<b>4. Who is the first Indian Nobel Laurette?</b><p>
<input type=radio value="a" onClick="Pop(4, this.value)">Amartya Sen<br>
<input type=radio value="b" onClick="Pop(4, this.value)">Rabindra Nath Tagore<br>
<input type=radio value="c" onClick="Pop(4, this.value)">Indira Gandhi<br>
<input type=radio value="d" onClick="Pop(4, this.value)">Mother Theresa<p>
<b>5. Who invented Radio? </b><p>
<input type=radio value="a" onClick="Pop(5, this.value)">Edison<br>
<input type=radio value="b" onClick="Pop(5, this.value)">Bell<br>
<input type=radio value="c" onClick="Pop(5, this.value)">Newton<br>
<input type=radio value="d" onClick="Pop(5, this.value)">Marcony<p>
<CENTER>
<input type=button onClick="NextLevel()" value="Advance to next level">
</CENTER>
</FORM>
Subscribe to:
Posts (Atom)