首页 文章

C自动评分系统

提问于
浏览
0

我无法按照规范完成作业 . 这是分配方案:

大学迫切需要一个自动测试评分系统 . 使用C,为大学写一个评分系统,并对至少五名学生的测试进行评分 . 要创建评分系统,请按照以下步骤操作:首先询问测试中的问题数量然后询问每个问题的正确答案 . 请注意,多项选择测试和问题将从A到D得到答案 . 询问学生人数并通过询问他们的姓名来处理每个学生,然后循环询问学生的答案 . 为每个问题打分 . 在最后一个问题计算出学生得分后,显示“学生'插入学生姓名'得分为20分中的10分或50% . ”重复,直到所有学生都得分 . 在对所有学生进行评分后,以与以前相同的方式插入打印所有学生成绩的 class 列表 .

这是我到目前为止:

#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
    //declare variables
    char choice;
    string studentName;
    vector<char> answers;
    vector<string> names;
    int getStudents();
    int getQuestions();

    //calls function to get number of questions
    float questions = getQuestions();


    //Get answers
    for (int i = 0; i < questions; ++i) {
        cout << "What is the answer for question " << i + 1 << endl;
        cin >> choice;
        answers.push_back(choice);
    }

    //Get number of students
    int students = getStudents();


    //Get student names
    for (int i = 0; i < students; i++) {
        cout << "Student " << i + 1 << ", what is your name?" << endl;
        cin >> studentName;
        names.push_back(studentName);
    }

    float score = 0;
    char studentAnswer;
    vector<char> userAnswer;
    vector<float> finalScore;

    //gets student answers
    for (int i = 0; i < students; i++) {
        for (int j = 0; j < questions; j++) {
            cout << names[i] << ", what is your answer for question " << j + 1 << "?" << endl;
            cin >> studentAnswer;
            userAnswer.push_back(studentAnswer);
        }
    }



    //calculates student scores
    for (int i = 0; i < students; i++) {
        for (int j = 0; j < questions; j++) {
            if (userAnswer[j] == answers[j])
                score = score + 1;
                }       
        finalScore.push_back(score);
    }

    //outputs scores
    for (int i = 0; i < students; i++) {
        cout << names[i] << " scored " << finalScore[i] << " out of " << questions <<
            " or " << (finalScore[i] / questions) * 100 << "%" << endl;
    }



    system("pause");
    return 0;
}
//function to get number of questions
int getQuestions()
{
    int questions;
    cout << "How many questions are there?" << endl;
    cin >> questions;
    return questions;
}
//function to get number of students
int getStudents()
{
    int students;
    cout << "How many students are there?" << endl;
    cin >> students;
    return students;
}

最终得分返回的值不准确,我找不到错误发生的位置 .

同样,为了在最后一步中进行排序,我被要求按升序或字母顺序按降序和名称排序 . 我能够相互独立地排序这些,但不知道如何将它们组合起来并按照这种方式对它们进行排序 .

2 回答

  • 3

    您将 score 初始化为0,但之后您不会为每个学生重置它 . 你应该做这个:

    //calculates student scores
        for (int i = 0; i < students; i++) {
            score = 0; // here, so that it is reset for each student
    

    顺便说一句,你的 questions 变量是 float ,我想你想要一个 int .

  • 3
    //calculates student scores
    for (int i = 0; i < students; i++) {
        score = 0; //Fabio was right you need to reset score to 0 for each student
        for (int j = 0; j < questions; j++) {
            if (userAnswer[j] == answers[j])
                score = score + 1;
                }       
        finalScore.push_back(score);
    }
    

    当你检查 userAnswer 是否等于 answers 时,你总是从0开始 . 所以你每次都要检查学生1的答案 . 你可以尝试:

    if (userAnswer[i*questions+j] == answers[j])
    

相关问题