0% found this document useful (0 votes)
39 views

C++ Program

This code defines a structure to store student records including roll number, name, and 5 marks. It uses file input/output streams to write a student record entered by the user to a binary file, then reopen and read the file to display the stored record.

Uploaded by

Vraj Mistry
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

C++ Program

This code defines a structure to store student records including roll number, name, and 5 marks. It uses file input/output streams to write a student record entered by the user to a binary file, then reopen and read the file to display the stored record.

Uploaded by

Vraj Mistry
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<fstream.

h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
struct stud
{
int r,m[5];
char name[20];
}s1,s2;
void main()
{
fstream fp;
fp.open("stud.txt",ios::in|ios::out|ios::binary);
cout<<"ENTER THE STUDENT'S RECORD:\n";
cout<<"ENTER THE ROLL NO:";
cin>>s1.r;
cout<<"ENTER THE NAME:";
gets(s1.name);
cout<<"ENTER THE 5 MARKS:\n";
for(int i=0;i<5;i++)
{
cin>>s1.m[i];
cout<<"\n";
}
fp.write((char*)&s1,sizeof(stud));
fp.close();
fp.open("stud.txt",ios::out|ios::in|ios::binary);
fp.read((char*)&s1,sizeof(stud));
cout<<"ROLL NO="<<s1.r;
cout<<"\nNAME IS:";
puts(s1.name);
cout<<"MARKS ARE:\n";
for(i=0;i<5;i++)
{
cout<<s1.m[i];
cout<<"\n";
}
fp.close();
getch();
}

You might also like