0

Requirements: Use a class, an array, file input/output.

Goal: Compare the student answers (.txt) to the answer key (.txt) and output the students name, missed questions and overall score to a .txt.

Firstly, is my design decent?

What I need to do now is to compare student answers to the answer key. I've been struggling trying to think of a pattern or design to follow to implement the array. Any guidance is appreciated.

#include <fstream>
#include <string>
#include <iostream>
using namespace std;

class Test {
    private:
        double score_; // Total score
        string StudentAnswer_;
        double QuestionValue_; // 1 point for correct answer, 0 for omitted, 1/4 deducted for incorrect
        string QuestionType_; // 9 multiple choice, 8 T/F, 3 fill in the blank
    public:
        Test(); // default constructor

        // Setters (mutators)
        void SetStudentAnswer_(string answer);
        void SetQuestionType_(string type);
        void SetQuestionValue_(double value);

        // Getters (accessors)
        string GetStudentAnswer_();
        string GetQuestionType_();
        double GetQuestionValue_();
}; 

Test::Test() { // Constructor
    score_ = 0;
    StudentAnswer_ = " ";
    QuestionValue_ = 0;
    QuestionType_[20]; // 20 total test questions
}

// Set functions
void Test::SetStudentAnswer_(string answer) {
    StudentAnswer_ = answer;
}

void Test::SetQuestionValue_(double value) {
    QuestionValue_ = value;
}

void Test::SetQuestionType_(string type) {
    QuestionType_ = type;
}

// Get functions
string GetStudentAnswer_(string answer) {
    return answer;
}

double GetQuestionValue_(double value) {
    return value;
}

string GetQuestionType_(string type) {
    return type;
}

int main() {
    Test DoTest; // Object

    int data; // temp storage
    ifstream inStudentAnswers; // Open student answers and answer key then compare them
    ifstream inAnswerKey;
    ofstream outStudentAnswers; // Output student name, missed questions and overall test grade

    inStudentAnswers.open("studentanswers.txt");
    inAnswerKey.open("answerkey.txt");
    outStudentAnswers.open("studentresults.txt");

    if (inStudentAnswers.is_open() && inAnswerKey.is_open()) {

    }

} // end main

Edited by Joe_29

2
Contributors
1
Reply
37
Views
5 Months
Discussion Span
Last Post by thines01
0

A single question in the question-key file could have its own class.
You can then put all of the questions into a collection.
I would imagine a structure of (QUESTION_NUM, QUESTION_VALUE, ANSWER)
...maybe tab-delimited

The student's answer file would have a simpler structure (QUESTION_NUM, ANSWER) -- with the student ID somewhere in the filename.

The rule-set for how to calculate the result could/should be separate in case you want to change it.
Since you're keep ing the question-type (multiple choice, T/F, fill in the blank), is the program going to display the questions and respond differently with each question-type?

If this program is to ONLY GRADE, then question itself is not needed and the question type may not be needed -- just compare answers to ansers based on the question number. Aggregate the values based on the rule-set and deliver the score.

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.