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

C++ Worksheet 10-1-1

This document describes two programs completed by a student. The first program copies the contents of one file to another and displays it on the output screen. It takes input file names, opens the files, copies characters from the source file to the target file until the end of file, then closes the files and prints a success message. The second program reads student name and age from keyboard, stores it in a file using read() and write() functions, reopens the file and displays the contents on the screen. It uses a Student class, input/output functions, and file handling operations like open, read, write and close. Both programs aim to demonstrate file handling in C++.

Uploaded by

Prince
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)
87 views10 pages

C++ Worksheet 10-1-1

This document describes two programs completed by a student. The first program copies the contents of one file to another and displays it on the output screen. It takes input file names, opens the files, copies characters from the source file to the target file until the end of file, then closes the files and prints a success message. The second program reads student name and age from keyboard, stores it in a file using read() and write() functions, reopens the file and displays the contents on the screen. It uses a Student class, input/output functions, and file handling operations like open, read, write and close. Both programs aim to demonstrate file handling in C++.

Uploaded by

Prince
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

STUDENT’S NAME – Yashdeep


STUDENT’S UID – 21BCS4897
CLASS AND GROUP – 504-A
SEMESTER – 2nd

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:Input the name of source file and pass through fopen(…)method and
store in fs

STEP 6: if fs=NULL print error occurred


STEP 7: Input the name of target file and passthrough fopen(…)method and 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 :-
STUDENT’S NAME – Yashdeep
STUDENT’S UID – 21BCS4897
CLASS AND GROUP – 504-A
SEMESTER – 2nd

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
files 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 input data and read data STEP 13: open file1

STEP14: again open the file in read mode STEP 15: read

data from the file

STEP16:display data on monitor STEP 17:

close the file

STEP 18: STOP


PROGRAM CODE –
OUTPUT PROGRAM –
Explanation:
1. In this program we have to reflect one files data to other using pointer body functions, initially
we take our inputs using array systems of source required files and then adress them using pointer
variable.

Using fget and null void function to derive & coly the data to output. we are able to pront required
results

2. In this program we store , record and print a set of data.. initially the input is stores in read() and
write () function and then we create getdata() amd showdata(), using fstream we link the two and
print our appropriate results.

LEARNING OUTCOMES
 Identify situations where computational methods would be useful.
 Approach the programming tasks using techniques learnt and write pseudo-code.
 Choose the right data representation formats based on the requirements of the problem.
 Use the comparisons and limitations of the various programming constructs and choose the
right one for the task.

EVALUATION COLUMN (To be filled by concerned faculty only)


Sr. No. Parameters Maximum Marks
Marks Obtained
1. Worksheet Completion including 10
writing learning objective/ Outcome
2. Post Lab Quiz Result 5

3. Student engagement in 5
Simulation/ Performance/ Pre Lab
Questions
4. Total Marks 20

You might also like