Skip to main content

Posts

Showing posts from 2014

C program for menu driven calculator

#include<stdio.h> #include<conio.h> float add(float, float); float sub(float, float); float div(float, float); float pro(float, float); float num1, num2, res; char oper, ext='n'; void main(){ clrscr(); while(ext!='Y' && ext!='y'){ printf("\n*****MENU*****\nOperations to perform: +, -, / & *\nEnter Operation: "); oper=getche(); printf("\nEnter two numbers:\n"); scanf("%f%f", &num1, &num2); switch(oper){ case '+': res=add(num1, num2); break; case '-': res=sub(num1, num2); break; case '/': res=div(num1, num2); break; case '*': res=pro(num1, num2); break; default: printf("invalid Operation!\n"); } printf("%f %c %f = %f\n", num1, oper, num2, res); printf("Do you want to exit (Y/N): "); ext=getche(); } } float add(float n1, float n2){ return n1...

Free Web hosting

Looking for a free web hosting site? If you are looking for a free web hosting site which supports PHP & MySQL, you can visit this site called hostinger.com You will get free website builder. You can install over 100 PHP applications for free. You can manage your files with cPanel file manager or with another file manager. You can easily change htaccess file. You can create E-mail accounts with custom mailbox size. You can add upto two domains under free hosting service. You can password protect any important directory. And much more.

Vanilla script

