0% found this document useful (0 votes)
2 views

practical 10YG

The document describes a practical exercise for a student named Yash Amit Gadade, focusing on creating a class FileDemo in C++. The program demonstrates how to open a file in write mode, input user data, and then read the data back from the file. The code includes functionalities for writing to and reading from a file, showcasing basic file handling in C++.

Uploaded by

Ahlam Khan
Copyright
© © All Rights Reserved
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)
2 views

practical 10YG

The document describes a practical exercise for a student named Yash Amit Gadade, focusing on creating a class FileDemo in C++. The program demonstrates how to open a file in write mode, input user data, and then read the data back from the file. The code includes functionalities for writing to and reading from a file, showcasing basic file handling in C++.

Uploaded by

Ahlam Khan
Copyright
© © All Rights Reserved
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/ 3

Practical No:3

Name:-Yash Amit Gadade Roll No:-28 Class:FYIT

Subject:-Object Oriented programing with c++ Date:-

Q A) Design a class FileDemo open a file in read mode and display the total
number of words and lines in the file.Program:
Code:-

#include <fstream>

#include <iostream>

using namespace std;

int main () {

char data[100];

// open a file in write mode.

ofstream outfile;

outfile.open("afile.dat");

cout << "Writing to the file" << endl;

cout << "Enter your name: ";

cin.getline(data, 100);

// write inputted data into the file.

outfile << data << endl;

cout << "Enter your age: ";

cin >> data;


cin.ignore();

// again write inputted data into the file.

outfile << data << endl;

// close the opened file.

outfile.close();

// open a file in read mode.

ifstream infile;

infile.open("afile.dat");

cout << "Reading from the file" << endl;

infile >> data;

// write the data at the screen.

cout << data << endl;

// again read the data from the file and display it.

infile >> data;

cout << data << endl;

// close the opened file.

infile.close();

return 0;

}
Output:-

You might also like