I am attempting to write a C++ program that has the results of a T/F test. It takes the information from a data file and then it compares the students answers to the correct answers. I have two problems. First the data file has the first 8 characters as the Student ID(Letters and Numbers), then it has a blank space followed by the student answers. Can someone give me some ideas about how I would maybe use strcmp or would I use a method of comparing Arrays?
The output would be the student ID followed by the student answers and then a Grade. :confused:
Here is where I am trying to go with this, I think:
/************************************************** ***********************************
Program Filename: ch09p6.cpp
Author: Keith A. Lambert Sr.
Date Written: February 26, 2005
Assignment: Program #3
Purpose:
Input From: disk file grades.dat
Output To: screen
Functions:
************************************************** ***********************************/
/* Preprocessor Directives: ************************************************** ******/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstring>
using namespace std;
/* Begin Main ************************************************** *********************/
int main()
{
char a[21]={'T','F','F','T','F','F','T','T','T','T','F','F',
'T','F','T','F','T','F','T','\0'};
char str[30];
ifstream inFile;
inFile.open ("grades.dat.c_str");
if (!inFile)
{
cout << "Could not open file.\n";
return 1;
}
while (inFile)
{
cin.get(str[30]);
strcpy(str, "grades.dat.c_str");
if (strcmp (a[0], str[9])<0)
{
cout << strcmp;
}
cout << str[0,1,2,3,4,5,6,7] << endl;
}
inFile.close();
return 0;
}
An example of the input file would be:
ABC54301 TFTFTFTT TFTFTFFTTFT
notice that one question would be unanswered in this example and the input starts with the Student ID and seperated only by a space.
§outh§tar
02-28-05, 12:21 AM
You could use the apstring header file to make things a lot easier.
Then it would be a simple matter of reading certain words as wholes and certain words as individual characters.
wesmorris
02-28-05, 12:51 AM
it would be easier to do in a database. oh i didn't notice it was a homework assignment.
wesmorris
02-28-05, 12:56 AM
having to keep in in C, I'd make a number of arrays. one contains the correct answers... one the student's answers, one for the results. Loop through and get a comparison, storing the result in the results array. The loop can be constructed in a number of different ways, mostly depending on the knowns about the structure of the input. Tag the top of the results array with the student id. perhaps write the graded papers to file or another array. if you're down with making custom objects, you could make an array of "graded tests" each of it's members being one instance of the results array. i'm not sure exactly how to deal with variant type arrays in c. you could do it a whole bunch of ways besides that, but that's the straightforward approach that comes to mind.