0% found this document useful (0 votes)
39 views3 pages

wap To Append Data in Binary File

This C++ program appends student data to a binary file. It defines a student class with attributes like roll number, name, class, and percentage. It has functions to input and output student details. The main function calls add() to add multiple student records to a binary file in append mode and display() to read and display the records.

Uploaded by

54gfh984
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
39 views3 pages

wap To Append Data in Binary File

This C++ program appends student data to a binary file. It defines a student class with attributes like roll number, name, class, and percentage. It has functions to input and output student details. The main function calls add() to add multiple student records to a binary file in append mode and display() to read and display the records.

Uploaded by

54gfh984
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 3

//WAP TO APPEND DATA IN BINARY FILE.

#include <fstream.h>

#include <iostream.h>

class student {

int roll_no, clas;

char name[25];

float percent;

public:

void input();

void output();

};

void student :: input()

{ cout << "\nEnter Roll No : "; cin >> roll_no;

cout << "\nEnter Name : "; cin >> name;

cout << "\nEnter Class : "; cin >> clas;

cout << "\nEnter percent : "; cin >> percent;

void student :: output()

{ cout << "\nRoll No : " << roll_no << endl;

cout << "\nName : " << name << endl;

cout << "\nClass : " << clas << endl;

cout << "\nPercent : " << percent << endl;

void add();

void display();

void main()

{ clrscr();

add();
display();

getch();

void add(){

ofstream f ("stu.dat", ios :: binary | ios :: app);

student s;

char choice;

do

{ s.input();

f.write((char *)&s, sizeof(s)) ;

cout << "\nWant to enter next (y/n): ";

cin >> choice;

} while (choice == 'y' || choice == 'Y');

f.close();

void display(){

ifstream f ("stu.dat", ios :: binary);

student s;

while (f.read ((char *)&s, sizeof (s))){

s.output();

f.close(); }
OUTPUT

You might also like