Lab 03 Week 3
Lab 03 Week 3
Task 1:
• Read an integer from file “read.txt” and write it in a new file
read.txt write.txt
2368 2368
• 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:
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”.
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:
Total 19300