C++ 我怎样才能显示成绩?

C++ 我怎样才能显示成绩?,c++,C++,我真正需要做的就是显示成绩,但由于某种原因,我脑子里出了个屁,我一辈子都想不出来。对于你们这些必须知道的人来说,整个任务就是给我一个带有数字的文本文件。每行由四个考试分数组成,相当于一个学生。我必须计算每个学生的平均成绩并显示他们的成绩。我将如何继续使用我设置的代码 以下是文本文件中显示的数字: 44 55 77 88 79 88 100 99 77 99 98 99 100 88 89 100 55 56 40 77 100 100 99 95 88 84 87 88 96 97 99 100

我真正需要做的就是显示成绩,但由于某种原因,我脑子里出了个屁,我一辈子都想不出来。对于你们这些必须知道的人来说,整个任务就是给我一个带有数字的文本文件。每行由四个考试分数组成,相当于一个学生。我必须计算每个学生的平均成绩并显示他们的成绩。我将如何继续使用我设置的代码

以下是文本文件中显示的数字:

44 55 77 88
79 88 100 99
77 99 98 99
100 88 89 100
55 56 40 77
100 100 99 95
88 84 87 88
96 97 99 100
30 44 77 55
79 77 88 0
54 52 60 77
88 77 88 77
44 77 10 95
这是密码

// This program calculates a student's average test score, displays
// their grade and then reads the file back to the user.
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

int main()
{
    ifstream testscores; // Creating an object to output file.
    testscores.open("grades.txt"); // Opening the file.

    char grade; // A student's grade.
    int score1, score2, score3, score4; // Four test scores.
    double average; // The average test score for each student.

    cout << "These are the scores and grades for each student.\n\n";
    cout << "Averages           Grade";
    cout <<"\n--------           -----\n";

    if (!testscores) // Checking for errors otherwise.
        cerr << "Error opening file.\n";
    else
    {
        /*A loop that reads each number until it reaches the end of the file */
        while(testscores >> score1 >> score2 >> score3 >> score4)
        {
            // Calculate the average.
            average = (score1 + score2 +score3 +score4) / 4.0;
            cout << setw(2) << average << endl; // Display the average.
        }
        testscores.close(); // closing the file.
    }
    return 0;
}

似乎您只需要显示每个学生的分数。为此,您可以在显示每个学生的平均值之后使用if…else

if(average>=90)
grade='A';
if(average<90 && average >=80 )
grade='B';
if(average<80 && average >=70)
grade='C';
// and so on...then print:
cout<<"Grade="<<grade<<endl;

考虑更新标题来反映你的要求。需要一点指导是非常不具体的。我仍在努力找出你的问题所在。你已经计算了平均值,现在你想根据平均值计算分数?是的,我想我可以在while循环中使用一些if/else语句,但这是我最好的猜测。那么,关于你应该如何计算分数的作业是什么呢?当然,别担心。