Objective: Discussion:

advertisement
ICS 103 – Computer Programming in C
Summer Semester 2008 (073)
Lab # 6 (Text File)
Objective:
1.
File pointer declaration
2.
Opening files
3.
fscanf and fprintf functions
4.
Closing files.
Discussion:
The following problem will be discussed in the class in detail:
Write a program that reads a set of grades from a data file and generates a new data file that stores
the ones that are 55 or higher.
Exercises #1:
1.
Open a new file and write the following data into it:
3 8 20
2.
Save the file into your working directory as input.dat.
3.
Write a program that reads those three integer numbers from input.dat file. The program
then calculates the average and prints the result in output.dat file.
Exercise # 2:
1.
Open a new file and write the following data into it:
2.
7
16
2
44
8
6
12
77
4
37
Save the file as lab6ex2.dat.
3.
Write a program that reads ten integer numbers from lab6ex2.dat file. The program then
finds the maximum and the minimum and displays the result.
1
HW # 4
1.
Due: next lab session
Open a new file and write the following data into it:
919999
928744
914628
918594
908736
928563
912534
912772
916352
906468
30
27
21
17.5
29
26
18
8
22.5
12
26
21
9.5
14
22
17
22
29.5
16
15
32
28
38.5
17
27
33
35
16
29
20.5
Note that columns 1, 2, 3, and 4 represent students IDs, exam 1 scores, exam 2 scores and
final exam scores respectively.
2.
Save the file as student.txt.
3.
Write a C program that takes its input data from student.txt file and then calculates the
total score for each student and the average of each exam and displays the following
output:
===========================================
ID
Exam 1
Exam 2
Final
Total
===========================================
919999
30.0
26.0
32.0
88.0
928744
27.0
21.0
28.0
76.0
914628
21.0
9.5
38.5
69.0
918594
17.5
14.0
17.0
48.5
908736
29.0
22.0
27.0
78.0
928563
26.0
17.0
33.0
76.0
912534
18.0
22.0
35.0
75.0
912772
8.0
29.5
16.0
53.5
916352
22.5
16.0
29.0
67.5
906468
12.0
15.0
20.5
47.5
===========================================
Average
21.1
19.2
27.6
67.9
4.
Save your program as xxxxxx.cpp where xxxxxx is your ID number.
Note: The submitted disk must contain both student.txt and xxxxxx.cpp files.
Submission Guidelines:
1. The homework must be submitted at the beginning of the next lab session in both soft and hard
copies.
2. Late homework is not accepted.
3. The homework must be solved individually. Any kind of cheating will result in F grade for all
parties involved.
2
Download