Thread: Grading Program

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    5

    TROUBLESHOOTING - Grading Program

    Hi, i'm in an introductory C++ programming class, buti have to do a (what i think is difficult) project. i have to grade an exam from a file. the first line is the key (abcdefabcdef etc.) and the second line is the student's answers. could anyone clue me in as to how to grade each question one-by-one and record them as correct or incorrect? thanks a lot, i appreciate it!

    jeff
    Last edited by hockeydrummer88; 03-08-2005 at 01:47 PM.

  2. #2
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    There are many simple ways you can accomplish this. You can read each line to a string or an array. Use a simple loop that would compare each element of the string/array and increment counters for correct or incorrect answers.

    More importantly though, what are you currently studying in your class? Whatever method you use to accomplish the task should weigh heavily on what you're currently learning. Even if it's not the best or most simple method, it's probably being emphasized as a learning tool.

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    5

    reply

    we've covered about half of our textbook (which isn't very helpful at all) which covers syntax, numeric types, expressions, output, program input (files and such), conditions, boolean exressions and loops.

    however, neither the book nor our professor go into much detail showing actual ways to execute all these techniques we're supposedly learning.

    we have to use a while loop in our program, but i'm not really sure how to use them in this situation.

    any help would be appreciated. thanks.

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    My comments in your other [closed] thread still go, but considering this is a half-decent excuse I will give you a bit of guidance.

    Since you are to use a while loop, it sounds like you will be using C-style strings. Use an input function (whatever one you've been taught, whether it be cin from iostream or something from cstdio), to read each line into a char array. Then cycle through the array in your loop and keep count of how many cycles yield characters that don't match. That final count is what you're looking for.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    5

    reply

    I've got the program comparing each line from the file, but it terminates when it reaches a mismatch. I assigned a variable to each match with a counter, but it never makes it past the first error.

    I looked up arrays in my textbook, but it's 4 chapters ahead and I don't understand most of the notation around the array, so I'm not sure how to use it. Thanks for the tip, I'm going to keep searching online for arrays.

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Post your code, and make sure you use code tags - refer to the sticky at the top of the forum for instructions.

  7. #7
    Registered User
    Join Date
    Mar 2005
    Posts
    5

    Getting there...

    Okay, so I was talking with my friend who's in a similar class, and he typed out almost the entire program, but he used classes and arrays, which we haven't learned yet. I was wondering if someone could clue me in if there was another way to write out parts of the program without using classes and arrays. I would use the program my friend half-wrote, but my professor would obviously know that I didn't do it myself. Here's part of the code he wrote...

    Code:
    #include <iostream>
    #include <fstream>
    #include <iomanip>
    #define NDEBUG 
    #include <cassert>
    #include <string>
    
    using namespace std;
    
    class Student {
        public:
    	void setId(string num){ id_num = num; }
    	void setAnswers(string ans){ answer = ans; }
    	void setPercentage(float z){ percentage = z; }
    	void setGrade(string earned){ grade = earned; }
    	string queryAnswer(){ return answer; }
    	string queryGrade(){ return grade; }
    	string queryId(){ return id_num; }
    	float queryPercentage(){ return percentage; }
    	private:
    	string id_num;
    	string answer;
    	string grade;
    	float percentage;
    };
    
    void calculate_percentage(string, int, Student []);
    int read_curve_file(ifstream &, int curve []);
    void calculate_letter_grade(int [], int, Student []);
    string index_to_grade(int);
    void write_output_file(ofstream &, int, Student []);        
        
    int main()
    {
        // Declare variables
        char inputfile[30];               // input file
    	string id, answers, key;          // storage strings
        
        do{
        ifstream inData;                  // Input file of answers
        ifstream grData;                  // Input file of grade curve
        ofstream outData;                 // Output file of readings
        Student data[100];                // Student class data
        int array[5];                     // Array for index
        int i=0;
       	cout << "Enter the name of the file (or type 'exit' to quit): " << endl;
    	cin >> inputfile;
    	if(!strcmp(inputfile, "exit")) return 0;
    	inData.open(inputfile, ios::in);
    	if(!inData){ cout << "Error opening file." << endl; continue; }
    	inData >> key;
    	while (!inData.eof()){
    		    inData >> id >> answers;
            		data[i].setId(id);
            		data[i].setAnswers(answers);
            		i++;
    	}
    	inData.close();
    	calculate_percentage(key, i, data);
    	read_curve_file(grData, array);
    	grData.close();
    	calculate_letter_grade(array, i, data);
    	write_output_file(outData, i, data);
    	outData.close();
        } while(inputfile != "exit");
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 12:27 PM
  2. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  3. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM