You are on page 1of 2

Lab

Sheet 12 Files & Streams

Programs on Text Files: 1. Write a C++ program to write number 1 to 100 in a data file NUMBERS.TXT 2. Write a C++ program to read the content from a text file OUT.TXT, count and display the number of alphabets present in it. 3. Write a C++ program to count the number of blank present in a text file named "OUT.TXT". 4. Write a function in C++ to print the count of word the as an independent word in a text file STORY.TXT. for example, if the content of the file STORY.TXT is There was a monkey in the zoo. The monkey was very naughty. Then the ouput of the program should be 2.

Programs on Binary Files (reading & writing Objects): 1. Consider the following class declaration: Class bank { Int accno; Chat name[20]; Float balance; Public: Void input() { Cin>>accno>>name>>balance; } Void display() { Cout<<accno<< <<name<< balance << endl; } Float getbalance() { Return balance; } }; Give function definitions to the following:

I. II.

Write a function in C++ to accept the objects of class bank from the user and write to a binary Bank.dat. Write a function in c++ to read the objects of bank from a binary file and display all the objects on screen where balance is more than Rs. 25,000.

2. Consider the following class declaration: Class Employee { int empcode; char empname[20]; char empdesg[15]; float empsalary; public: void add_data(); void read_data(); void mod_data(); void del_data(); void show_data(); } }; Write a C++ program that allows the user to add an employee record, read any one employee record at a time, and modify a record at a time using binary files. Overloading Stream insertion & Extraction Operator 1. Create a Class complex that accepts the complex number with it real and imaginary part by overloading the >> and << operator.

You might also like