Está en la página 1de 5

Programming Fundamentals

“Lab no 2”
(File Handling)
Note:-

 Submission is on UCP Portal.


 Submit only .cpp files named as (task1, task2, task3, task4) in a zip file.
 No late submission would be entertained.

Task 1

Write a C++ program in which you need to read the data from file. The first entry
represents the total count of entries. Your task is to find the occurrence(s) of every
entry.
Example file data:
5
1
1
2
3
4
Output:
Count of 1 2
Count of 2 1
Count of 3 2
Count of 4 1
Example file data:
10
4
66
4
1
1
2
3
66
4
66
Output:
Count of 4 3
Count of 1 2
Count of 2 1
Count of 3 1
Count of 66 3

Task 2
Modify the above program so that the position of every entry is recorded.
Example file data:
5
4
3
2
1
Output:
Position of 1 on lines = 2,3
Position of 2 on lines = 4
Position of 3 on lines = 5
Position of 4 on lines = 6

Example file data:


10
4
66
4
1
1
2
3
66
4
66

Output:
Position of 4 on lines = 2,4,10
Position of 66 on lines = 3,9,11
Position of 1 on lines = 5,6
Position of 2 on lines = 7
Position of 3 on lines = 8

Task 3

You are given the data of students in a csv file. Your task is to display the data on
the console from the file.
Example 1 of file:
Usama Tariq,18,M,89.99
Output:
Usama Tariq 18 M 89.99

Example 2 of file:
Waqas Waqar,40,M,45.00
Tariq,60,M,66.5
Rimsha Azeem,18,F,100.00
Rida Ali Yousaf,18,F,48.99
Iqra Umer,18,F,9.99

Output:
Waqas Waqar 40 M 45.00
Tariq 60 M 66.5
Rimsha Azeem 18 F 100.00
Rida Ali Yousaf 18 F 48.99
Iqra Umer 18 F 99.99

También podría gustarte