This function gets the cookie specified:- function gcook(cookieName) {         /**          * This variable holds the array of available cookies          */         var cookies = document.cookie.split(";");         cookieName += "=";         for (var i = 0; i < cookies.length; i++) {             var c = cookies[i].trim();             if (c.indexOf(cookieName) == 0) {                 /**                  * This statement retrieves the value of the specified cookie        ...

Java Applet MouseListener example

import java.applet.*; import java.awt.*; import java.awt.event.*; public class MouseEventHandle extends Applet implements MouseListener{ String message="\0"; int Xcoordinate=0, Ycoordinate=20; public void mouseClicked(MouseEvent e){ message="Mouse Clicked Event"; repaint(); } public void mouseEntered(MouseEvent e){ message="Mouse Entered Event"; repaint(); } public void mouseExited(MouseEvent e){ message="Mouse Exited Event"; repaint(); } public void mousePressed(MouseEvent e){ message="Mouse Pressed Event"; repaint(); } public void mouseReleased(MouseEvent e){ message="Mouse Released Event"); repaint(); } public void mouseMoved(MouseEvent e){ message="Mouse Moved Event"; showstatus(message); } public void paint(Graphics g){ g.drawString(message, Xcoordinate, Ycoordinate); } }

Java Applet KeyListener example

import java.appleat.*; import java.awt.*; import java.awt.event.*; public class KeyListenerExample extends Applet implements KeyListener{ String pstr="This is your KeyListener class example"; public void init(){ addKeyListener(this); } public void keyPressed(KeyEvent e){ showstatus("You have pressed a key"); } public void keyReleased(KeyEvent e){ showstatus("You have released the key"); } public void paint(Graphics g){ g.drawString(pstr, 20, 40); } public void keyTyped(KeyEvent e){ repaint(); } }

Java applet passing values using parameters example

import java.applet.*; public class ParameterExample extends Applet{ String str; int a, b, sum; public void init(){ pstr=getParameter("msg"); a=Integer.parseInt(getParameter("first")); b=Integer.parseInt(getParameter("second")); sum=a+b; repaint(); } public void paint(Graphics g){ g.drawString("First Number: "+a, 20, 40); g.drawString("Second Number: "+b, 20, 60); g.drawString("Sum: "+sum, 20, 80); } } HTML:- <html> <head> <title>Java Applet</title> </head> <body> <applet code="ParameterExample.class" width="600" height="250"> <param name="msg" value="Add"/> <param name="first" value="52"/> <param name="second" value="87"/> </applet> </body> </html>

C++ program to perform addition and multiplication using inheritance

#include<iostream.h> #include<conio.h> class a{ public: int no1, no2; void put(); }; void a::put(){ cout<<"Enter two numbers:-"<<endl; cin>>no1>>no2; } class b:public virtual a{ public: int sum; void add(); }; void b::add(){ sum=no1+no2; } class c:public virtual a{ public: int pro; void multiply(); }; void c::multiply(){ pro=no1*no2; } class d:public b, public c{ public: display(); }; void d::display(){ cout<<"Sum: "<<sum<<"\nProduct: "<<pro<<endl; } void main(){ d obj(); clrscr(); d.put(); d.add(); d.multiply(); d.display(); getch(); }

C++ program to swap the values of four variables without using fifth variable

#include<iostream.h> #include<conio.h> int a, b, c, d; void main(){ clrscr(); cout<<"Enter four numbers:"<<endl; cin>>a>>b>>c>>d; a=a+b+c+d; b=a-b-c-d; c=a-b-c-d; d=a-b-c-d; a=a-b-c-d; cout<<"Before swapping the values:- "<<endl<<"A:"<<a<<endl<<"B:"<<b<<endl<<"C:"<<c<<endl<<"D:"<<d<<endl<<"After swapping the values:-"<<endl<<"A:"<<a<<endl<<"B:"<<b<<endl<<"C:"<<c<<endl<<"D:"<<d; getch(); }

C++ program declaring class & object

#include<iostream.h> #include<conio.h> #include<iomanip.h> class Student{ private: char a[5][10]; int r[5], c[5], f[5], i; public: void input(); void display(); }; void Student::input(){ cout<<"Enter Name, Class, Roll Number & Fee of five students"<<endl; for(i=0; i<5; i++){ cout<<(i+1)<<". Student:"<<endl; cin>>a[i]>>c[i]>>r[i]>>f[i]; } } void Student::display(){ cout<<"Name"<<setw(25)<<"Class"<<setw(25)<<"Roll Number"<<setw(25)<<"Fee"<<endl; for(i=0; i<5; i++){ cout<<a[i]<<setw(25)<<c[i]<<setw(25)<<r[i]<<setw(25)<<f[i]<<endl; } } void main(){ Student obj; clrscr(); obj.input(); obj.display(); getch(); }

JQuery dragaable example

<html>     <head>         <title>Draggable</title>         <script src="jquery.js"></script>         <script src="jquery-ui.js"></script>         <style>             #draggable{                 width: 150px;                 height: 150px;                 padding: 0.5em;             }         </style>         <script>          ...

PHP create an image with custom text, background and foreground colors

PHP code:- <?php header("Content-Type: image/png"); $size = NULL; $x = NULL; $height = NULL; $y = NULL; /* $fonts = array("font.ttf", "font bd.ttf");   shuffle($fonts);   $font = $fonts[0]; */ $font = "font.ttf"; if (!isset($_GET["favicon"]) && !isset($_GET['image-min'])) {     $width = NULL;     if (isset($_GET["width"]))         $width = $_GET["width"];     if ($width > 920) {         $size = 100;         $height = 110;     } elseif ($width < 920 && $width > 750) {         $size = 50;         $height = 60;     } elseif ($width < 750 && $width > 550) {         $size = 30;         $height = 40; ...

Java program to perform binary addition

import java.util.*; public class BinaryAddition {     private Scanner scan;     private String num1, num2, binary;     public BinaryAddition() {         scan = new Scanner(System.in);         num1 = num2 = binary = "";     }     public void input() {         try {             System.out.printf("Enter First Number: ");             num1 = scan.next();             if (!isBinary(num1)) {                 System.err.printf("Binary Number Expected.");                 System.exit(0);    ...

Java program to print fibonacci series in reverse order

import java.util.*; public class FabonicRev {     Scanner scan;     int a1, b1, c1, a2, b2, c2, limit, i;     public FabonicRev() {         scan = new Scanner(System.in);         a1 = c1 = 1;         b1 = a2 = b2 = c2 = limit = i = 0;     }     public void input() {         try {             System.out.printf("Enter limit: ");             limit = scan.nextInt();             scan.close();         } catch (InputMismatchException | NumberFormatException e) {             System.err.println("Error Occurred!");   ...

Java program to perform number system conversions

import java.util.*; interface ConversionBase {     Scanner scan = new Scanner(System.in);     byte bin = 2, dec = 10, hex = 16, oct = 8;     char hex1[] = new char[]{'A', 'B', 'C', 'D', 'E', 'F'};     int hex2[] = new int[]{10, 11, 12, 13, 14, 15}; } class Number implements ConversionBase {     String nm;     char ch;     long num;     byte base;     int i;     public Number() {         nm = "\0";         ch = '\0';         num = i = base = 0;     }     public boolean isBinary(long num) {         nm = Long.toString(num);         for (; i < nm.length(); i++) {             ch ...