Lab 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
Shourn 50000 IT
Francis 40000 Engineering
Clara 42000 Commerce
Kash 50000 Business
Output Screen
Shourn 50000 IT
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
Output Screen
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
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
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