This program will ask user to input 10 names that will be array of strings and then user has to press a down arrow key or up arrow key to scroll down or upwards. If users presses a down arrow key then name will be scroll one by one on the screen. If user presses up arrow key then previous name will be displayed on the screen. If last name is displayed and users presses again down arrow key then beep sound will be generated and then noscrolling will be there. Same way if users is already at first name and if he presses up arrow key then also beep sound will be generated and no scrolling will occured.
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<process.h>
main()
{
clrscr();
char name[10][10];
for (int i=0;i<=9;i++)
{
cout <<"enter any name";
cin >> name[i];
}
clrscr();
int ch;
i=0;
while(1)
{
ch = getch();
if (ch==65)
{
break;
}
if (i==-1)
{
i=0;
sound(700);
delay(100);
nosound();
}
if (i==10)
{
i=9;
sound(700);
delay(100);
nosound();
}
if (ch==80 && i>=0 && i<=10 && ch!=0)
{
gotoxy(50,12);
cout << name[i]<<" ";
name[++i];
}
if (ch==72 && i>=0 && i<=10 && ch!=0)
{
gotoxy(50,12);
cout << name[i]<<" ";
name[--i];
}
}
getch();
}
Jun 13, 2007
C++ Program to scroll names by arrow keys
Jun 12, 2007
C++ program to controle an object through keyboard
// C++ program to draw a circle on the screen and controlling it
// through keyboard by direction keys.
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<graphics.h>
#include<stdlib.h>
class snake{
int x,y;
int randx,randy;
public :
int success;
snake()
{
int dv,mo;
x=320;y=240;
success=0;
dv = DETECT;
initgraph(&dv,&mo,"");
circle(x,y,4);
randomize();
nextPoint();
}
~snake(){
getch();
closegraph();}
moveUp()
{cleardevice();
y -= 1;
circle(x,y,4);
if (x==randx & y==randy)
{randx=1+random(639);
randy=1+random(479);}
nextPoint();}
moveLeft(){
cleardevice();
x -= 1;
circle(x,y,4);
if (x==randx & y==randy)
{
randx=1+rand()%639;
randy=1+rand()%479;
}
nextPoint();
}
moveRight()
{
cleardevice();
x += 1;
circle(x,y,4);
if (x==randx & y==randy)
{
randx=1+random(639);
randy=1+random(479);}
nextPoint();}
moveDown()
{
cleardevice();
y += 1;
circle(x,y,4);
if (x==randx & y==randy)
{
randx=1+random(639);
randy=1+random(479);}
nextPoint();
}
nextPoint()
{
circle(randx,randy,1);}
};
//snake dj(5);
snake dj;
main()
{
while(!0)
{
int tch=getch();
int ch=getch();
cout <<tch<<" "<< ch;
if (ch==72) dj.moveUp();
if (ch==75) dj.moveLeft();
if (ch==77) dj.moveRight();
if (ch==80) dj.moveDown();
}
}
Jun 7, 2007
C++ Program to Generate Series 1 11 111 1111............
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
float k=1;
float a=k;
for (int i=1;i<=8;i++)
{
cout << a <<endl;
k = k*10;
a=a+k;
}
getch();
}
Series 1 11 111 1111............
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
float k=1;
for (int i=1;i<=8;i++)
{
cout << k <<endl;
k = k*10+1;
}
getch();
}
C++ Program To Generate this Series: 1 10 100 1000 10000 100000
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
float k=1;
for (int i=1;i<=8;i++)
{
cout << k <<endl;
k = k*10;
}
getch();
}
Jun 6, 2007
C++ program to draw and move a circle on the screen
// C++ program to draw and move a circle on the screen (up and down). when hit any key from the keyboard circle will stop moving and program ends if you don't press any key from the keyboard circle will move on the screen infinite times. Here in this program kbhit() function is
used. it checks for the keyboard keystroke.
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
main()
{
clrscr();
int driver,mode;
driver = DETECT;
initgraph(&driver,&mode,"");
while (!kbhit())
{
for (int i=1;i<=400; i++)
{
circle(300,i,10);
delay(10);
cleardevice();
}
for ( i=400;i>=1; i--)
{
circle(300,i,10);
delay(10);
cleardevice();
}
}
}
Jun 5, 2007
C++ program
//C++ program that will take input an integer for the month and displays users season (Indian season) name according to the input
#include<iostream.h>
#include<conio.h>
main()
{
clrscr();
int m;
cout <<"enter any months";
cin >> m;
if (m==12 || m==1 || m==2)
{
cout << "It is a winter season" <<endl;
}
if (m==3 || m==4 || m==5 || m==6)
{
cout << "It is a summer season";
}
if (m==7 || m==8 || m==9)
{
cout <<"It is a rainy season";
}
if (m==10 || m==11)
{
cout << "It is an autumn";
}
getch();
}
Jun 4, 2007
Multithreading in Java:
{
Thread t;
mt()
{
t = new Thread(this, "Demo thread");
t.start();
}
public void run()
{
try
{
for(int i=1;i<=10;i++)
{
System.out.println(i);
t.sleep(1000);
}
}
catch(InterruptedException e)
{
System.out.println("Thread is interrupted");
}
}
};
class th
{
public static void main(String[] args)
{
mt t = new mt();
try
{
for (int i=2;i<=20;i=i+2)
{
System.out.println(i);
Thread.sleep(500);
}
}
catch(InterruptedException e)
{
}
}
}
Jun 3, 2007
JAVA PROGRAM TO DEMONSTRATE MARKSHEET CALCULATIONS
class markproject
{
int h,e,p,c,m,totmark,percentage;
int add(int h,int e,int p,int c,int m)
{
totmark = h+e+c+p+m;
return totmark;
}
void per()
{
percentage = totmark/5;
}
void grade()
{
if (percentage>=45 && percentage<60)
{
System.out.println("Grade is C");
}
if (percentage>=60 && percentage<=80)
{
System.out.println("Grade is a");
}
if (percentage>=80 && percentage<=100)
{
System.out.println("Grade is a+");
}
}
};
class mark
{
public static void main(String[] args)
{
markproject mp1;
mp1 = new markproject();
int totmark=mp1.add(55,65,75,85,95);
System.out.println(totmark);
mp1.per();
System.out.println(mp1.percentage);
mp1.grade();
}
}
Jun 2, 2007
HOW TO FORMAT NOKIA 6600
If you have been facing some problem in your NOKIA 6600 handset like hanging, slowing so you need to format the handset.
Warning: All data will be lost in your mobile handset if you format the phone so take backup of your important data before doing these.
Disclaimer: If you damage something in your phone while doing this trick, there will be no responsibility of blogger or poster. Do all at your own risk
Note: Make sure before formatting the NOKIA 6600, battery is full charged and there is no memory (MMC card) and SIM card in the handset.
Step 1: Switch off your 6600 Handset.
Step 2: Press and hold these keys simultaneously *, 3, Left Green Key, Power On/ Off switch. If you make some delay before pressing these keys, format function wont start. Progress indicator would display formatting. Wait when formatting is being done.
Step 3: When formatting is done. Phone would automatically get started and you are done.
Step 4: Restore your important data into phone.
Single Dimensional Array in JAVA:
class arrdemo
{
public static void main(String[] args)
{
int marks[]; // array declaration that array would be of integer type
marks =new int[5]; // new operator will allocates memory to the array
int tot=0;
for (int i=0;i<=4 ;i++ )
{
marks[i] = i; // storing values in array elements
}
for (int i=0;i<=4 ;i++ ) // printing value of array elements.
{
System.out.println(marks[i]);
}
for (int i=0;i<=4;i++ )
{
tot = marks[i] + tot; // adding array elements
}
System.out.println("Addition of array elements is="+tot);
for (int i=4;i>=0 ;i-- )
{
System.out.println(marks[i]); // printing value of array elements in reverse order
}
}
}
Jun 1, 2007
Inheritance in JAVA
class a // superclass
{
void add()
{
int a,b,c;
a=10;
b=20;
c=a+b;
System.out.println(c);
}
};
// creating a subclass
class b extends a
{
void sub()
{
int a,b,c;
a=10;
b=20;
c=a-b;
System.out.println(c);
}
};
class demo
{
public static void main(String[] args)
{
b b1; // by object of subclass we can access member of superclass.
b1 = new b();
b1.add();
b1.sub();
}
}