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

Assignment

This document outlines 9 steps for a programming lab assignment involving reading and writing files. The programs get increasingly complex, starting with basic input/output and eventually processing records for multiple students, calculating grades, and writing output to different files based on pass/fail status. Functions are introduced in the final program to modularize the grade calculations. The overall goal is to demonstrate concepts of file input/output, control structures, and functions through a series of programming exercises.

Uploaded by

Tiong Marcus
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
65 views

Assignment

This document outlines 9 steps for a programming lab assignment involving reading and writing files. The programs get increasingly complex, starting with basic input/output and eventually processing records for multiple students, calculating grades, and writing output to different files based on pass/fail status. Functions are introduced in the final program to modularize the grade calculations. The overall goal is to demonstrate concepts of file input/output, control structures, and functions through a series of programming exercises.

Uploaded by

Tiong Marcus
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

LAB 4

Objectives:
This lab cover topics Input and Output into a File (Chapter 6), Control Structure (Chapter 7
and 8) and Function (Chapter 9) of lectures.

Important Tip:
When you write a computer program, start with a simple program first for example just start
with a simple reading and writing process. If your program running well, then extend the
program step by step to cover the complex situation. This idea represents in this lab. Once
you see your program running, it becomes an addiction to continue writing your program.
---------------------------------------------------------------------------------------------------------------
Step 1
1. The program1 shows in Figure 1 is to read marks of three subjects (mark1, mark2, and
mark3) for a student from keyboard, calculate total marks (totalmark) and average marks
(avgmark) and then display the value of mark1, mark2, mark3, totalmark and avgmark
on the screen.
2. The input of the Program1 shows in Figure 2 and the output shows in Figure 3.

Figure 1: Program1 (Read data from keyboard and display output on the computer’s
screen).

1
Figure 2: Input of the program1 from computer keyboard.

Figure 3: Output of Program1 display on the computer’s screen.


---------------------------------------------------------------------------------------------------------------
Step 2
1. The program2 shows in Figure 4 is extension of Program1.
2. The Program2 read the input data from file input “student.dat” and display the values
of mark1, mark2, mark3, totalmark and avgmark on the computer’s screen.
3. The content of file “student.dat” shows in Figure 5.
4. You have to create file “student.dat” using notepad. To get the space between the
values, use <Spacebar> button, not <Tab> button.
3. The output of Program2 shows in Figure 3.

2
Figure 4: Program 2 (Read data input from file “student.dat” and display the output on the
computer’s screen)

Figure 5: Input file “student.dat”.


---------------------------------------------------------------------------------------------------------------
Step 3
1. The program3 shows in Figure 6 is extension of Program2.
2. The program3 read mark1, mark2, and mark3 from a data file “student.dat”, calculate
totalmark and avgmark and then write the values of mark1, mark2, mark3, totalmark
and avgmark into output file “student.out”.
2. Output file “student.out” is generate by the computer, not by you!!!
3. Input file “student.dat” shows in Figure 5 and the output file “student.out” shows in
Figure 7.

3
Figure 6: Program3 (Read data input from file “student.dat” and write the output into file
output “student.out”)

Figure 7: Output file “student.out”.


---------------------------------------------------------------------------------------------------------------
Step 4
1. The Program4 shows in Figure 8 is extension of Program3.
2. Program4 read name of student (studentname), mark1, mark2 and mark3 from input
file “student.dat”, calculate totalmark and avgmark and then write studentname,
mark1, mark2, mark3, totalmark and avgmark into output file called “student.out”.
2. Student name declare as 25 characters, but you can use only 24 characters only
because the last character reserves for “\0”.
3. A new input file “student.dat” shows in Figure 9 and a new output file “student.out”
shows in Figure 10.

4
Figure 8: Program4 (Read a studentname (string) from a file input and write a string into
file output).

Figure 9: A new input file “student.dat”.

Figure 10: A new output file “student.out”.


---------------------------------------------------------------------------------------------------------------
5
Step 5
1. Program 5 shows in Figure 11 perform the same operations with Program 4 but it is
write the title in the output file “student.out”.
2. The input file shows in Figure 9 and output file shows in Figure 12.

Figure 11: Program 5 (Write a title into file output “student.out”).

Figure 12: Output file “student.out” with a title.


------------------------------------------------------------------------------------------------------------
Step 6
1. Program 6 show in Figure 13 is extension of Program 5.
2. Program 6 is to repeat the process for 10 student records.
2. A new input file “student.dat” shows in Figure 14 and a new output file “student.out”
shows in Figure 15.

6
Figure 13: Program 6 (Process for 10 student records).

Figure 14: Input file “student.dat” with 10 student’s records.


7
Figure 15: Output file “student.out” with 10 student’s records.
---------------------------------------------------------------------------------------------------------------
Step 7
1. Program 7 show in Figure 16 is extension of Program 6.
2. Program 7 will print message “FAIL” or “PASS” at the end of each student record in
the output file.
2. If one of the student’s mark (mark1, marks or mark3) less than 40, a message “FAIL
will be print at the of student record. If all of the student’s marks greater than 40, a
message “PASS” will be display at the end of student’s record.
3. Input file “student.dat” shows in Figure 14 and a new file output “student.out” shows
in Figure 17.

8
Figure 16: Program 7 (Print message “FAIL” or “PASS” at the end of student’s record).

9
Figure 17: A new output file “student.out” with a “FAIL” or “PASS” message.
---------------------------------------------------------------------------------------------------------------
Step 8
1. Program 8 show in Figure 18 is extension of Program 7.
2. Program 8 is create another file output “studentfail.out” which contain list of student
failed at least one of the subjects.
3. Input file “student.dat” shows in Figure 12 and a new file output “studentfail.out”
shows in Figure 19.

10
Figure 18: Program 8 (Create another ouput file “studentfail.out” to record all failed
students).
11
Figure 19: Output file “studentfail.out” which contain all student’s records failed at least
one subject.
---------------------------------------------------------------------------------------------------------------
Step 9
1. Program 9 shows in Figure 20 perform the same operations with Program 8 but the
calculation of total mark and averages marks perform in different function named
caltotalmark and calaveragemark.
2. Input file “student.dat” shows in Figure 12 and the output of the file “student.out” and
“studentfail.out” shows in Figure 17 and Figure 19.

12
13
Figure 20: Program 9.

--- oooOooo ---

14

You might also like