Ds Practical 10
Ds Practical 10
10
#include <iostream>
#include <fstream>
#include <cstring>
struct Student {
int rollNumber;
char name[50];
char division[10];
char address[100];
};
fstream file;
Student student;
if (!file) {
return;
}p
cin.ignore();
cout << "Enter Name: ";
cin.getline(student.name, 50);
cin.getline(student.division, 10);
cin.getline(student.address, 100);
file.write(reinterpret_cast<char*>(&student), sizeof(student));
file.close();
Student student;
file.open(filename, ios::in);
if (!file) {
return;
tempFile.open("temp.dat", ios::out);
if (!tempFile) {
file.close();
return;
found = true;
continue;
tempFile.write(reinterpret_cast<char*>(&student), sizeof(student));
if (found) {
} else {
cout << "No student found with Roll Number: " << rollNumber << endl;
file.close();
tempFile.close();
remove(filename);
rename("temp.dat", filename);
fstream file;
Student student;
file.open(filename, ios::in);
if (!file) {
return;
found = true;
break;
if (!found) {
cout << "No student found with Roll Number: " << rollNumber << endl;
file.close();
void menu() {
do {
case 1:
addStudent(filename);
break;
case 2:
deleteStudent(filename, rollNumber);
break;
case 3:
displayStudent(filename, rollNumber);
break;
case 4:
break;
default:
int main() {
menu();
return 0;
}Output:-