#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
void main()
{ clrscr();
char str1[500],str2[500];
char substr1[50][50],substr2[50][50];
for(int l=0;l<50;l++)
{ strcpy(substr1[l],"");
strcpy(substr2[l],"");
}
cout<<"enter the first string: ";
gets(str1);
cout<<"enter the second string: ";
gets(str2);
int i=0,index=0,s1index=0;
while(str1[i]!='\0')
{ if(str1[i]==' '||str1[i]=='?'||str1[i]=='.'||str1[i]=='!'||str1[i]=='_')
{ for(int j=index, k=0;j<i;j++,k++)
{ substr1[s1index][k]=str1[j];
}
substr1[s1index][k]='\0';
s1index++;
index=i+1;
}
i++;
}
index=0;
s1index=0;
i=0;
while(str2[i]!='\0')
{ if(str2[i]==' '||str2[i]=='?'||str2[i]=='.'||str2[i]=='!'||str2[i]=='_')
{ for(int j=index, k=0;j<i;j++,k++)
{ substr2[s1index][k]=str2[j];
}
substr2[s1index][k]='\0';
s1index++;
index=i+1;
}
i++;
}
cout<<"repeated words are: ";
i=0;
// for(int g=0;g<5;g++)
// {cout<<substr1[g]<<endl;}
// for(int d=0;d<5;d++)
// {cout<<substr2[d]<<endl;}
while(strcmp(substr1[i],"")!=0)
{ int j=0;
while(strcmp(substr2[j],"")!=0)
{ if(strcmp(substr1[i],substr2[j])==0)
cout<<substr1[i];
j++;
}
i++;
}
getch();
}
- Upinder Singh Dhami
- Bangalore, Karnataka, India
- Extending one hand to help someone has more value rather than joining two hands for prayer
Archives
-
▼
2009
(135)
-
▼
September
(132)
- program to print a random number
- program to remove the first and last occurance of ...
- program of selection sort
- program to reverse a string without using inbuilt ...
- program which show the basics of pointer
- program to count characters, words and lines in th...
- program to count vovels,digits,spaces,consonent an...
- program to sort a string
- program to find the number of substrings in a string
- program of password, where you write your password...
- program of dynamic merge
- program of dynamic sort
- program to toogle a string
- program which convert a float value to the string
- program to show the use of gotoxy
- program of merge sort
- calculate the occurance of a word in the string
- program to find the transpose of a matrix
- program to find the largest number in each row of ...
- program to find the sum of rows of the matrix
- program to find the sum of diagonal elements of th...
- program to sort the array using function
- program of seletion sort
- program to search a number present in number of ti...
- program to find the product of matrix
- program to insert the element in the array
- program for binary search of elements which are al...
- program to show basics of linklist
- program to count number of nodes in the link list
- program to count odd values of node in linklist
- program to search a node by value
- program to search a node by value and place a node...
- program to search a node by value and remove it
- program which domonstrate the use of tree
- program to remove alternate nodesin the link list
- program to reversea link list
- program to search a node by value and replace it w...
- program to remove duplicate nodes from the link list
- program to enter the name and email of students us...
- program to show inserting and deleting from a queue
- program to remove a duplicate node from link list
- program to insert an element in the queue
- program to calculate the roots of fourth order alz...
- program to solve three variable linear equation
- simple program of railway reservation
- program to replace the substring with another subs...
- program to reverse each word of the string
- program to save the output as a bitmap image
- program of sparse matrix
- program to add, sub, mul ,and divide two complex n...
- program to find the area and circumference of circ...
- program to show the basics of inline function in oops
- program to print rectangle without using inbuilt f...
- program to print rectangular bowl without using in...
- program to print 'c graphic' in the lines without ...
- program to print menu without using inbuilt functions
- program of loading
- program of loading 2
- program of moving boundries
- program to print all the ascii values
- program to print a barcode
- program to print a line
- program to print a welcome screen?
- program to demonstrate setfillstyle
- program to select the different background colours
- program which demonstrate the text style
- program to demonstrate line style
- program to demonstrate the size of text
- program to print a baby
- program of loading 1
- program of loading 2
- program to print mickey mouse
- program to print a variable box
- program to print database using moving lights arou...
- program to print menu base in graphics
- program to print menu in very good graphic form
- program to enter the values in student database
- program to enter the values of data of form in box...
- program of main menu
- program which define the pixel of the cursor while...
- program to draw lines on the screen with the help ...
- program of moving 3dimensional rectangle box
- program to show menu with the cursor
- program which takes a number from keyboard and giv...
- program which draw rectangles on the screen with t...
- program of digital switches
- program to show the basics os screen saver
- program of text box
- project of editor(like notepad) in c++
- project of banking
- project of hostel management
- project of three dimensional calculator working wi...
- graphical project of students database
- project of shooting game
- Program to find the factorial of a large number
- Solved Placement papers of different IT companies
- there is a matrix N x N .Its elements consist of e...
- program to convert binary number into decimal numb...
- A string of charater is given.Find the highest occ...
- Two sentences are given and we were required to pr...
-
▼
September
(132)
Two sentences are given and we were required to print the common word in the two sentences. Words were delimited by space, full stop, ? , ! and , . The trick in the question was that common word should be printed only once so if ur first sentence contains two word "how" and second contains "how" then in output how should be printed only once for this u can replace each matched word in second sentence by spaces .
Wednesday, September 23, 2009Posted by Upinder Singh Dhami at Wednesday, September 23, 2009 0 comments
A string of charater is given.Find the highest occurance of a character and display that character. eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE. OUTPUT: E or I,J(if equal occurance)
//to find the charater which is repeated most time in string
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{ clrscr();
char ch;
struct node
{ char info;
node *link;
};
node *start,*q,*p,*r;
start=NULL;
cout<<"enter the string: ";
while((ch=getch())!='\r')
{ cout<<ch;
node *p=new node;
p->info=ch;
if(start==NULL)
{ start=p;
p->link=NULL;
}
else
{ q=start;
while(q->link!=NULL)
{ q=q->link;
}
q->link=p;
p->link=NULL;
}
}
char record[50];
int count[50],idx=0;
for(int i=0;i<50;i++)
{ record[i]=NULL;
count[i]=0;
}
while(start!=NULL)
{ p=start;
ch=start->info;
while(p!=NULL)
{ q=p->link;
if(q->info==ch)
{ p->link=q->link;
delete q;
count[idx]++;
continue;
}
p=p->link;
}
if(count[idx]==count[0])
{ record[idx]=ch;
idx++;
}
if(count[idx]>count[0])
{ count[0]=count[idx];
for(int i=1;i<50;i++)
{ count[i]=0;
record[i]=NULL;
}
idx=0;
record[idx]=ch;
idx++;
}
start=start->link;
}
cout<<"\nmaximum occurance numbers are: ";
i=0;
while(record[i]!=NULL)
{ cout<<record[i]<<", ";
i++;
}
getch();
}
Posted by Upinder Singh Dhami at Wednesday, September 23, 2009 0 comments
program to convert binary number into decimal number in c++
//binary to decimal conversion
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
void main()
{ clrscr();
int num[50];
char ch,st[2];
for(int i=0;i<50;i++)
num[i]=-1;
i=0;
cout<<"enter the binary number: ";
while((ch=getch())!='\r')
{
cout<<ch;
st[0]=ch;
st[1]='\0';
num[i]=atoi(st);
i++;
}
int max=0,sum=0,m=0;
while(num[max]!=-1)
max++;
max--;
cout<<endl<<endl;
while(max>=0)
{ sum=sum+(num[max]*pow(2,m));
max--;m++;
}
cout<<endl<<sum;
getch();
}
Posted by Upinder Singh Dhami at Wednesday, September 23, 2009 0 comments
there is a matrix N x N .Its elements consist of either value =1 or value=0. If there is a any zero in the row, then the output matrix should have all zeroes in that row. If there is a single zero in any column then that column should have all zeroes n the output matrix.
#include<iostream.h>
#include<conio.h>
void main()
{ clrscr();
int mat[50][50],r,c,stack[500],id=0;
for(int i=0;i<500;i++)
stack[i]=-1;
cout<<"enter the number of rows and columns resp: ";
cin>>r>>c;
cout<<"enter the elements: ";
for(i=0;i<r;i++)
{ for(int j=0;j<c;j++)
{ cin>>mat[i][j];
}
}
cout<<"ur entered matrix is: "<<endl;
for(i=0;i<r;i++)
{ for(int j=0;j<c;j++)
{ cout<<mat[i][j]<<" ";
}
cout<<endl;
}
for(i=0;i<r;i++)
{ for(int j=0;j<c;j++)
{ if(mat[i][j]==0)
{ stack[id]=i;
id++;
stack[id]=j;
id++;
}
}
}
int k=0;
while(stack[k]!=-1)
{ for(i=0;i<r;i++)
{ for(int j=0;j<c;j++)
{ mat[(stack[k])][j]=0;
}
mat[i][(stack[k+1])]=0;
}
k+=2;
}
cout<<"after ur operation ur matrix become:\n";
for(i=0;i<r;i++)
{ for(int j=0;j<c;j++)
{ cout<<mat[i][j]<<" ";
}
cout<<endl;
}
getch();
}
Posted by Upinder Singh Dhami at Wednesday, September 23, 2009 0 comments
Solved Placement papers of different IT companies
Monday, September 21, 2009Solved C& C++ technical paper of Nagarro
- A string of charater is given.Find the highest occurance of a character and display that character. eg.: INPUT: AEGBCNAVNEETGUPTAEDAGPE, OUTPUT: E or I,J(if equal occurance)
- Two sentences are given and we were required to print the common word in the two sentences. Words were delimited by space, full stop, ? , ! and , . The trick in the question was that common word should be printed only once so if ur first sentence contains two word "how" and second contains "how" then in output how should be printed only once for this u can replace each matched word in second sentence by spaces
- there is a matrix N x N .Its elements consist of either value =1 or value=0. If there is a any zero in the row, then the output matrix should have all zeroes in that row. If there is a single zero in any column then that column should have all zeroes n the output matrix. write the function to perform these operations
- Program to convert binary number into decimal number in c++
- write a program to check whether the given number was of the form 3^n. ( i.e. 3 to the power n).
- There are two sorted arrays, a1 and a2 of size n1 and size n2 respectively. array a1 is full, array a2 has exactly n1(size of array a1) empty space. Example, a1[]=1234, a2[]=56789_ _ _ _ Write a function to merge these two arrays to form a sorted array without any extra memory use.
- suppose u r given a 4*3 rectangle like (take these values from user) Now u have to calculate the no. of squares in this rectangle like: No. of squares of dimension 1 is 12 No. of squares of dimension 2 is 6 No. of squares of dimension 3 is 2 No. of squares of dimension 4 is 0 Total no. of squares are 20.
Posted by Upinder Singh Dhami at Monday, September 21, 2009 0 comments
Labels: placement
Program to find the factorial of a large number
Thursday, September 10, 2009#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num,i,k,a[200],temp,index,n,x,test;
cout<<"enter the no. of test cases";
cin>>test;
while(test>0)
{
cout<<endl<<"enter the number ";
cin>>num;
k=num;
for(i=0;k>=1;i++)
{
a[i]=k%10;
k=k/10;
}
for(n=1;n<num;n++)
{
temp=0;
for(index=0;index<i;index++)
{
x=a[index]*n+temp;
a[index]=x%10;
temp=x/10;
}
while(temp!=0)
{
a[index]=temp%10;
temp=temp/10;
index++;
i++;
}
}
for(i=index-1;i>=0;i--)
cout<<a[i];
test--;}
clrscr();
cout<<"made by anil";
getch();
}
Posted by Upinder Singh Dhami at Thursday, September 10, 2009 2 comments
Labels: programs of string and pointers
project of shooting game
Tuesday, September 1, 2009#include<iostream.h>
#include<alloc.h>
#include<dos.h>
#include<conio.h>
#include<stdlib.h>;
#include<graphics.h>
void front_page();
void second_page();
void final_page();
long o=0,g=0,a=20;
float v;
char w;
void main()
{ int gde=DETECT,gme;
initgraph(&gde,&gme,"c:\\tc");
mit: //label
front_page();
w=getch();
switch(w)
{ case '1':v=1.2; break;
case '2':v=2.0; break;
case '3':v=5; break;
default: goto mit;
}
cleardevice();
int c=0;
char *h;
second_page();
int maxx,maxy,area,x=580,ch,xdirn=1,ydirn=1;
float y=25;
void *buff;
setcolor(WHITE);
setfillstyle(SOLID_FILL,RED );
circle(605,50,25);
floodfill(605,50,WHITE);
area=imagesize(580,25,630,75);
buff=malloc(area);
getimage(580,25,630,75,buff);
maxx=getmaxx();
maxy=getmaxy();
while(1)
{ putimage(x,y,buff,XOR_PUT);
//delay(0);
y=y+(ydirn*v);
putimage(x,y,buff,XOR_PUT);
if(y>maxy-50||y<20)
{ c=0;
sound(130);
delay(5);
nosound();
ydirn*=-1;
}
int marea,m=98,n=235,ch,mdirn=1,ndirn=1,mn;
int maxm,maxn,narea,buffn;
void *buffe;
setcolor(DARKGRAY);
setfillstyle(SOLID_FILL,DARKGRAY );
rectangle(98,235,105,239);
floodfill(101,237,DARKGRAY);
marea=imagesize(98,235,105,239);
buffe=malloc(marea);
getimage(98,235,105,239,buffe);
maxm=getmaxx();
maxn=getmaxy();
gotoxy(2,10);
int in;
cout<<"BULLETS REMAINING = ";
for(in=0;in<=a-1;in++)
{ cout<<"!";
}
if(kbhit())
{ mn=getch();
char *bul;
if(a==0)
break;
if((mn==115||mn==83) &&c==0)
{ a=a-1;
cout<<0;
sound(9999);
delay(10);
c++;
nosound();
while(m<=maxm)
{ putimage(m,n,buffe,XOR_PUT);
m=m+(mdirn*2);
delay(0);
putimage(m,n,buffe,XOR_PUT);
gotoxy(11,3);
cout<<g;
if(m==maxm-51 && (y<=235 && y+25>=205))
{ g=g+10;
o=g;
sound(2200);
delay(900);
putimage(700,25,buff,XOR_PUT);
nosound();
}
}
}
else
{ if(mn==27)
break;
}
}
}
cleardevice();
final_page();
getch();
closegraph();
}
void front_page()
{ setbkcolor(GREEN);
setcolor(WHITE);
setfillstyle(SOLID_FILL,RED );
circle(505,190,50);
floodfill(505,190,WHITE);
setcolor(BROWN);
line(0,235,35,235);
line(0,235,0,258);
line(35,240,35,235);
line(0,258,35,240);
setfillstyle(1,BROWN);
floodfill(2,240,BROWN);
setcolor(DARKGRAY);
line(35,235,102,235);
line(35,240,35,235);
line(35,240,102,240);
line(102,235,102,240);
setfillstyle(1,DARKGRAY);
floodfill(99,236,DARKGRAY);
arc(35,220,250,310,25);
line(35,242,38,243);
settextstyle(1,0,1);
setcolor(BLUE);
outtextxy(200,300,"MADE BY :- MOHIT VASHISHT");
outtextxy(200,317,"E_MAIL :- mohitvashisht88@yahoo.com");
settextstyle(4,0,5);
outtextxy(200,50,"SHOOTING");
outtextxy(250,120,"GAME");
gotoxy(20,12);
cout<<" 1 : EASY";
gotoxy(20,13);
cout<<" 2 : MEDIUM";
gotoxy(20,14);
cout<<" 3 : TOUGH";
gotoxy(10,16);
cout<<"ENTER THE LEVEL = ";
}
void second_page()
{ setcolor(BROWN);
setbkcolor(YELLOW);
line(0,235,35,235);
line(0,235,0,258);
line(35,240,35,235);
line(0,258,35,240);
setfillstyle(1,BROWN);
floodfill(2,240,BROWN);
setcolor(DARKGRAY);
line(35,235,102,235);
line(35,240,35,235);
line(35,240,102,240);
line(102,235,102,240);
setfillstyle(1,DARKGRAY);
floodfill(99,236,DARKGRAY);
arc(35,220,250,310,25);
line(35,242,38,243);
outtextxy(10,35,"SCORE");
outtextxy(10,50,"FIRE");
outtextxy(50,50,"S");
outtextxy(10,65,"EXIT");
outtextxy(50,65,"esc");
}
void final_page()
{ setcolor(BROWN);
setbkcolor(RED);
for(int x=1;x<=4;x++)
{
clrscr();
setbkcolor(RED);
delay(100);
gotoxy(31,12);
cout<<"YOUR SCORE = "<<o;
sound(2200);
delay(750);
nosound();
}
gotoxy(28,16);
cout<<"PRESS ANY KEY TO EXIT";
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 4 comments
Labels: games
graphical project of students database
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
#include<process.h>
#include<fstream.h>
#include<dos.h>
#include<graphics.h>
#include "c:/tc/file1.cpp"
#include "c:/tc/file2.cpp"
char fname[]="c:/temp1.bin";
class student
{
char name[20],fees[20],rollno[20],e_mail[20];
public:
int input();
void output(int,int);
int compare(char r[]);
};
struct node
{
student info;
node *link;
};
class linklist
{
node * start;
public:
linklist()
{
start=NULL;
}
void file2list();
void list2file();
void insert(student);
void show();
void search();
void delete1();
void modify();
};
void linklist::file2list()
{
ifstream f;
f.open(fname,ios::binary);
student n;
if(f.fail())
{
cout<<"\n FILE COULD NOT BE OPENED:";
return;
}
while(1)
{
f.read((char*)&n,sizeof(n));
if(f.eof())
break;
insert(n);
}
f.close();
}
void linklist::list2file()
{
ofstream f;
f.open(fname,ios::binary);
student n;
node*p=start;
while(p!=NULL)
{
n=p->info;
f.write((char*)&n,sizeof(n));
p=p->link;
}
f.close();
}
int student::input()
{
char s[4][50];
int a;
a=showform(s,4);
if(a==0)
return 0;
else
{
strcpy(rollno,s[0]);
strcpy(name,s[1]);
strcpy(fees,s[2]);
strcpy(e_mail,s[3]);
return 1;
}
}
void student::output(int x,int y)
{
outtextxy(x,y,rollno);
outtextxy(x+100,y,name);
outtextxy(x+200,y,fees);
outtextxy(x+300,y,e_mail);
}
int student::compare(char r[10])
{
if(strcmp(rollno,r)==0)
{
return 1;
}
else
{
return 0;
}
}
void linklist::delete1()
{ char temp[20];
cout<<"Enter the roll no. whose record u want to delete:-> ";
gets(temp);
student n;
node *p,*q;
int i=0;
p=start;
q=p->link;
if(start==NULL)
{ cout<<"Linked list is empty";
getch();
return;
}
while(q!=NULL)
{ n=q->info;
if(n.compare(temp)==1)
{ i++;
p->link=q->link;
q->link=NULL;
delete q;
cout<<"\n\n Record is successfully deleted";
break;
}
p=p->link;
q=q->link;
}
if(i==0)
cout<<"\n\n\n NO RECORD FOUND";
}
void linklist::search()
{
student n;
char k[10];
cout<<"\n ENTER THE ROLL NO THAT U WANT TO SEARCH:";
cin>>k;
int z=0;
node *p=start;
while(p!=NULL)
{
n=p->info;
if(n.compare(k)==1)
{
cout<<"\n RECORD IS FOUND:";
n.output(100,80);
z++;
}
p=p->link;
}
if(z==0)
{
cout<<"\n RECORD IS NOT FOUND:";
}
}
void linklist::insert(student n)
{
node*q=new node;
q->info=n;
q->link=NULL;
if(start==NULL)
{
start=q;
}
else
{
node* p=start;
while(p->link!=NULL)
{
p=p->link;
}
p->link=q;
}
}
void linklist::show()
{
cleardevice();
student n;
node *p=start;
int a=10,b=30;
while(p!=NULL)
{
n=p->info;
n.output(a,b);
b+=30;
p=p->link;
}
}
void linklist::modify()
{
char temp[20];
cout<<"enter the roll no. whose record u want to modify:-> ";
gets(temp);
student n;
node *p,*q;
int i=0;
p=start;
q=p->link;
if(start==NULL)
{ cout<<"\n\n\n Linked list is empty";
getch();
return;
}
while(q!=NULL)
{ n=q->info;
if(n.compare(temp)==1)
{ i++;
cout<<"Privious record is:-> "<<endl;
n.output(100,80);
getch();
cleardevice();
cout<<"\n\n Now enter new record:-> ";
n.input();
q->info=n;
cout<<"\n\n\n\n\n\n\n\n\n\n Record is successfully modify";
break;
}
p=p->link;
q=q->link;
}
if(i==0)
cout<<"\n\n NO RECORD FOUND";
}
void main()
{
int d,m;
d=DETECT;
initgraph(&d,&m,"c:/tc");
student n;
char choice;
linklist l;
l.file2list();
while(1)
{
cleardevice();
choice=mmenu();
cleardevice();
setbkcolor(0);
settextstyle(0,0,0);
switch (choice)
{
case 1:
if(n.input()==1)
{
l.insert(n);
l.list2file();
}
break;
case 2:
l.show();
break;
case 3:
l.search();
break;
case 4:
l.delete1();
l.list2file();
break;
case 5:
l.modify();
l.list2file();
break;
case 6:
exit(0);
}
getch();
}
}
?///////////////////////////////////////////////////////////////////////////////////
//////////////////////////file1////////////////////////////////////////////////////
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<process.h>
int color;
void arrow(int xx,int yy,int color)
{ setcolor(color);
int a[]={xx-50,yy+7,xx-40,yy+7,xx-20,yy+20,xx-40,yy+33,xx-50,yy+33,xx-50,yy+26,xx-40,yy+26,xx-27,yy+20,xx-40,yy+14,xx-50,yy+14,xx-50,yy+7};
drawpoly(11,a);
setfillstyle(1,color);
floodfill(xx-40,yy+10,color);
}
void msetfocus(int l,int r,int t,int b,char s[])
{ arrow(l,t,8);
setcolor(15);
rectangle(l,t,r,b);
setfillstyle(1,15);
floodfill(l+2,t+2,15);
setcolor(6);
outtextxy(l+5,t,s);
}
void mlostfocus(int l,int r,int t,int b,char s[])
{ arrow(l,t,7);
setcolor(7);
rectangle(l,t,r,b);
setfillstyle(1,7);
floodfill(l+2,t+2,7);
setcolor(6);
outtextxy(l+5,t,s);
}
void men(char x[][50],int msize,int hl)
{
int lf,tp,rh,bt;
lf=175;
rh=lf+225;
tp=150;
bt=tp+40;
setcolor(5);
settextstyle(1,HORIZ_DIR,4);
outtextxy(140,60,x[0]);
settextstyle(1,HORIZ_DIR,2);
for(int i=1;i<=msize;i++)
{ if(i==hl)
msetfocus(lf,rh,tp,bt,x[i]);
else
mlostfocus(lf,rh,tp,bt,x[i]);
tp+=40;
bt+=40;
}
}
void getkey(int &j,int &k,int &l)
{ REGS n,m;
m.h.ah=0X00;
int86(22,&m,&n);
j=n.h.ah;
k=n.h.al;
m.h.ah=0X02;
int86(22,&m,&n);
l=n.h.al;
}
int mmenu()
{
settextstyle(1,HORIZ_DIR,2);
setbkcolor(7);
int ac,sc,st,z=1;
char mstr[][50]={"STUDEMT'S DATABASE","INSERT NEW RECORD ","SHOW ALL RECORD","SEARCH A RECORD","DELETE A RECORD ","MODIFY A RECORD","EXIT"};
while(1)
{
men(mstr,6,z);
getkey(sc,ac,st);
/*sound(7);
delay(100);
nosound(); */
if(sc==72 && z>=1)
{
if(z==1)
{ z=6;
continue;
}
z--;
}
else if(sc==80&& z<=6)
{
z++;
if(z==7)
z=1;
}
else if(sc==1)
return 0;
else if(sc==28)
{ return z;
}
}
getch();
}
//////////////////////////////////////////////////////////////////////////
/////////////////////////file2///////////////////////////////////////////
void setfocus(int,int,int,int,char*);
void lostfocus(int,int,int,int,char*);
void lostfocus1(int,int,int,int,char*);
int showform(char str[][50],int n)
{
cleardevice();
int z;
int cur=0,max=0;
int lf=200,rh=320,tp=20,bt=40;
char s1[2],s2[50];
int s,a,p;
strcpy(s2,"");
outtextxy(50,28,"ROLL NO.->");
outtextxy(50,78,"NAME ->");
outtextxy(50,128,"FEE ->");
outtextxy(50,178,"E_MAIL ->");
setfocus(lf,tp,rh,bt,s2);
for(int i=0;i<n;i++)
strcpy(str[i],"");
while(1)
{
getkey(s,a,p);
z=p&4;
if(s==1)
return 0;
else if(z==4 && s==31 )
return 1;
// up arrow key
else if(s==72)
{
if(cur>0)
{
lostfocus1(lf,tp,rh,bt,str[cur]);
lostfocus(lf,tp,rh,bt,str[cur]);
cur--;
strcpy(s2,str[cur]);
tp=tp-50;
bt=tp+20;
}
}
// down arrow key
else if(s==80)
{
if(cur<=max-1)
{
lostfocus1(lf,tp,rh,bt,str[cur]);
lostfocus(lf,tp,rh,bt,str[cur]);
cur++;
strcpy(s2,str[cur]);
tp=tp+50;
bt=tp+20;
}
}
// enter key
else if(a==13)
{
if(strlen(s2)!=0)
{
strcpy(str[cur],s2);
if(max<n-1)
{
max++;
}
if(cur<=max-1)
{
cur++;
lostfocus(lf,tp,rh,bt,s2);
if(cur==max&&max<n-1)
strcpy(s2,"");
else
strcpy(s2,str[cur]);
tp=tp+50;
bt=tp+20;
}
}
}
else
{
if(a==8)
{
//code for backspace key
if(strlen(s2)>0)
s2[strlen(s2)-1]='\0';
}
else
{
// code for any other alphabet
s1[0]=a;
s1[1]='\0';
strcat(s2,s1);
}
}
setfocus(lf,tp,rh,bt,s2);
}
}
// Function to write the string in the text box
void setfocus(int a,int b,int c,int d,char *f)
{
setcolor(GREEN);
rectangle(a,b,c,d);
setfillstyle(SOLID_FILL,BLACK);
floodfill(a+2,b+2,GREEN);
setcolor(YELLOW);
outtextxy(a+3,b+3,f);
}
// Function to wash the rectangle in black
void lostfocus(int a,int b,int c,int d,char *f)
{
setcolor(BLACK);
rectangle(a,b,c,d);
setfillstyle(SOLID_FILL,BLACK);
floodfill(a+2,b+2,BLACK);
setcolor(WHITE);
outtextxy(a+3,b+3,f);
}
// Function called before lostfocus to wash the rectangle
void lostfocus1(int a,int b,int c,int d,char *f)
{
setcolor(BLUE);
rectangle(a,b,c,d);
setfillstyle(SOLID_FILL,BLACK);
floodfill(a+2,b+2,BLUE);
setcolor(WHITE);
outtextxy(a+3,b+3,f);
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: projects
project of three dimensional calculator working with mouse
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<process.h>
int aaa=247,bbb=167,l2,status,rep=0,mul=0;
char ch,st2[50],st1[2];
double f1=0,f2=0,d1=0,d2=0,d3=0;
void buttan1(int,int,int,int);
void buttan(int,int,int,int);
void text();
void screen(char);
void scremt();
void main()
{ int d,mm,e,a,b,c,k;
d=DETECT;
initgraph(&d,&mm,"c:/tc");
e=graphresult();
if(e!=0)
{
cout<<"Graphics not inialised";
getch();
return;
}
setbkcolor(BLUE);
setcolor(7);
rectangle(aaa-10,bbb-50,aaa+153,bbb+150);
setfillstyle(1,7);
floodfill(aaa,bbb,7);
setcolor(15);
int f[]={aaa-15,bbb-55,aaa+158,bbb-55,aaa+153,bbb-50,aaa-10,bbb-50,aaa-10,bbb+150,aaa-15,bbb+155,aaa-15,bbb-55};
drawpoly(7,f);
setfillstyle(1,15);
floodfill(aaa-12,bbb-42,15);
setcolor(8);
int h[]={aaa+158,bbb-55,aaa+158,bbb+155,aaa-15,bbb+155,aaa-10,bbb+150,aaa+153,bbb+150,aaa+153,bbb-50,aaa+158,bbb-55};
drawpoly(7,h);
setfillstyle(1,8);
floodfill(aaa+156,bbb-40,8);
for(int ii=1;ii<17;ii++)
{
buttan(aaa,bbb,15,8);
aaa+=39;
if(ii%4==0)
{ bbb+=39;
aaa=247;
}
}
buttan1(236,75,15,8);
buttan1(350,75,15,8);
aaa=247;
bbb=167;
text();
scremt();
REGS n,m;
n.x.ax=0;
int86(0x33,&n,&m);
k=m.x.ax;
if(k==0)
return;
int aa,bb,t1,t2;
while(1)
{ n.x.ax=1;
int86(0x33,&n,&m);
n.x.ax=3;
int86(0x33,&n,&m);
a=m.x.cx;
b=m.x.dx;
c=m.x.bx;
// FOR EXIT XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if(c==1 && a>350 && a<400 && b>75 && b<100)
{ buttan1(350,75,8,15);
delay(200);
cleardevice();
cleardevice();
setcolor(RED);
outtextxy(50,50,"MADE BY:");
outtextxy(50,80,"UPINDER SINGH DHAMI");
outtextxy(50,110,"B.TECH (FIFTH SEM)");
outtextxy(50,140,"ELECTRONICS AND COMM ENGG");
outtextxy(50,170,"GURU NANAK DEV UNIVERSITY (AMRITSAR)");
outtextxy(50,200,"DATE: 17\\07\\2008");
delay(7000);
return;
}
// FOR RECET XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
if(c==1 && a>236 && a<286 && b>75 && b<100)
{ rep=0;
mul=0;
buttan1(236,75,8,15);
delay(200);
buttan1(236,75,15,8);
strcpy(st2,"");
screen(' ');
scremt();
}
// FOR FIRST ROW XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// FOR 7
if(c==1 && a>aaa && a<(aaa+25) && b>bbb && b<(bbb+25))
{
buttan(aaa,bbb,8,15);
delay(200);
buttan(aaa,bbb,15,8);
screen('7');
mul=0;
continue;
}
// FOR 8
if(c==1 && a>(aaa+39) && a<(aaa+64) && b>bbb&&b<(bbb+25))
{
buttan((aaa+39),bbb,8,15);
delay(200);
buttan((aaa+39),bbb,15,8);
screen('8');
mul=0;
continue;
}
// FOR 9
if(c==1 && a>(aaa+78) && a<(aaa+103) && b>bbb&&b<(bbb+25))
{
buttan((aaa+78),bbb,8,15);
delay(200);
buttan((aaa+78),bbb,15,8);
screen('9');
mul=0;
continue;
}
// FOR +
if(c==1 && a>(aaa+117) && a<(aaa+142) && b>bbb&&b<(bbb+25))
{ rep++;
mul++;
if(mul==2)
{ rep--;
mul--;
}
if(rep==2)
goto label;
status=2;
buttan((aaa+117),bbb,8,15);
delay(200);
buttan((aaa+117),bbb,15,8);
d1=f1;
strcpy(st2,"");
scremt();
continue;
}
//FOR SECOND ROW XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// FOR 4
if(c==1 && a>aaa && a<(aaa+25) && b>(bbb+39) && b<(bbb+64))
{
buttan(aaa,bbb+39,8,15);
delay(200);
buttan(aaa,bbb+39,15,8);
screen('4');
mul=0;
continue;
}
//FOR 5
if(c==1 && a>(aaa+39) && a<(aaa+64) && b>(bbb+39) && b<(bbb+64))
{
buttan(aaa+39,bbb+39,8,15);
delay(200);
buttan(aaa+39,bbb+39,15,8);
screen('5');
mul=0;
continue;
}
//FOR 6
if(c==1 && a>(aaa+78) && a<(aaa+103) && b>(bbb+39) && b<(bbb+64))
{
buttan(aaa+78,bbb+39,8,15);
delay(200);
buttan(aaa+78,bbb+39,15,8);
screen('6');
mul=0;
continue;
}
//FOR -
if(c==1 && a>(aaa+117) && a<(aaa+142) && b>(bbb+39) && b<(bbb+64))
{ rep++;
mul++;
if(mul==2)
{ rep--;
mul--;
}
if(rep==2)
goto label;
status=3;
buttan(aaa+117,bbb+39,8,15);
delay(200);
buttan(aaa+117,bbb+39,15,8);
d1=f1;
strcpy(st2,"");
scremt();
continue;
}
// FOR THIRD ROW XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// FOR 1
if(c==1 && a>aaa && a<(aaa+25) && b>(bbb+78) && b<(bbb+103))
{
buttan(aaa,bbb+78,8,15);
delay(200);
buttan(aaa,bbb+78,15,8);
screen('1');
mul=0;
continue;
}
//FOR 2
if(c==1 && a>(aaa+39) && a<(aaa+64) && b>(bbb+78) && b<(bbb+103))
{
buttan(aaa+39,bbb+78,8,15);
delay(200);
buttan(aaa+39,bbb+78,15,8);
screen('2');
mul=0;
continue;
}
//FOR 3
if(c==1 && a>(aaa+78) && a<(aaa+103) && b>(bbb+78) && b<(bbb+103))
{
buttan(aaa+78,bbb+78,8,15);
delay(200);
buttan(aaa+78,bbb+78,15,8);
screen('3');
mul=0;
continue;
}
//FOR *
if(c==1 && a>(aaa+117) && a<(aaa+142) && b>(bbb+78) && b<(bbb+103))
{ rep++;
mul++;
if(mul==2)
{ rep--;
mul--;
}
if(rep==2)
goto label;
status=1;
buttan(aaa+117,bbb+78,8,15);
delay(200);
buttan(aaa+117,bbb+78,15,8);
d1=f1;
strcpy(st2,"");
scremt();
continue;
}
// FOR FORTH ROW XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// FOR 0
if(c==1 && a>aaa && a<(aaa+25) && b>(bbb+117) && b<(bbb+142))
{
buttan(aaa,bbb+117,8,15);
delay(200);
buttan(aaa,bbb+117,15,8);
screen('0');
mul=0;
continue;
}
// FOR .
if(c==1 && a>(aaa+39) && a<(aaa+64) && b>(bbb+117) && b<(bbb+142))
{
buttan(aaa+39,bbb+117,8,15);
delay(200);
buttan(aaa+39,bbb+117,15,8);
screen('.');
mul=0;
continue;
}
// FOR =
if(c==1 && a>(aaa+78) && a<(aaa+103) && b>(bbb+117) && b<(bbb+142))
{
buttan(aaa+78,bbb+117,8,15);
delay(200);
buttan(aaa+78,bbb+117,15,8);
label:
if(status==1)
{ d2=f1;
d3=d1*d2;
}
if(status==2)
{ d2=f1;
d3=d1+d2;
}
if(status==3)
{ d2=f1;
d3=d1-d2;
}
if(status==4)
{ d2=f1;
d3=d1/d2;
}
char temp[50];
int sig = 10;
gcvt(d3, sig, temp);
strcpy(st2,"");
strcpy(st2,temp);
scremt();
screen(' ');
rep=0;
mul=0;
continue;
}
// FOR %
if(c==1 && a>(aaa+117) && a<(aaa+142) && b>(bbb+117) && b<(bbb+142))
{ rep++;
mul++;
if(mul==2)
{ rep--;
mul--;
}
if(rep==2)
goto label;
status=4;
buttan(aaa+117,bbb+117,8,15);
delay(200);
buttan(aaa+117,bbb+117,15,8);
d1=f1;
strcpy(st2,"");
scremt();
continue;
}
}
getch();
closegraph();
}
void buttan(int x, int y,int ltcolor,int rtcolor)
{
setcolor(7);
rectangle(x,y,x+25,y+25);
setfillstyle(1,7);
floodfill(x+2,y+2,7);
setcolor(ltcolor);
int a[]={ x-2,y-2,x+27,y-2,x+25,y,x,y,x,y+25,x-2,y+27,x-2,y-2};
drawpoly(7,a);
setfillstyle(1,ltcolor);
floodfill(x-1,y+5,ltcolor);
setcolor(rtcolor);
int b[]={x+27,y-2,x+27,y+27,x-2,y+27,x,y+25,x+25,y+25,x+25,y,x+27,y-2 };
drawpoly(7,b);
setfillstyle(1,rtcolor);
floodfill(x+26,y+5,rtcolor);
}
void text()
{ setcolor(4);
outtextxy(aaa+9,bbb+10,"7");
outtextxy(aaa+48,bbb+10,"8");
outtextxy(aaa+87,bbb+10,"9");
outtextxy(aaa+126,bbb+10,"+");
outtextxy(aaa+9,bbb+49,"4");
outtextxy(aaa+48,bbb+49,"5");
outtextxy(aaa+87,bbb+49,"6");
outtextxy(aaa+126,bbb+49,"-");
outtextxy(aaa+9,bbb+88,"1");
outtextxy(aaa+48,bbb+88,"2");
outtextxy(aaa+87,bbb+88,"3");
outtextxy(aaa+126,bbb+88,"*");
outtextxy(aaa+9,bbb+127,"0");
outtextxy(aaa+48,bbb+124,".");
outtextxy(aaa+87,bbb+127,"=");
outtextxy(aaa+126,bbb+127,"%");
outtextxy(243,85,"RESET");
outtextxy(361,85,"EXIT");
settextstyle(7,HORIZ_DIR,1);
outtextxy(aaa+50,bbb+250,"MADE BY: UPINDER SINGH DHAMI");
settextstyle(0,0,1);
}
void screen(char ch)
{ setcolor(15);
rectangle(aaa-5,bbb-40,aaa+148,bbb-10);
setfillstyle(1,15);
floodfill(aaa,bbb-20,15);
// outtextxy(aaa+140,bbb,"0.");
scremt();
if(ch!='a')
{
setcolor(1);
st1[0]=ch;
st1[1]='\0';
strcat(st2,st1);
}
l2=strlen(st2);
if(l2>19)
{ scremt();
setcolor(BLUE);
outtextxy(250,136," data overflow");
return;
}
f1 = atof(st2);
outtextxy(395-(l2*8),136,st2);
}
void scremt()
{ setcolor(14);
rectangle(aaa-5,bbb-40,aaa+148,bbb-10);
setfillstyle(1,14);
floodfill(aaa,bbb-20,14);
}
void buttan1(int x, int y,int ltcolor,int rtcolor)
{
setcolor(7);
rectangle(x,y,x+50,y+25);
setfillstyle(1,7);
floodfill(x+2,y+2,7);
setcolor(ltcolor);
int a[]={ x-4,y-4,x+54,y-4,x+50,y,x,y,x,y+25,x-4,y+29,x-4,y-4};
drawpoly(7,a);
setfillstyle(1,ltcolor);
floodfill(x-3,y-3,ltcolor);
setcolor(rtcolor);
int b[]={x+54,y-4,x+54,y+29,x-4,y+29,x,y+25,x+50,y+25,x+50,y,x+54,y-4};
drawpoly(7,b);
setfillstyle(1,rtcolor);
floodfill(x+52,y+10,rtcolor);
setcolor(1);
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
project of hostel management
#include<iostream.h>
#include<dos.h>
#include<graphics.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<math.h>
#include<iomanip.h>
#include<process.h>
#include<fstream.h>
void password();
void add();
void display();
void update();
void del();
void search();
void exit();
struct time t;
struct date d;
fstream fin,fout,fio;
void ctd()
{
gettime(&t); gotoxy(45,50);
printf("Current Time :%2d:%02d:%02d.%02d\n",
t.ti_hour,t.ti_min,t.ti_sec,t.ti_hund);
getdate(&d);gotoxy(45,48);
printf("Current Date:%d-%d-%d\n",d.da_day,d.da_mon,d.da_year);
}
class student
{
private:
int stid;
char name[20];
char sex[10];
char course[20];
char trade[20];
int semester;
int fee;
char fpaid[10];
int rn,bc;
char rt[12];
public:
void getnewdata()
{
cout<<"enter new semester";
cin>>semester;
cout<<"enter new room no";
cin>>rn;
}
int putstid()
{
return(stid);
}
void getdata()
{ gotoxy(30,14);
cout<<"ENTER STUDENT ID :";gotoxy(30,16);
cin>>stid;
cout<<"ENTER NAME :";gotoxy(30,18);
cin>>name;
cout<<"ENTER THE ROOM ALLOTED :";gotoxy(30,20);
cin>>rn;
cout<<"ENTER SEX :";gotoxy(30,22);
cin>>sex;
cout<<"ENTER COURSE :";gotoxy(30,24);
cin>>course;
cout<<"ENTER TRADE :";gotoxy(30,26);
cin>>trade;
cout<<"ENTER SEMESTER";gotoxy(30,28);
cin>>semester;
cout<<"ENTER BATCH";gotoxy(30,30);
cin>>bc;
}
void putrt(char* p)
{
strcpy(rt,p);
}
void putdata()
{ gotoxy(30,14);
cout<<"STUDENT ID IS"<<"\t"<<"STUDENTNAME"<<"\t"<<"ROOMALLOTED"<<"\t"<<"SEX"<<"\t"<<"COURSE"<<"\t"<<"TRADE"<<"\t"<<"SEMSETER"<<"\t"<<"BATCH"<<endl;
cout<<name<<"\t"<<rn<<"\t"<<sex<<"\t"<<course<<"\t"<<trade<<"\t"<<semester<<"\t"<<bc<<endl;
}
}s1;
class personal
{
private:
int rollno;
char name[20];
char sex[10];
char bg[20];
char dob[20];
char fn[20];
char mn[20];
char adr[50];
long phn;
int rn;
public:
void getnewaddress()
{
cout<<"ENTER NEW ADDRESS";
cin>>adr;
}
char * getname()
{
return(name);
}
int getrollno()
{
return(rollno);
}
void getdata()
{
gotoxy(25,18);
textcolor(23);
cout<<" ENTER STUDENT ID :";gotoxy(25,20);
cin>>rollno;
cout<<"ENTER NAME :";gotoxy(25,22);
cin>>name;
cout<<"ENTER SEX :";gotoxy(25,24);
cin>>sex;
cout<<"ENTER BLOOD GROUP :";gotoxy(25,26);
cin>>bg;
cout<<"ENTER DATE OF BIRTH :"; gotoxy(25,28);
cin>>dob;
cout<<"ENTER FATHER NAME :"; gotoxy(25,30);
cin>>fn;
cout<<"ENTER MOTHER NAME :";gotoxy(25,32);
cin>>mn;
cout<<"ENTER THE ADDRESS :";gotoxy(25,34);
cin>>adr;
cout<<"ENTER PHONE NO. :" ;gotoxy(25,36);
cin>>phn;
}
void putdata()
{
cout<<"SID"<<"\t"<<"NAME"<<"\t"<<"SEX"<<"\t"<<"BGROUP"<<"\t"<<"FATHERNAME"<<"\t"<<"MOTHERNAME"<<"\t"<<"ADDRESS"<<"\t"<<"PNO."<<endl;
cout<<rollno<<"\t "<<name<<"\t"<<sex<<"\t"<<bg<<"\t " <<fn<<"\t "<<mn<<"\t "<<adr<<"\t "<<phn<<"\t "<<rn<<endl;
}
}p1 ;
class room
{
private:
int rn, fan,tubelight,ac,cooler,tc,bed,cupboard;
char rt[12];
char avail;
public:
int putrn()
{
return(rn);
}
void grn(int p)
{
rn=p;
}
void getrn()
{
cout<<"ENTER NEW ROOM NUMBER :";
cin>>rn;
}
void getdata()
{
gotoxy(25,25);
textcolor(13);
/* cout<<"ENTER ROOM NUMBER : ";cout<<endl;
cin>>rn; */
cout<<"ENTER NUMBER OF FAN AVAILABLE :";cout<<endl;
cin>>fan;
cout<<"ENTER NUMBER OF TUBELIGHT AVAIABLE : ";cout<<endl;
cin>>tubelight;
cout<<"ENTER NUMBER OF AC AVAILABLE : ";cout<<endl;
cin>>ac;
cout<<"ENTER NUMBER OF COOLER AVAILABLE :";cout<<endl;
cin>>cooler;
cout<<"ENTER NUMBER OF CUPBOARD AVAILABLE :";cout<<endl;
cin>>cupboard;
cout<<"ENTER NUMBER OF TABLE CHAIR AVAILABLE :";cout<<endl;
cin>>tc;
cout<<"ENTER THE NUMBER OF BED : ";cout<<endl;
cin>>bed;
cout<<"ENTER NUMBER OF ROOM AVAILABLE :";cout<<endl;
cin>>avail;
cout<<"ENTER ROOM TYPE";cout<<endl;
cout<<"1. SINGLET ROOM :"<<endl;
cout<<"2. DOUBLET ROOM :"<<endl;
cout<<"3. TRIPLET ROOM :"<<endl;
cout<<"PLEASE ENTERED CHOICE :"<<endl;
int choice;
cin>>choice;
if(choice==1)
strcpy(rt,"singlet");
else if(choice==2)
strcpy(rt,"doublet");
else strcpy(rt,"triplet");
}
void putdata()
{
cout<<"ROOMNO"<<"\t"<<"FAN"<<"\t"<<"TUBE"<<"\t"<<"AC"<<"\t"<<"COOLER"<<"\t"<<"CUPBOARD"<<"\t"<<"TABLE"<<"\t"<<"BED"<<"\t"<<"ROOM"<<endl;
cout<<rn<<"\t "<<fan<<"\t "<<tubelight<<"\t"<<ac<<"\t"<<cooler<<"\t "<<cupboard<<"\t " <<tc<<"\t "<<bed<<"\t "<<avail<<endl;
}
}r1,r2;
void main()
{
// password();
int gmode,gdriver=DETECT;
initgraph(&gdriver,&gmode,"l:\tc\bgi");
char ch;
do
{
clrscr();
ctd();
gotoxy(25,14); sound(600);
delay(500);
nosound();
cout<<"======================================"; gotoxy(30,14);
cout<<"*MAIN MENU*"<<setw(20)<<endl;gotoxy(24,16);
cout<<" 1. ADD THE RECORD:"<<endl;gotoxy(25,18);
cout<<" 2. DISPLAY THE RECORD:"<<endl;gotoxy(25,20);
cout<<" 3. SEARCH THE RECORD:"<<endl;gotoxy(25,22);
cout<<" 4. UPDATE RECORD:"<<endl;gotoxy(25,24);
cout<<" 5. DELETE RECORD:"<<endl;gotoxy(25,26);
cout<<" 6. EXIT"<<endl;gotoxy(25,28);
cout<<"PLEASE ENTER THE CHOICE :"; gotoxy(25,30);
cout<<"=======================================";
cin>>ch;
switch(ch) //main switch
{
case '1': add();break;
case '2': display();break;
case '3': search();break;
case '4': update();break;
case '5': del(); break;
case '6': exit();
}
}while(ch!='6');
closegraph();
getch();
}
// end of main function
void password()
{ ctd();
gotoxy(15,20);
textcolor(6);
textbackground(750);
cout<< " *******************************************************"<<endl;gotoxy(15,20);
cout<< " *******************************************************"<<endl;gotoxy(15,21);
cout<< " *******************************************************"<<endl;gotoxy(15,22);
cout<< " ********** PROJECT **********"<<endl;gotoxy(15,23);
cout<< " ********** ON **********"<<endl;gotoxy(15,24);
cout<< " ********** HOSTEL MANAGEMENT **********"<<endl;gotoxy(15,25);
cout<< " ********** **********"<<endl;gotoxy(15,26);
cout<< " ********** MADE BY: **********"<<endl;gotoxy(15,27);
cout<< " ********** VAMA VARUN **********"<<endl;gotoxy(15,28);
cout<< " ********** VISHAL VISHAL **********"<<endl;gotoxy(15,29);
cout<< " *******************************************************"<<endl;gotoxy(15,30);
cout<< " *******************************************************"<<endl;gotoxy(15,31);
cout<< " *******************************************************"<<endl;gotoxy(15,32);
getch();
// password code
char un[20]="vishal",pw[20]="manish",un1[20],pw1[20];
for(int i=0;i<3;i++) //for loop
{
int j=0;
textcolor(6);
textbackground(700);
clrscr();
ctd();
gotoxy(26,26);
cout<<"PLEASE ENTER USER NAME : ";
gotoxy(50,26);
cin>>un1;
clrscr();
ctd();
gotoxy(26,26);
textcolor(6);
textbackground(700);
cout<<"PLEASE ENTER YOUR PASSWORD >%>%>%>%>%> ";
char ch; j=0;
do
{
ch=getch();
pw1[j]=ch;
if(ch=='\n'||ch=='\t'||ch=='\r')
break;
else
{
cout<<"*";
j++;
}
}while(ch!='\r');
pw1[j]='\0';
gotoxy(25,15);
if(strcmp(un,un1)==0 && strcmp(pw,pw1)==0)
{
clrscr();
ctd(); //right password
gotoxy(30,12);
textcolor(6);
textbackground(700);
cout<<"PASSWORD................IS....CONFERMED";
getch();
clrscr();
gotoxy(30,12);
cout<<" WELCOME ";gotoxy(30,14);
cout<<" TO ";gotoxy(30,16);
cout<<" HOSTEL ";
getch();
break;
}
else
{
if(i==2) //wrong code
exit(0);
} clrscr();
gotoxy(30,14);
cout<<" WRONG......... PASSWORD.........";
getch();
clrscr();
gotoxy(30,14);
cout<<"TRY AGAIN.......................";
getch();
}
} //end of password function
void add()
{
char choice;
do
{
clrscr();
ctd();
gotoxy(29,14);
cout<<"*ADD RECORD*"<<endl;
gotoxy(25,18);
cout<<"a.ROOM RECORD"<<endl; gotoxy(25,20);
cout<<"b.STUDENT RECORD ::PERSONAL INFORMATION"<<endl; gotoxy(25,22);
cout<<"c.STUDENT RECORD ::STUDENT ID "<<endl; gotoxy(25,24);
cout<<"d.TO EXIT";
cout<<"ENTER CHOICE ";
cin>>choice;
clrscr();
switch(choice)
{
case 'a':
cout<<"STUDENT ID"<<endl;gotoxy(30,14);
char a;
clrscr();
ctd();
gotoxy(25,25);
cout<<" ROOM INFORMATION : "<<endl;gotoxy(25,26);
cout<<"1. SINGLET ROOM :"<<endl;gotoxy(25,27);
cout<<"2. DOUBLET ROOM :"<<endl; gotoxy(25,28);
cout<<"3. TRIPLET ROOM :"<<endl; gotoxy(25,29);
cout<<"PLEASE ENTERED CHOICE :"<<endl;
cin>>a;
switch(a)
{
case '1':
cout<<"*SINGLET ROOM*" <<endl;
cout<<"SINGLET"<<endl;
cout<<"CHARGES ARE AS FOLLOWS:"<<endl;
cout<<"ROOM CHARGES ARE:Rs 1500 PER MONTH (AC)"<<endl;
getch();
break;
case '2':
cout<<" *DOUBLET ROOM*" <<endl;
cout<<"DOUBLET "<<endl;
cout<<"CHARGES ARE AS FOLLOWS:"<<endl;
cout<<"ROOM CHARGES ARE:Rs 1200 PER MONTH (AC)"<<endl;
getch();
break;
case '3':
cout<<" *TRIPLET ROOM*"<<endl;
cout<<"TRIPLET "<<endl;
cout<<"CHARGES ARE AS FOLLOWS:"<<endl;
cout<<"ROOM CHARGES ARE:Rs 1000 PER MONTH (AC)"<<endl;
getch();
break;
default :
{
cout<<" *ENTER APPOPRIATE CHOICE*"<<endl;
cout<<"WRONG CHOICE "<<endl;
getch();
}
}
cout<<"ROOM RECORD :"<<endl; gotoxy(10,11);
int flag=0;
clrscr();
ctd();
cout<<"ENTER ROOM INFORMATION"<<endl;
fio.open("rm.dat",ios::out|ios::in);
fio.seekg(0,ios::beg);
if(!fio)
{
cout<<"FILE CAN'T BE OPENED"<<endl;
getch();
}
else
{
int rn;
cout<<"enter room no";
cin>>rn;
fio.seekg(0,ios::beg);
while(fio.read((char*)&r1,sizeof(r1)))
{
getch();
if(rn==r1.putrn())
{
flag=1;
break;
}
}
fio.clear();
fio.close();
if(flag==1)
{
cout<<"room already exist";
getch();
return;
}
r2.getdata();
r2.grn(rn);
fout.open("rm.dat",ios::out|ios::ate);
cout<<"WANT TO SAVE THE DATA? PRESS Y/N.";
cin>>choice;
if(choice=='y')
{
fout.write( (char *)&r2,sizeof(r2));
fout.clear();
cout<<"record saved";
getch();
}
fout.close();
}
break;
case 'c':
cout<<"STUDENT RECORD:STUDENT ID "<<endl; gotoxy(10,11);
int flag1=0;
clrscr();
ctd();
cout<<"ENTER STUDENT ID"<<endl;
fio.open("st.dat",ios::out|ios::in);
fio.seekg(0,ios::beg);
if(!fio)
{
cout<<"FILE CAN'T BE OPENED"<<endl;
getch();
}
else
{
int rn5;
cout<<"enter student id";
cin>>rn5;
fio.seekg(0,ios::beg);
while(fio.read((char*)&s1,sizeof(s1)))
{
getch();
if(rn5==s1.putstid())
{
flag1=1;
break;
}
}
fio.clear();
fio.close();
if(flag1==1)
{
cout<<"id already exist";
getch();
return;
}
s1.getdata();
s1.putstid();
fout.open("st.dat",ios::out|ios::ate);
cout<<"WANT TO SAVE THE DATA? PRESS Y/N.";
cin>>choice;
if(choice=='y')
{
fout.write( (char *)&s1,sizeof(s1));
fout.clear();
cout<<"record saved";
getch();
}
fout.close();
}
break;
/* clrscr();
ctd();
fout.open("pi.dat",ios::app);
if(!fout)
{
cout<<"FILE CAN'T BE OPENED"<<endl;
}
else
{
clrscr();
cout<<"ENTER THE DATA :"<<endl;
p1.getdata();
cout<<"WANT TO BE SAVE THEN PRESS Y:";
cin>>choice;
if(choice=='y')
{
fout.write((char*)&p1,sizeof(p1));
fout.clear();
getch();
}
fout.close();
}
break; */
case 'b':
cout<<"STUDENT RECORD:PERSONAL INFORMATION "<<endl; gotoxy(10,11);
int flag2=0;
clrscr();
ctd();
cout<<"ENTER PERSONAL INFORMATION"<<endl;
fio.open("pi.dat",ios::out|ios::in);
fio.seekg(0,ios::beg);
if(!fio)
{
cout<<"FILE CAN'T BE OPENED"<<endl;
getch();
}
else
{
char* p;
char name2[15];
cout<<"enter student name";
cin>>name2;
fio.seekg(0,ios::beg);
while(fio.read((char*)&p1,sizeof(p1)))
{
getch();
if(strcmp(name2,p)==0)
{
flag2=1;
break;
}
}
fio.clear();
fio.close();
if(flag2==1)
{
cout<<"name already exist";
getch();
return;
}
p1.getdata();
// p1.get(name2);
fout.open("pi.dat",ios::out|ios::ate);
cout<<"WANT TO SAVE THE DATA? PRESS Y/N.";
cin>>choice;
if(choice=='y')
{
fout.write( (char *)&p1,sizeof(p1));
fout.clear();
cout<<"record saved";
getch();
}
fout.close();
}
break;
/* clrscr();
ctd();
gotoxy(30,14);
cout<<"PERSONAL INFORMATION"<<endl;
fout.open("pi.dat",ios::app);
if(!fout)
{
cout<<"FILE CAN'T BE OPENED"<<endl;
}
else
{
cout<<"ENTER THE DATA :"<<endl;
p1.getdata();
cout<<"want to save then press y";
cin>>choice;
if(choice=='y')
{
fout.write( (char *)&p1,sizeof(p1));
fout.clear();
getch();
}
fout.close();
} */
// main add switch case
}
}while(choice!='d');
getch();
}
void display()
{ char choice;
do
{ clrscr(); //label for add menu
ctd();
gotoxy(29,14);
cout<<"*DISPLAY RECORD*"<<endl;
gotoxy(25,18);
cout<<"a.ROOM RECORD "<<endl; gotoxy(25,20);
cout<<"b.STUDENT RECORD ::PERSONAL INFORMATION "<<endl; gotoxy(25,22);
cout<<"c.STUDENT RECORD ::STUDENT ID"<<endl;gotoxy(25,24);
cout<<"d.BACK TO MAIN MENU"<<endl;gotoxy(25,26);
cout<<"ENTER CHOICE ";
cin>>choice;
clrscr();
ctd();
switch(choice) // case 2a student record
{
case 'a':cout<<"ROOM RECORD"<<endl; gotoxy(10,11);
cout<<"ROOM INFORMATION"<<endl;
fin.open("rm.dat",ios::in);
fin.seekg(0,ios::beg);
if(!fin)
{
cout<<"FILE CAN'T BE OPENED"<<endl;
getch();
}
else
{
clrscr();
while(fin.read((char *)&r1,sizeof(r1)))
{
r1.putdata();
fin.clear();
getch();
}
fin.close();
}
break;
case 'b':clrscr();
ctd();
gotoxy(30,14);
cout<<"STUDENT RECORD :"<<endl; gotoxy(25,18);
cout<<"PERSONAL INFORMATION"<<endl;
fin.open("pi.dat",ios::in);
if(!fin)
{
cout<<"FILE CAN'T BE OPENED"<<endl;
getch();
}
else
{
while(fin.read((char *)&p1,sizeof(p1)))
{
p1.putdata();
cout<<endl;
fin.clear();
getch();
}
fin.close();
}
break;
case 'c': gotoxy(30,14);
cout<<"STUDENT INFORMATION"<<endl;
cout<<"STUDENT ID"<<endl;
fin.open("st.dat",ios::in);
if(!fin)
{
cout<<"FILE CAN'T BE OPENED"<<endl;
}
else
{
while(fin.read((char*)&s1,sizeof(s1)))
{
s1.putdata();
fin.clear();
getch();
}
fin.close();
}
break;
case 'd': cout<<"back to main menu";
getch();
}
}while(choice!='d');
getch();
}
void search()
{
clrscr();
ctd();
char choice;
do
{
clrscr();
ctd();
gotoxy(29,14);
textcolor(25);
textbackground(373);
cout<<"*SEARCH RECORD*"<<endl;
char choice22; gotoxy(25,18);
cout<<"a.STUDENT RECORD BY NAME "<<endl; gotoxy(25,20);
cout<<"b.student id "<<endl; gotoxy(25,22);
cout<<"c.room no "<<endl; gotoxy(25,24);
cout<<"d. back to main menu "<<endl; gotoxy(25,26);
cout<<"ENTER CHOICE ";
cin>>choice;
clrscr();
ctd();
switch(choice)
{
case 'a' : gotoxy(30,14);
cout<<"STUDENT RECORD BY NAME"<<endl;
char *p; char name[15];int flag=0;
cout<<"ENTER STUDENT NAME";
cin>>name;
fin.open("pi.dat",ios::in);
while(fin.read((char*)&p1,sizeof(p1)))
{
p=p1.getname();
if(strcmp(name,p)==0)
{
p1.putdata();
getch();
flag=1;
}
}
if(flag==0)
{
cout<<"RECORD DOES NOT EXIST";
getch();
}
fin.close(); //search main switch
break;
case 'b' : gotoxy(30,14);
int roll;
cout<<"STUDENT RECORD BY ID"<<endl;
cout<<"ENTER THE STUDENT ID";
cin>>roll;
flag=0;
fin.open("st.dat",ios::in);
while(fin.read((char*)&s1,sizeof(s1)))
{
if(roll==s1.putstid())
{
s1.putdata();
getch();
flag=1;
}
}
if(flag==0)
{
cout<<"RECORD DOES NOT EXIST";
getch();
}
fin.close();
break;
case 'c': clrscr();
gotoxy(30,16);
cout<<"ROOM INFORMATION "<<endl;
int rn;
flag=0;
cout<<"ENTER ROOM NUMBER ";
cin>>rn;
fin.open("rm.dat",ios::in);
while(fin.read((char*)&r1,sizeof(r1)))
{
if(rn==r1.putrn())
{
r1.putdata();
flag=1;
getch();
}
fin.clear();
}
if(flag==0)
{
cout<<"RECORD DOES NOT EXIST"<<endl;
getch();
}
fin.close();
break;
case 'd': cout<<"BACK TO MAIN MENU";
getch(); }
} while(choice!='d'); //main serch
getch();
}
void update()
{
clrscr();
cout<<"update"<<endl;
char choice;
do
{
clrscr();
gotoxy(29,14);
textcolor(25);
textbackground(373);
cout<<"*UPDATE RECORD*"<<endl;
char choice22; gotoxy(25,18);
cout<<"a.ROOM RECORD"<<endl; gotoxy(25,20);
cout<<"b.STUDENT RECORD:: PERSONAL INFORMATION "<<endl; gotoxy(25,22);
cout<<"c.STUDENT RECORD::STUDENT ID "<<endl; gotoxy(25,24);
cout<<"d. BACK TO MAIN MENU "<<endl; gotoxy(25,26);
cout<<"ENTER CHOICE ";
cin>>choice;
clrscr();
int flag;
switch(choice)
{
case 'a': clrscr();
gotoxy(30,16);
cout<<"ROOM INFORMATION "<<endl;
int rn;
flag=0;
cout<<"ENTER ROOM NO";
cin>>rn;
fin.open("rm.dat",ios::in|ios::out|ios::ate);
fin.seekg(0,ios::beg);
if(!fin)
{
cout<<"FILE CAN NOT OPENED";
getch(); return;
}
else
{
while(fin.read((char*)&r1,sizeof(r1)))
{ cout<<"rn"<<r1.putrn()<<endl;
if(rn==r1.putrn())
{
int p=fin.tellp();
fin.seekp(p-sizeof(r1));
r1.getrn();
fin.write((char*)&r1,sizeof(r1));
fin.clear();
flag=1;
getch();
break;
}
} fin.close();
if(flag==0)
{
cout<<"RECORD DOES NOT EXIST"<<endl;
return;
}
cout<<"RECORD IS UPDATED"<<endl;
getch();
}
break;
case 'b' : gotoxy(30,14);
cout<<"STUDENT RECORD BY NAME"<<endl;
char *p; char name[15];int flag=0;
cout<<"ENTER STUDENT NAME";
cin>>name;
fin.open("pi.dat",ios::in|ios::ate|ios::out);
fin.seekg(0,ios::beg);
while(fin.read((char*)&p1,sizeof(p1)))
{
if(strcmp(name,p1.getname())==0)
{
int p=fin.tellp();
p1.getnewaddress();
fin.seekp(p-sizeof(p1));
fin.write((char*)&p1,sizeof(p1));
fin.clear();
p1.putdata();
getch();
flag=1;
}
}
if(flag==0)
{
cout<<"RECORD DOES NOT EXIST";
getch();
}
fin.close();
cout<<"RECORD IS UPDATED"<<endl;
getch(); //update main switch
break;
case 'c' : gotoxy(30,14);
int roll;
cout<<"STUDENT RECORD BY STUDENT ID"<<endl;
cout<<"ENTER THE STUDENT ID";
cin>>roll;
flag=0;
fin.open("st.dat",ios::in|ios::ate|ios::out);
fin.seekg(0,ios::beg);
while(fin.read((char*)&s1,sizeof(s1)))
{
if(roll==s1.putstid())
{
int p=fin.tellp();
s1.getnewdata();
fin.seekp(p-sizeof(s1));
fin.write((char*)&s1,sizeof(s1));
fin.clear();
getch();
flag=1;
}
}
if(flag==0)
{
cout<<"RECORD DOES NOT EXIST";
getch();
}
cout<<"RECORD IS UPDATED";
getch();
fin.close();
break;
case 'd': cout<<"back to main menu";
return;
}
} while(choice!='d'); //main update.
getch();
}
void del()
{ clrscr();
cout<<"delete"<<endl;
char choice;
do
{
clrscr();
gotoxy(29,14);
textcolor(25);
textbackground(373);
cout<<"*DELETE RECORD*"<<endl;
char choice22; gotoxy(25,18);
cout<<"a.DELETE THROUGH ROOM NUMBER"<<endl; gotoxy(25,20);
cout<<"b.DELETE THROUGH SYUDENT ID "<<endl; gotoxy(25,22);
cout<<"c.DELETE THROUGH STUDENT NAME "<<endl; gotoxy(25,24);
cout<<"d. BACK TO MAIN MENU "<<endl; gotoxy(25,26);
cout<<"ENTER CHOICE ";
cin>>choice;
clrscr();
int flag;
switch(choice)
{
case 'a': clrscr();
gotoxy(30,16);
cout<<"DELETE THROUGH ROOM NO "<<endl;
int rn;
flag=0;
cout<<"ENTER ROOM NO";
cin>>rn;
fout.open("temp.dat",ios::in|ios::out|ios::app);
fout.seekg(0, ios::beg);
fin.open("rm.dat",ios::in|ios::out|ios::app);
fin.seekg(0, ios::beg);
while(fin.read((char*)&r1,sizeof(r1)))
{
if(rn==r1.putrn())
{
cout<<"RECORD DELETED";
getch();
flag=1;
}
else
{ fout.write((char*)&r1,sizeof(r1));
fout.clear();
fin.clear();
}
}
fin.close();
fout.close();
if(flag==0)
{
cout<<"RECORD NOT FOUND";
getch();
}
remove("rm.dat");
rename("temp.dat","rm.dat");
break;
case 'b':
clrscr();
gotoxy(30,16);
cout<<"DELETE THROUGH STUDENT ID "<<endl;
int rn1;
flag=0;
cout<<"ENTER STUDENT ID";
cin>>rn1;
fout.open("temp.dat",ios::in|ios::out|ios::app);
fout.seekg(0, ios::beg);
fin.open("st.dat",ios::in|ios::out|ios::app);
fin.seekg(0, ios::beg);
while(fin.read((char*)&s1,sizeof(s1)))
{
if(rn1==s1.putstid())
{
cout<<"RECORD DELETED";
getch();
flag=1;
}
else
{ fout.write((char*)&s1,sizeof(s1));
fout.clear();
fin.clear();
}
}
fin.close();
fout.close();
if(flag==0)
{
cout<<"RECORD NOT FOUND";
getch();
}
remove("st.dat");
rename("temp.dat","st.dat");
break;
case 'c':
clrscr();
gotoxy(30,16);
cout<<"DELETE THROUGH STUDENT NAME"<<endl;
char name[15];
char* p;
flag=0;
cout<<"ENTER STUDENT NAME";
cin>>name;
fout.open("temp.dat",ios::in|ios::out|ios::app);
fout.seekg(0, ios::beg);
fin.open("pi.dat",ios::in|ios::out|ios::app);
fin.seekg(0, ios::beg);
while(fin.read((char*)&p1,sizeof(p1)))
{
p=p1.getname();
if(strcmp(name,p)==0)
{
cout<<"RECORD DELETED";
getch();
flag=1;
}
else
{ fout.write((char*)&s1,sizeof(s1));
fout.clear();
fin.clear();
}
}
fin.close();
fout.close();
if(flag==0)
{
cout<<"RECORD NOT FOUND";
getch();
}
remove("pi.dat");
rename("temp.dat","pi.dat");
break;
case 'd':
cout<<"BACK TO MAIN MENU";
getch();
return;
}}while(choice!='d');
getch();
}
void exit()
{
clrscr();
gotoxy(35,25);
cout<<"BYE BYE";
getch();
exit(1);
}
Posted by Upinder Singh Dhami at Tuesday, September 01, 2009 0 comments
Labels: projects