C++有什么方法可以对文本文件的部分进行分类,然后单独使用它们?
我目前正在尝试做我的大学作业,我们现在正在研究C ++的文件流和向量,我们的任务很长,但我只是尝试解释我的主要问题:
我们需要阅读多个文本文件并获取信息并存储它们在向量中, 无论如何,在我们的第一个文本文件中,我们需要像这样阅读的部分:
作业
00011234 84
00012341 90
00012481 100
中期
00011234 55
00012341 99
00012481 50
(学生ID,等级)
等...在我们的任务中,我们需要获得10%的家庭作业等级,20%的中期成绩和最终成绩的30%,然后获得与学生ID相关的成绩的总和。
我的问题是:有什么方法可以通过迭代或对这些信息进行分组,并使用它们来获取相关百分比? (顺便说一句,我们还没有学习类/结构/指针,因此禁止在我们的任务中使用它们,只有向量,fstream,sstream,string库。) 此外,学生有多个家庭作业等级,或者只有1个作业等级等(我们需要占据百分比并总和该学生的所有等级)
I am currently trying to do my college homework, we are studying file streams and vectors in C++ right now, our task is long but I will just try to explain my main problem:
We need to read multiple text files and get information and store them in vectors,
anyways, in our first text file, there are parts we need to read like this:
HOMEWORK
00011234 84
00012341 90
00012481 100
MIDTERM
00011234 55
00012341 99
00012481 50
(student Id, grade)
etc... In our task, we need to get 10% of homework grade, 20% of midterm grade and 30% of final grade, and then take the sum of grades related with student id's.
My question is: is there any way to read by iteration or group these informations, and use them to take related percentages?
(btw we didn't learn classes/structs/pointers yet, so it's forbidden to use them in our task, just vectors, fstream, sstream, string libraries.)
Also, there are multiple homework grades for a student, or only 1 homework grade etc. (We need to take percentages and sum all grades of that student)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有很多方法可以解决这个问题,但是一个简单的方法是使用
break
关键字在满足特定条件时退出循环。There are many ways of going about that, but a simple one is to use the
break
keyword to exit out of a loop when a certain condition is met.