how to read a data file that contain "name grade" and Calculate the GPA in clips

81 Views Asked by At

how to calculate the GPA in clips after reading from the file the file is: a 10 9 13 7

b 12 3 10 14

c 8 10 12 10

d 15 8 14 9

output: a (10 9 13 7) 9.75

b (12 3 10 14) 9.75

1

There are 1 best solutions below

0
On

Use the open function to open the file. You can use the readline function to grab a line of data and then use the explode$, nth$, and rest$ functions to grab the name and list of grades. Here's an example reading from standard input rather than a file:

         CLIPS (6.4 2/9/21)
CLIPS> (bind ?i (readline))
a 10 9 13 7
"a 10 9 13 7"
CLIPS> (bind ?i (explode$ ?i))
(a 10 9 13 7)
CLIPS> (nth$ 1 ?i)
a
CLIPS> (bind ?grades (rest$ ?i))
(10 9 13 7)
CLIPS>