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

Lab 3

The document contains 6 questions about reading and writing files in C++. Question 1 asks to read a file containing student data and print it. Question 2 reads a similar file using getline and prints the records. Question 3 reads student fees from a file, adds 4000 to each, and writes the results to a new file. Question 4 reads employee data using getline, prints the records and counts them. Question 5 reads a sentence from a file and separates the words into a new file. Question 6 reads words from a file, counts frequencies, and writes words with frequencies to another file.
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)
92 views

Lab 3

The document contains 6 questions about reading and writing files in C++. Question 1 asks to read a file containing student data and print it. Question 2 reads a similar file using getline and prints the records. Question 3 reads student fees from a file, adds 4000 to each, and writes the results to a new file. Question 4 reads employee data using getline, prints the records and counts them. Question 5 reads a sentence from a file and separates the words into a new file. Question 6 reads words from a file, counts frequencies, and writes words with frequencies to another file.
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

Lab 3

Question 1:
Write a program which will read from a file “sampleIn.txt” and print it on the screen. The file
contains student’s name, student Fee and department name.

SampleIn.txt

Name Fee Dept

Shourn 50000 IT
Francis 40000 Engineering
Clara 42000 Commerce
Kash 50000 Business

Output Screen

Student Name S. ID Dept.

Shourn 50000 IT

Francis 40000 Engineering

Clara 42000 Commerce

Kash 50000 Business

Question 2:
Write a program which reads the file sampleIn.txt as given below. use getline() function and
display it on the screen.

SampleIn.txt

Employee, Salary, Department

Ahsan Khan, 50000, IT


Alia Shams,60000, Management
Najam ul Saqib,30000,Sales
Ahmer Javed, 50000, HR

Output Screen

Employee Name Salary Department

Ahsan Khan 50000 IT


Alia Shams 60000 Management

Najam ul Saqib 30000 Sales

Ahmer Javed 50000 HR

Question 3:
Write a program which reads an input file of student’s “samplein.txt”, add the fee of each
student by 4000 and write the result in new file “sampleout.txt.”

Samplein.txt

Student Name, Fees

Shourn, 50000

Francis, 40000

Clara,42000

Kash,50000

sampleout.txt
Student Name , Fees

Shourn ,54000

Francis, 44000

Clara,46000

Kash,54000

Question 4:
Write a program which reads the file sampleIn.txt as given below. use getline() function and
display it on the screen and count the number of records present into the sampleln.txt.

SampleIn.txt
Employee, Salary, Department
Ahsan Khan, 50000, IT
Alia Shams, 60000, Management
Najam ul Saqib, 30000, Sales
Ahmer Javed, 50000, HR
Output Screen
Employee Name Salary Department
Ahsan Khan 50000 IT
Alia Shams 60000 Management
Najam ul Saqib 30000 Sales

Ahmer Javed 50000 HR

Question 5:
Write a C++ program in which, read a c-string sentence from file sentence.txt at once. Your task
is to separate each word into another c-string one by one and store them into a file word.txt.
Example:

sentence.txt word.txt
he
is
he is a good boy. a
good
boy

Question 6:
Write a C++ program in which, read a c-string word from a file “word.txt”. Your task is to find
the frequency of each word and store the word with its frequency separated by a coma into
another file word_frequency.txt
Example:

word.txt word_frequency.txt
Happy
Happy,2
Sad
Sad,1
Good
Good,1
Bad
Bad,1
Happy

You might also like