0% found this document useful (0 votes)
50 views10 pages

Aim of Experiment - : WAP To Copy The Contents of One File To Another and Display It On Output Screen

This document describes an experiment in C++ to copy the contents of one file to another. The key steps are: 1) Declare variables to store the names of the source and target files. 2) Open the source file and store the file pointer. 3) Read characters from the source file and write them to the target file until the end of file is reached. 4) Print a message to confirm the file copy was successful and close both files.

Uploaded by

Adarsh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views10 pages

Aim of Experiment - : WAP To Copy The Contents of One File To Another and Display It On Output Screen

This document describes an experiment in C++ to copy the contents of one file to another. The key steps are: 1) Declare variables to store the names of the source and target files. 2) Open the source file and store the file pointer. 3) Read characters from the source file and write them to the target file until the end of file is reached. 4) Print a message to confirm the file copy was successful and close both files.

Uploaded by

Adarsh Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

EXPERIMENT NUMBER 10

NAME – KANISHK NAYAK BRANCH – B.E C.S.E

UID – 21BCS8240 CLASS –BCS218/A

SUBJECT – C++ D.O.P – 4/5/22

Aim of Experiment - WAP to copy the contents of one file to another and display it on output
screen.

Things to do Before Program


Create two files say codes.txt and cracker.txt inside the same directory where you're saving our C++ source code.
That is, either:

Create two files inside the directory where you're saving your program or going to save your C++ program of copy file
(given below)
Or save your C++ program (that copies the content of one file to another) in that folder where the two files codes.txt
and
cracker.txt are created.

Algorithm –

STEP 1: START

STEP 2: Declare Header file and namespace

STEP 3: In main method declare ch, sourcefile[20],targetfile[20] STEP 4: Declare

File*fs,*ft

STEP5:Inputthenameofsourcefileandpassthroughfopen(…)methodand
store in fs

STEP 6: if fs=NULL print error occurred


STEP 7: Inputthename of targetfileandpassthroughfopen(…)methodand store in ft

STEP 8:ch=fget(fs)

STEP 9:if(ch!=EOF)

STEP10:fput(ch,ft)

STEP 11: ch=fget(fs) goto

STEP 12: print “File copied Successfully”

STEP 13: fclose(fs)

STEP 14: fclose(ft)

STEP 15: STOP


PROGRAM CODE –
Output. Program :-
Aim of Experiment – WAP to read the class object of student info
such as name, age and roll no from the keyboard and to store them
on a specified file using read() and write() functions. Again the
same file is opened for reading and displaying the contents of the
file on the screen.

Algorithm –
STEP 1: START

STEP 2: Declare Header file and namespace and declare a class Student

STEP3:InStudentdeclareprivatemembernameofsize30andagevariables STEP 4: Input

name and age under function getData()

STEP 5: Define showData() to print the data

STEP 6: In main method declare student object, ofstream file STEP 7: open the

file using file.open function

STEP 8: if(file is not present then print “Error message”) else print ”file created
successfully ”

STEP 9: call getData using the student’s object STEP 10:

Write into file

STEP 11: Close the file


STEP12:reopenfile in inputdataandreaddata STEP 13: open file1

STEP14:againopenthefilein readmode STEP 15: read

data from the file

STEP16:displaydataonmonitor STEP 17:

close the file

STEP 18: STOP


PROGRAM CODE –
OUTPUT PROGRAM –

You might also like