0% found this document useful (0 votes)
106 views5 pages

Programming Fundamentals: "Lab No 2"

The document outlines 4 tasks related to file handling in C++. Task 1 involves reading data from a file, counting the occurrences of each unique entry, and outputting the results. Task 2 modifies Task 1 to also record and output the line positions of each entry. Task 3 involves reading student data from a CSV file and outputting it to the console. Task 4 was not described.

Uploaded by

Azaz Ali Shah
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)
106 views5 pages

Programming Fundamentals: "Lab No 2"

The document outlines 4 tasks related to file handling in C++. Task 1 involves reading data from a file, counting the occurrences of each unique entry, and outputting the results. Task 2 modifies Task 1 to also record and output the line positions of each entry. Task 3 involves reading student data from a CSV file and outputting it to the console. Task 4 was not described.

Uploaded by

Azaz Ali Shah
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/ 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

You might also like