Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Variable Length Records: A C++ Implementation, Summaries of Bankruptcy Law

A c++ implementation of a student record management system that utilizes variable-length records. The system allows users to perform various operations such as packing, unpacking, searching, modifying, and deleting student records. The code includes classes and functions to handle these tasks, including reading and writing to a file. A detailed overview of the program's functionality, showcasing its ability to efficiently manage student data using variable-length records. This implementation could be useful for students or professionals interested in learning about file handling, data structures, and object-oriented programming in c++.

Typology: Summaries

2022/2023

Uploaded on 07/07/2023

raghavendra-s-nayak
raghavendra-s-nayak 🇮🇳

2 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#include<iostream>
#include<fstream>
#include<string.h>
#include<stdlib.h>
using namespace std;
class student
{
string usn,name,sem,buffer;
public:
void unpack();
void read();
void read_file();
void write_file();
void display();
void pack();
int del(string);
void modify(string);
int search1(string);
}s;
main()
{
int ch;
string regno;
cout<<"\nVARIABLE LENGTH RECORDS";
while(1){
cout<<"\n1:Pack 2:Unpack 3:Search 4:Modify 5:exit\n";
cin>>ch;
switch(ch)
{
case 1: s.read();
s.pack();
s.write_file();
break;
case 2: s.read_file();
break;
case 3: cout<<"Enter regno to search\n";
cin>>regno;
s.search1(regno);
break;
case 4: cout<<"Enter regno to search\n";
cin>>regno;
s.modify(regno);
break;
default : exit(0);
}//switch
}//while
}
void student::read()
{
cout<<"Enter details[USN,Name,Sem]\n";
cin>>usn>>name>>sem;
}
void student::pack()
{
buffer.erase();
buffer+=usn+"|"+name+"|"+sem+"$\n";
pf3

Partial preview of the text

Download Variable Length Records: A C++ Implementation and more Summaries Bankruptcy Law in PDF only on Docsity!

#include #include #include<string.h> #include<stdlib.h> using namespace std; class student { string usn,name,sem,buffer; public: void unpack(); void read(); void read_file(); void write_file(); void display(); void pack(); int del(string); void modify(string); int search1(string); }s; main() { int ch; string regno; cout<<"\nVARIABLE LENGTH RECORDS"; while(1){ cout<<"\n1:Pack 2:Unpack 3:Search 4:Modify 5:exit\n"; cin>>ch; switch(ch) { case 1: s.read(); s.pack(); s.write_file(); break; case 2: s.read_file(); break; case 3: cout<<"Enter regno to search\n"; cin>>regno; s.search1(regno); break; case 4: cout<<"Enter regno to search\n"; cin>>regno; s.modify(regno); break; default : exit(0); }//switch }//while } void student::read() { cout<<"Enter details[USN,Name,Sem]\n"; cin>>usn>>name>>sem; } void student::pack() { buffer.erase(); buffer+=usn+"|"+name+"|"+sem+"$\n";

void student::read_file() { fstream fp; fp.open("3.txt",ios::in); while(!fp.eof()) { buffer.erase(); getline(fp,buffer); unpack(); if(!fp.eof()&& buffer[0]!='') display(); } fp.close(); } void student::unpack() { int i=0; usn.erase(); while(buffer[i]!='|') usn+=buffer[i++]; i++; name.erase(); while(buffer[i]!='|') name+=buffer[i++]; i++; sem.erase(); while(buffer[i]!='$') sem+=buffer[i++]; } void student::display() { cout<<"Usn:"<<usn<<" Name:"<<name<<" Sem:"<<sem<<endl; } int student::search1(string regno) { fstream fp; int recno=0,flag=0,pos=0; fp.open("3.txt",ios::in); while(!fp.eof()) { buffer.erase(); getline(fp,buffer); if(buffer[0]!='') //check the buffer ==* recno++; unpack(); if(usn==regno) { cout<<"\nRecord is "<<buffer; cout<<"\nRecord Found at Position "<<recno; pos=fp.tellg(); flag=1; return pos; } } fp.close(); if(!flag)