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

Lab 03 Week 3

The document outlines a series of tasks related to file handling in programming. It includes reading various data types from a file and writing them to new files, calculating sums and averages, determining maximum and minimum values, and storing election results. Each task specifies input and output files along with the expected results.

Uploaded by

Narmeen Javed
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)
2 views

Lab 03 Week 3

The document outlines a series of tasks related to file handling in programming. It includes reading various data types from a file and writing them to new files, calculating sums and averages, determining maximum and minimum values, and storing election results. Each task specifies input and output files along with the expected results.

Uploaded by

Narmeen Javed
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/ 2

PF B20 Lab Week 02

Topic File Handling

Task 1:
• Read an integer from file “read.txt” and write it in a new file
read.txt write.txt
2368 2368

• Read a double from file “read.txt” and write it in a new file.


read.txt write.txt
52.37 52.37

• Read a bool from file “read.txt” and write it in a new file.


read.txt write.txt
1 1

• Read a float from file “read.txt” and write it in a new file.


read.txt write.txt
543.52 543.52

• Read a char array from file “read.txt” and write it in a new file.
read.txt write.txt
This is PF Lab This is PF Lab

Task 2: Write a program that reads 5 integer numbers from a file “integer.txt”, and
store sum and average in “result.txt”.

integer.txt result.txt
21374 Sum is 17
Average is 3

Task 3: Write a program that reads 5 integer numbers from a file “integer.txt” and
store Maximum and Minimum in “result.txt”.
integer.txt Result.txt
21374 Max is 7
Min is 1
Task 4: Write a program that reads an average from file “average.txt”, and store the
status in “newfile.txt” on the basis of following criteria:

If Average < 4, then Below Average


If 4 <= Average <= 6, then On Average
If Average > 6, then Above Average

average.txt newfile.txt
3 below average

Task 5: Write a program in which, you have to insert an integer value n in the start of
file “integer.txt”.

integer.txt Input Integer.txt


21374 9 921374

Task 6: Write a program that allows the user to enter the names of five candidates in
a local election and the number of votes received by each candidate. The program
should then write each candidate’s name, the number of votes received, and the
percentage of the total votes received by the candidate into a file name “result.txt”.
Your program should also write the winner of the election. A sample output is:

Candidate Votes Received % of Total Votes


Abbas 5000 25.91
Bilal 4000 20.73
Duffy 6000 31.09
Daood 2500 12.95
Hassan 1800 9.33

Total 19300

The Winner of the Election is Duffy.

You might also like