Anda di halaman 1dari 3

Class XII

Assignment : File Handling

Q1. What is the purpose of read and write function in file handling?
Q2. Differentiate between: -
a. ios::nocreate, ios::noreplace and ios::out.
b. Read() and get()
c. Write() and put()
d. Ios::cur and ios::app
e. Ios::ate and ios::app
Q3. What is the purpose of ios::binary?
Q4. Name the heard file used in file handling in c++.
Q5. Write a program to accept a text file name from the user and display the following
menu:
1. Encrypt content of file( copy content to another file by changing vowel
with numbers 1 to 5 and consonants with next consonant eg D with F)
2. Encrypt Alphabets( change contents of original file by changing alphabet
with ASCII value +20)
3. Convert a file(change cases in the file ie upper to lower and lower to
upper)
4. Frequency table ( where you display no of words, characters, lines,
uppercase, lowercase, digits, special characters and no of bytes)
Q6. Consider a structure
struct labor
{
int lcode;
char name[20];
float wage;
int nofohours;
};
Write user defined functions using labor.dat file:-
1. Add
2. Delete
3. Modify
4. Search on the basis of lcode
5. search on the basis of name
6. Display money earned by each labor
Q6. Consider a student
class student
{
int scode;
char name[20];
float fee_paid;
public:
void getdata()
{
cin>>scode; gets(name); cin>>fee_paid;
}
void displaydata()
{
cout<<scode<<name<<fee_paid<<endl;
}
int return_code()
{
return scode;
}
float return_feepaid()
{
return fee_paid;
}
};
Write user defined functions using student.dat file:-
1 Add
2 Delete
3 Modify
4 Search on the basis of scode
5 Display total fee paid by all the students
Q7. Consider a class staff
class staff
{
int empcode;
char name[20];
float salary;
public:
void getdata()
{
cin>>empcode; gets(name); cin>>salary;
}
void displaydata()
{
cout<<empcode<<name<<salary<<endl;
}
Void updatesalary(int incr)
{
Salary+=inrc;
}
int return_code()
{
return empcode;
}
}e;
The company is increment salary of every employee after displaying the empcode
incremented amount is accepted and then file updated. Complete the code:-
void update()
{
int ecode;
fstream fp(“Empl.dat”,ios::in|ios::out|ios::binary);
while(fp.read((hcar * )&e,sizeof(e)))
{
cout<<”Employee code”<<e.return_code;
cout<<”enter Increment value”;
cin>>ic;
e.updatesalry(ic);
_____________________________________ // give command to write at
appropriate position
___________________________________// give command to write in
file
}
fp.close();
}
Q8. Give Command:-
a. To move file pointer fp to 20th byte
b. To tell position of read pointer
c. To move file pointer File back by 30 bytes
d. To move file pointer FP back by 20 bytes from end position
e. To move file pointer FP1 on 0th byte.
Q9. Read the following program and predict the output
void main()
{
fstream fp(“ab.txt”,ios::app);
fp<<’Z’;
cout<<fp.tellp();
}
The file ab.txt had ABCD
What will be the output, if we open the file in output mode.
Q10. What is the relationship between fstream, ifstream, ofstream and iostream?

Anda mungkin juga menyukai