| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. I just need help getting started in the right direction. So far my ideas have been bad... Last edited by klmbrt : February 27th, 2005 at 12:51 PM. Reason: Revised |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
||||
|
||||
|
I was going to edit your post and put code tags around your code but I see way to many font and size tags
. anyways use code tags next time it makes it very easy to read that way and keeps formatting. moved to C/C++ forum |
|
#4
|
||||
|
||||
|
I took the liberty to indent the code, and strip the font tags...
Code:
/************************************************** ***********************************
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;
}
And I don't quite understand what the output represents... |
|
#5
|
|||
|
|||
|
Thanks MadCowDzz...it was incomprehensible the other way (I apologise for my terrible spelling)
use a char *answers and asign it a strtok(<input>," "). Afterwards, just do a Code:
for (i = 0; i < <number of answers>; i++) if(answers[i] == arrayOfCorrectAnswers[i]) rightOnes++; and acumulate the rigth answers to write down the grade after the cycle is over. I think that's all...if I'm not mistaken and understood correctly!! Good Luck... Anibal. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > C/C++ Help > Array or String Comparing Assignment |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|