ASSIGNMENT – FILE
HANDLING CLASS XII A
Q1 Write a function count in C++ to count the no. of spaces
in a text file “ memo.txt”.
Q2 Write a function count in C++ to count the no. of vowels in a text file “ memo.txt”.
Q 3 Write a function count in C++ to count the presence of a
word ‘do’ in a text file “ memo.txt”.
Q4 Write a function count in C++ to count and display the no. of lines start
with ‘A’ in a file “ school.txt”.
Q 5 Given a binary file game.dat which has following structure type data
Struct game
{ int
gcode;
char gname[20];
char no_of_participant;
}
(1) write a function that would copy those structures from
game.dat to cricket.dat where gname is ‘cricket’.
(2) write a function that would update the value of
no_of_participant in the file game.dat.
Q 6 Given a binary file phone.dat which has following class type data
Class phonelist
{ char name[20];
char address[30];
char acode[5];
char pno[15];
public:
void register();
void show();
int checkcode(char ac[])
{
return strcmp(areacode,ac);
}
};
write a function that would copy those objects from
phone.dat to phoneback.dat where acode is “del”.
Q 7 void main()
{ char ch=’A’;
fstream
file(data.dat”,ios::app);
file<
int
p=file.tellg();
cout<
}
what will be the output if the file content before the
execution of the program is the string “ABC” (Note that “”are not the part of
the file)
Q8 Given the binary file ITEM.DAT,
containing the records of the following structure:
struct item
{
int item_no;
char item_name[20];
int stock;
};
Implement the function AddStock( item x, int n), which
updates a record by adding the existing stock for the item x in the file.
Q 9
Write a function in c++ to read and display the records of computers that cost
more than Rs. 20000 from the binary file “COMP.DAT”, assuming that the binary
file is containing the objects of the following class :
class
COMPUTER
{
int srno;
char
model[25];
float
price;
public:
float
Retpr( ) { return price; }
void
Enter( ){ cin>>srno>>price; gets(model); }
void
Display( ){ cout<
Q 10 Write a function RevText() to read a text file
“ Input.txt “ and Print each word in reverse order .
Example If value in text file is :
INDIA IS MY COUNTRY
Output will be :
AIDNI SI YM YRTNUOC
Q 11 Write a function in C++ to search for BookNo from a
binary file “BOOK.DAT”, assuming the binary file is contained the objects of
the following class:
class BOOK
{
int
Bno; char Title [20];
public
:
int
Rbno ( ) { return Bno; }
void
Enter ( ) { cin >> Bno; gets (Title); }
void
Display ( ) { cout << Bno <
};
Q 12 Following is the structure of each record in a data file named
“Colony.dat”
struct Colony
{
char colony_code[10];
char colony_name[10];
int no_of_people;
};
Wite
a function to update the file with a new value of No_of_people. The value of
colony_code and no_of_people are read
during the execution of the program.
Q 13 Assuming the
class ZOO given below, write functions in C++ to perform following:
i.
Write the objects of ZOO to a binary file.
ii.
Read the objects of ZOO from binary file and display
them on screen.
class ZOO
{
char
location[20];
int
no_of_animals[10];
public:
void
readdata()
{
cin>>location;
gets(no_of_animals);
}
void
writedata()
{
cout<
}
};
No comments:
Post a Comment