[英]how to read a data file that contain "name grade" and Calculate the GPA in clips
how to calculate the GPA in clips after reading from the file the file is: a 10 9 13 7从文件中读取后如何计算剪辑中的 GPA 文件是:a 10 9 13 7
b 12 3 10 14 b 12 3 10 14
c 8 10 12 10 c 8 10 12 10
d 15 8 14 9 15 8 14 9
output: a (10 9 13 7) 9.75 output:一个(10 9 13 7)9.75
b (12 3 10 14) 9.75 b (12 3 10 14) 9.75
Use the open function to open the file.使用open function打开文件。 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.您可以使用 readline function 获取一行数据,然后使用 explode$、nth$ 和 rest$ 函数获取名称和成绩列表。 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.