24.3k views
3 votes
1) Create a text file students.txt, contains information about an unknown number of students in 230 class as follow:

1150987 87.40 37 82.3 16
1160098 72.82 103 73.8 15
.
.
1161430 68.55 68 85.0 18


Each line contains: student-number , accumulative average so far , total credits taken , average this semester , credits registered this semester.

2) Let the program reads from the file students.txt and computes the final accumulative average for each student as follow:

Final accumulative average =

( ( accumulative average so far * total credits taken ) + (average this semester * credits registered this semester ) ) /
( total credits taken + credits registered this semester )

3) Write a function calculate that.

receives student-number, accumulative average so far, total credits taken, average this semester, credits registered this semester and returns the final accumulative average


4) Display on another text file result.txt the result as shown below:


Student Number Total New Credits finished Final Accumulative Average
-------------------- --------------------------------- -----------------------------------
. . .
. . .
. . .
. .
5) The program should display also the number of students who received an honor (Accumulative Average >=85) and the number of students whose Accumulative Average <=65.

1 Answer

4 votes

Answer:

1. To create a text file called students.txt that contains the information about the unknown number of students in class 230, you can use a text editor such as Notepad or TextEdit to create the file and enter the information in the format specified.

2.To read the information from the students.txt file and calculate the final accumulative averages for each student, you can use Python programming language and the following steps:

. Open the students.txt file using the built-in open() function and assign the file object to a variable.

.Use a for loop to iterate over each line of the file, using the built-in readlines() method.

. Split each line of the file into individual elements using the built-in split() method.

. Assign each element to a variable, such as student_number, accumulative_average, total_credits, this_semester_average, and this_semester_credits.

. Use the final accumulative average formula to calculate the final accumulative average for each student.

. Close the file using the built-in close() method.

3. To write a function that calculates the final accumulative average, you can use the following steps:

. Define the function, and give it a name, such as calculate()

. Pass in the necessary parameters, such as student_number, accumulative_average, total_credits, this_semester_average, and this_semester_credits

. Use the final accumulative average formula to calculate the final accumulative average for each student.

. Return the final accumulative average

4. To display the results in another text file called result.txt, you can use the following steps:

. Open a new file using the built-in open() function, and assign the file object to a variable.

. Use the built-in write() method to write the student number, total new credits, finished credits, and final accumulative average to the file.

. Close the file using the built-in close() method.

5. To display the number of students who received an honor (Accumulative Average >=85) and the number of students whose Accumulative Average <=65, you can use a counter variable, and increment it each time you encounter a student with accumulative average >= 85 or <= 65. At the end of the iteration, you can print the counter variable.

User JAponte
by
8.7k points