Filing All Combine
Filing All Combine
# include <conio.h>
# include <stdio.h>
# include <iostream.h>
# include <string.h>
# include <process.h>
void main()
FILE *f;
f=fopen("Marks.dat","rb");
int rno,found=0;
float tot,per;
struct myrecord
int roll_no;
char name[15];
float it,win,word,excel,pp;
};
struct myrecord r;
clrscr();
gotoxy(15,3);
cin>>rno;
if(rno==0)
exit(1);
while(!feof(f))
fread(&r,sizeof(r),1,f);
if(r.roll_no==rno)
found=1;
clrscr();
gotoxy(10,5);
gotoxy(10,6);
gotoxy(10,7);
gotoxy(10,8);
gotoxy(10,10);
gotoxy(10,11);
tot=r.it+r.win+r.word+r.excel+r.pp;
per=(tot*100)/500;
gotoxy(10,12);
gotoxy(10,13);
cout<<"Percetage is "<<per;
getch();
else
continue;
fclose(f);
if(found==0)
clrscr();
gotoxy(15,5);
getch();
}
Data given (Writing) Program
# include <conio.h>
# include <stdio.h>
# include <iostream.h>
# include <string.h>
void data_given()
FILE *f;
f=fopen("Marks.dat","ab");
struct myrecord
int roll_no;
char name[15];
float it,win,word,excel,pp;
};
struct myrecord r;
while(1)
gotoxy(10,5);
cin>>r.roll_no;
if(r.roll_no==0)
break;
gotoxy(10,6);
gets(r.name);
gotoxy(10,7);
cin>>r.it;
gotoxy(10,8);
gotoxy(10,9);
cin>>r.word;
gotoxy(10,10);
cin>>r.excel;
gotoxy(10,11);
cin>>r.pp;
fwrite(&r,sizeof(r),1,f);
fclose(f);
void disp()
{
clrscr();
gotoxy((80-strlen(h1))/2,1);
cout<<h1;
gotoxy((80-strlen(h2))/2,2);
cout<<h2;
void main()
disp();
data_given();
getch();
Updating Program
# include <conio.h>
# include <stdio.h>
# include <iostream.h>
# include <string.h>
# include <process.h>
void main()
FILE *f,*t;
f=fopen("Marks.dat","rb");
t=fopen("temp.dat","wb");
struct myrecord
{
int roll_no;
char name[15];
float it,win,word,excel,pp;
};
int rno,found=1;
struct myrecord r;
clrscr();
gotoxy(15,3);
cin>>rno;
if(rno==0)
exit(1);
while(!feof(f))
{
clrscr();
fread(&r,sizeof(r),1,f);
if(r.roll_no==rno)
found=1;
gotoxy(10,5);
cin>>r.roll_no;
gotoxy(10,6);
gets(r.name);
gotoxy(10,7);
cout<<"Enter IT Marks to Update ";
cin>>r.it;
gotoxy(10,8);
cin>>r.win;
gotoxy(10,9);
cin>>r.word;
gotoxy(10,10);
cin>>r.excel;
gotoxy(10,11);
cout<<"Enter Power Point Marks to Update ";
cin>>r.pp;
fwrite(&r,sizeof(r),1,t);
else
fwrite(&r,sizeof(r),1,t);
fclose(f);
fclose(t);
if(found==1)
clrscr();
gotoxy(15,5);
cout<<"Record Found and Update";
unlink("Marks.dat");
rename("temp.dat","Marks.dat");
getch();
else
clrscr();
gotoxy(15,5);
getch();
}
Deleting Program
# include <conio.h>
# include <stdio.h>
# include <iostream.h>
# include <string.h>
# include <process.h>
void main()
FILE *f,*t;
f=fopen("Marks.dat","rb");
t=fopen("temp.dat","wb");
int rno,found=1;
float tot,per;
struct myrecord
int roll_no;
char name[15];
float it,win,word,excel,pp;
};
struct myrecord r;
clrscr();
gotoxy(15,3);
cin>>rno;
if(rno==0)
exit(1);
while(!feof(f))
fread(&r,sizeof(r),1,f);
if(r.roll_no==rno)
{
found=1;
continue;
else
fwrite(&r,sizeof(r),1,t);
fclose(f);
fclose(t);
if(found==1)
clrscr();
gotoxy(15,5);
unlink("Marks.dat");
rename("temp.dat","Marks.dat");
getch();
else
clrscr();
gotoxy(15,5);
getch();
}
Printing (Traversing ) Progam
# include <conio.h>
# include <stdio.h>
# include <iostream.h>
# include <string.h>
void main()
FILE *f;
f=fopen("Marks.dat","rb");
float tot,per;
struct myrecord
int roll_no;
char name[15];
float it,win,word,excel,pp;
};
struct myrecord r;
while(!feof(f))
clrscr();
fread(&r,sizeof(r),1,f);
gotoxy(10,5);
gotoxy(10,6);
gotoxy(10,7);
gotoxy(10,9);
gotoxy(10,10);
gotoxy(10,11);
tot=r.it+r.win+r.word+r.excel+r.pp;
per=(tot*100)/500;
gotoxy(10,12);
cout<<"Percetage is "<<per;
getch();
fclose(f);