0% found this document useful (0 votes)
235 views2 pages

Lab Sheet 12 - Files

This document provides examples of C++ programs involving text and binary files: 1. It describes programs to write numbers to a text file, read and count characters/words from a text file, and count blank spaces in a text file. 2. It discusses functions to write and read class objects from a binary file, including accepting user input and displaying objects with balances over Rs. 25,000. 3. It outlines a program for a class representing employees that allows adding, reading, modifying and deleting records from a binary file using class methods. 4. The final example creates a complex number class that overloads insertion and extraction operators for user input/output.

Uploaded by

AmritaRupini
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
235 views2 pages

Lab Sheet 12 - Files

This document provides examples of C++ programs involving text and binary files: 1. It describes programs to write numbers to a text file, read and count characters/words from a text file, and count blank spaces in a text file. 2. It discusses functions to write and read class objects from a binary file, including accepting user input and displaying objects with balances over Rs. 25,000. 3. It outlines a program for a class representing employees that allows adding, reading, modifying and deleting records from a binary file using class methods. 4. The final example creates a complex number class that overloads insertion and extraction operators for user input/output.

Uploaded by

AmritaRupini
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy