#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
#include<string.h>
class student
{
public:
int len;
char name[10],rollno[10],attendence[10],marks[10];
void getdata()
{
cout<<"enter student name:"<<endl;
gets(name);
cout<<"enter student rollnumber:"<<endl;
cin>>rollno;
cout<<"enter student marks:"<<endl;
cin>>marks;
cout<<"enter student attendence:"<<endl;
cin>>attendence;
strcat(name,"|");
strcat(rollno,"|");
strcat(marks,"|");
strcat(attendence,"|");
len=strlen(name)+strlen(rollno)+strlen(marks)+strlen(attendence);
}
};
int main()
{
int i,j,n;
clrscr();
student s;
const int size=40;
char buffer[size];
fstream f;
f.open("alter.var",ios::in|ios::out|ios::trunc);
cout<<"enter how many records u want:"<<endl;
cin>>n;
for(i=0;i<n;i++)
{
buffer[0]='\0';
s.getdata();
strcat(buffer,s.name);
strcat(buffer,s.rollno);
strcat(buffer,s.marks);
strcat(buffer,s.attendence);
for(j=s.len;j<size;j++)
{
buffer[j]='*';
}
buffer[j]='\0';
f.write((char *)&buffer,size);
}
f.seekg(0,ios::beg);
cout<<"record details are:"<<endl;
while(f.read((char *)&buffer,sizeof(buffer)))
{
cout<<buffer<<endl;
}
f.close();
getch();
return 0;
}
#include<conio.h>
#include<stdio.h>
#include<fstream.h>
#include<string.h>
class student
{
public:
int len;
char name[10],rollno[10],attendence[10],marks[10];
void getdata()
{
cout<<"enter student name:"<<endl;
gets(name);
cout<<"enter student rollnumber:"<<endl;
cin>>rollno;
cout<<"enter student marks:"<<endl;
cin>>marks;
cout<<"enter student attendence:"<<endl;
cin>>attendence;
strcat(name,"|");
strcat(rollno,"|");
strcat(marks,"|");
strcat(attendence,"|");
len=strlen(name)+strlen(rollno)+strlen(marks)+strlen(attendence);
}
};
int main()
{
int i,j,n;
clrscr();
student s;
const int size=40;
char buffer[size];
fstream f;
f.open("alter.var",ios::in|ios::out|ios::trunc);
cout<<"enter how many records u want:"<<endl;
cin>>n;
for(i=0;i<n;i++)
{
buffer[0]='\0';
s.getdata();
strcat(buffer,s.name);
strcat(buffer,s.rollno);
strcat(buffer,s.marks);
strcat(buffer,s.attendence);
for(j=s.len;j<size;j++)
{
buffer[j]='*';
}
buffer[j]='\0';
f.write((char *)&buffer,size);
}
f.seekg(0,ios::beg);
cout<<"record details are:"<<endl;
while(f.read((char *)&buffer,sizeof(buffer)))
{
cout<<buffer<<endl;
}
f.close();
getch();
return 0;
}
No comments:
Post a Comment