BNMIT file structure lab manual - baixardoc
-
Upload
khangminh22 -
Category
Documents
-
view
0 -
download
0
Transcript of BNMIT file structure lab manual - baixardoc
Vidyaya Amrutham Ashnuthe
Department of Information Science & Engineering
FILE STRUCTURE LABORATORY MANUAL
SUBCODE: 06ISL67, VI SEMESTER B.E
BNM Institute of Technology
(Approved by AICTE & Affiliated to VTU, Karnataka)
(An ISO 9001:2008 Certified Institution)
Post Box No, 7087, 27th cross, 12th Main Road,
Banshankari 2nd Stage, Bengalore-560070
Phone: 91-8026711781/26711782
Fax: 91-80-26710881,E-mail:[email protected]
Visit us at: www.bnmit.org
VTU LAB SYLLABUS
FILE STRUCTURE LABORATORY
Subject Code : 06ISL67 IA Marks : 25
No. of Practical
Hours/Week
: 03 Exam Hours : 03
Total No. of Practical
Hours
: 42 Exam Marks : 50
1. Write a C++ program to read series of names, one per line, from standard input and
write these names spelled in reverse order to the standard output using I/O
redirection and pipes. Repeat the exercise using an input file specified by the user
instead of the standard input and using an output file specified by the user instead of
the standard output.
2. Write a C++ program to read and write student objects with fixed-length records and
the fields delimited by “|”. Implement pack ( ), unpack ( ), modify ( ) and search ( )
methods.
3. Write a C++ program to read and write student objects with Variable - Length
records using any suitable record structure. Implement pack ( ), unpack ( ), modify (
) and search ( ) methods.
4. Write a C++ program to write student objects with Variable - Length records using
any suitable record structure and to read from this file a student record using RRN.
5. Write a C++ program to implement simple index on primary key for a file of student
objects. Implement add ( ), search ( ), delete ( ) using the index.
6. Write a C++ program to implement index on secondary key, the name, for a file of
student objects. Implement add ( ), search ( ), delete ( ) using the secondary index.
BNMIT/ISE/2012/VI/ File Structure laboratory Page 2
7. Write a C++ program to read two lists of names and then match the names in the two
lists using Cosequential Match based on a single loop. Output the names common to
both the lists.
8. Write a C++ program to read k Lists of names and merge them using k-way merge
algorithm with k = 8.
9. Write a C++ program to implement B-Tree for a given set of integers and its
operations insert ( ) and search ( ). Display the tree.
10. Write a C++ program to implement B+ tree for a given set of integers and its
operations insert ( ), and search ( ). Display the tree.
11. Write a C++ program to store and retrieve student data from file using hashing. Use
any collision resolution technique.
12. Write a C++ program to reclaim the free space resulting from the deletion of
records using linked lists.
ContentsVTU LAB SYLLABUS ...................................................................................... 2
Contents ...................................................................................................... 3
BNMIT/ISE/2012/VI/ File Structure laboratory Page 3
Program 1 .................................................................................................... 5
Program 2 .................................................................................................... 9
Program 3 .................................................................................................. 19
Program 4 .................................................................................................. 27
Program 5 .................................................................................................. 33
Program 6 .................................................................................................. 42
Program 7 .................................................................................................. 58
Progrm 8 .................................................................................................... 63
Program 9 .................................................................................................. 68
Program 10 ................................................................................................ 79
Program 11 ................................................................................................ 93
Program 12 .............................................................................................. 100
BNMIT/ISE/2012/VI/ File Structure laboratory Page 4
Program 1
Write a C++ program to read series of names, one per line, from standard input
and write these names spelled in reverse order to the standard output using I/O
redirection and pipes. Repeat the exercise using an input file specified by the user
instead of the standard input and using an output file specified by the user instead
of the standard output.
#include<iostream.h>
#include<conio.h>
#include<process.h>
#include<string.h>
#include<fstream.h>
class names
{
public:char name[50];
};
void reverse(ofstream &out,char name[255])
{
char *rev;
rev=name+strlen(name)-1;
while(rev>=name)
{
cout<<*rev;
out<<*rev;
rev--;
}
cout<<endl;
out<<"\n";
BNMIT/ISE/2012/VI/ File Structure laboratory Page 5
}
void main()
{
names n[10];
clrscr();
ofstream out;
out.open("file.txt",ios::out|ios::app|ios::trunc);
int m;
cout<<"enter the no. of names to be entered\n";
cin>>m;
for(int i=0;i<m;i++)
{
cout<<"enter name";
cin>>n[i].name;
cout<<"the name in reverse order";
reverse(out,n[i].name);
}
out.close();
ifstream in;
in.open("file.txt",ios::in|ios::binary);
ofstream outf;
outf.open("f1.txt",ios::out|ios::app|ios::trunc);
char ch[255];
cout<<"names from files\n";
while(in)
{
in.getline(ch,255);
if(in)
reverse(outf,ch);
BNMIT/ISE/2012/VI/ File Structure laboratory Page 6
}
cout<<endl;
in.close();
outf.close();
in.open("f1.txt",ios::in|ios::binary);
outf.open("f2.txt",ios::out|ios::app|ios::trunc);
cout<<"reverse order from files\n";
while(in)
{
in.getline(ch,255);
if(in)
reverse(outf,ch);
}
in.close();
outf.close();
getch();
}
Output:
Enter the no. of names to be entered
5
Enter name
priya
The name in reverse order
ayirp
Enter name
padma
The name in reverse order
amdap
Enter name
BNMIT/ISE/2012/VI/ File Structure laboratory Page 7
ajit
The name in reverse order
tija
Enter name
sohan
The name in reverse order
nahos
Enter name
dilip
The name in reverse order
pilid
The names from files (f1.txt)
priya
padma
ajit
soni
dilip
Reverse order from files (f2.txt)
ayirp
amdap
tija
nahos
pilid
BNMIT/ISE/2012/VI/ File Structure laboratory Page 8
Program 2
Write a C++ program to read and write and student objects with fixed length
records and the fields delimited by “|”.implement pack(),unpack(),modify() and
search() methods.
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
#include<stdlib.h>
#include<fstream.h>
#include<string.h>
class student
{
public:char name[25],usn[15],branch[15],buffer[45];
};
student s,s1[100];
char extra[45];
int i,no=0,mode=0;
void pack()
{
fstream app;
if(mode==0)
app.open("st1.txt",ios::app);
else
app.open("st1.txt",ios::out);
if(!app)
{
cout<<"cant open the file in output mode";
BNMIT/ISE/2012/VI/ File Structure laboratory Page 9
getch();
exit(0);
}
strcpy(s.buffer,s.name);
strcat(s.buffer,"|");
strcat(s.buffer,s.usn);
strcat(s.buffer,"|");
strcat(s.buffer,s.branch);
int count=strlen(s.buffer);
for(int k=0;k<45-count;k++)
strcat(s.buffer,"|");
strcat(s.buffer,"\n");
app<<s.buffer;
app.close();
}
void unpack()
{
fstream in;
in.open("st1.txt",ios::in);
i=0,no=0;
if(!in)
{
cout<<"cant open the file in input mode";
getch();
exit(0);
}
while(!in.eof())
{
in.getline(s1[i].name,15,'|');
BNMIT/ISE/2012/VI/ File Structure laboratory Page 10